Validation database prefix fix
[lhc/web/wiklou.git] / includes / SkinTemplate.php
1 <?php
2 # This program is free software; you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation; either version 2 of the License, or
5 # (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
11 #
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 # http://www.gnu.org/copyleft/gpl.html
16
17 /**
18 * Template-filler skin base class
19 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
20 * Based on Brion's smarty skin
21 * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
22 *
23 * Todo: Needs some serious refactoring into functions that correspond
24 * to the computations individual esi snippets need. Most importantly no body
25 * parsing for most of those of course.
26 *
27 * PHPTAL support has been moved to a subclass in SkinPHPTal.php,
28 * and is optional. You'll need to install PHPTAL manually to use
29 * skins that depend on it.
30 *
31 * @package MediaWiki
32 * @subpackage Skins
33 */
34
35 /**
36 * This is not a valid entry point, perform no further processing unless
37 * MEDIAWIKI is defined
38 */
39 if( defined( 'MEDIAWIKI' ) ) {
40
41 require_once 'GlobalFunctions.php';
42
43 /**
44 * Wrapper object for MediaWiki's localization functions,
45 * to be passed to the template engine.
46 *
47 * @access private
48 * @package MediaWiki
49 */
50 class MediaWiki_I18N {
51 var $_context = array();
52
53 function set($varName, $value) {
54 $this->_context[$varName] = $value;
55 }
56
57 function translate($value) {
58 $fname = 'SkinTemplate-translate';
59 wfProfileIn( $fname );
60
61 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
62 $value = preg_replace( '/^string:/', '', $value );
63
64 $value = wfMsg( $value );
65 // interpolate variables
66 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
67 list($src, $var) = $m;
68 wfSuppressWarnings();
69 $varValue = $this->_context[$var];
70 wfRestoreWarnings();
71 $value = str_replace($src, $varValue, $value);
72 }
73 wfProfileOut( $fname );
74 return $value;
75 }
76 }
77
78 /**
79 *
80 * @package MediaWiki
81 */
82 class SkinTemplate extends Skin {
83 /**#@+
84 * @access private
85 */
86
87 /**
88 * Name of our skin, set in initPage()
89 * It probably need to be all lower case.
90 */
91 var $skinname;
92
93 /**
94 * Stylesheets set to use
95 * Sub directory in ./skins/ where various stylesheets are located
96 */
97 var $stylename;
98
99 /**
100 * For QuickTemplate, the name of the subclass which
101 * will actually fill the template.
102 *
103 * In PHPTal mode, name of PHPTal template to be used.
104 * '.pt' will be automaticly added to it on PHPTAL object creation
105 */
106 var $template;
107
108 /**#@-*/
109
110 /**
111 * Setup the base parameters...
112 * Child classes should override this to set the name,
113 * style subdirectory, and template filler callback.
114 *
115 * @param OutputPage $out
116 */
117 function initPage( &$out ) {
118 parent::initPage( $out );
119 $this->skinname = 'monobook';
120 $this->stylename = 'monobook';
121 $this->template = 'QuickTemplate';
122 }
123
124 /**
125 * Create the template engine object; we feed it a bunch of data
126 * and eventually it spits out some HTML. Should have interface
127 * roughly equivalent to PHPTAL 0.7.
128 *
129 * @param string $callback (or file)
130 * @param string $repository subdirectory where we keep template files
131 * @param string $cache_dir
132 * @return object
133 * @access private
134 */
135 function &setupTemplate( $classname, $repository=false, $cache_dir=false ) {
136 return new $classname();
137 }
138
139 /**
140 * initialize various variables and generate the template
141 *
142 * @param OutputPage $out
143 * @access public
144 */
145 function outputPage( &$out ) {
146 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
147 global $wgScript, $wgStylePath, $wgLanguageCode, $wgContLanguageCode, $wgUseNewInterlanguage;
148 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgUseDatabaseMessages, $wgRequest;
149 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses;
150 global $wgMaxCredits, $wgShowCreditsIfMax;
151 global $wgPageShowWatchingUsers;
152
153 $fname = 'SkinTemplate::outputPage';
154 wfProfileIn( $fname );
155
156 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
157
158 wfProfileIn( "$fname-init" );
159 $this->initPage( $out );
160
161 $this->mTitle = $wgTitle;
162 $this->mUser =& $wgUser;
163
164 $tpl =& $this->setupTemplate( $this->template, 'skins' );
165
166 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
167 $tpl->setTranslator(new MediaWiki_I18N());
168 #}
169 wfProfileOut( "$fname-init" );
170
171 wfProfileIn( "$fname-stuff" );
172 $this->thispage = $this->mTitle->getPrefixedDbKey();
173 $this->thisurl = $this->mTitle->getPrefixedURL();
174 $this->loggedin = $wgUser->isLoggedIn();
175 $this->iscontent = ($this->mTitle->getNamespace() != NS_SPECIAL );
176 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
177 $this->username = $wgUser->getName();
178 $userPage = $wgUser->getUserPage();
179 $this->userpage = $userPage->getPrefixedText();
180 $this->userpageUrlDetails = $this->makeUrlDetails($this->userpage);
181
182 $this->usercss = $this->userjs = $this->userjsprev = false;
183 $this->setupUserCss();
184 $this->setupUserJs();
185 $this->titletxt = $this->mTitle->getPrefixedText();
186 wfProfileOut( "$fname-stuff" );
187
188 wfProfileIn( "$fname-stuff2" );
189 $tpl->set( 'title', $wgOut->getPageTitle() );
190 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
191
192 $tpl->setRef( "thispage", $this->thispage );
193 $subpagestr = $this->subPageSubtitle();
194 $tpl->set(
195 'subtitle', !empty($subpagestr)?
196 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
197 $out->getSubtitle()
198 );
199 $undelete = $this->getUndeleteLink();
200 $tpl->set(
201 "undelete", !empty($undelete)?
202 '<span class="subpages">'.$undelete.'</span>':
203 ''
204 );
205
206 $tpl->set( 'catlinks', $this->getCategories());
207 if( $wgOut->isSyndicated() ) {
208 $feeds = array();
209 foreach( $wgFeedClasses as $format => $class ) {
210 $feeds[$format] = array(
211 'text' => $format,
212 'href' => $wgRequest->appendQuery( "feed=$format" ),
213 'ttip' => wfMsg('tooltip-'.$format)
214 );
215 }
216 $tpl->setRef( 'feeds', $feeds );
217 } else {
218 $tpl->set( 'feeds', false );
219 }
220 $tpl->setRef( 'mimetype', $wgMimeType );
221 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
222 $tpl->setRef( 'charset', $wgOutputEncoding );
223 $tpl->set( 'headlinks', $out->getHeadLinks() );
224 $tpl->setRef( 'wgScript', $wgScript );
225 $tpl->setRef( 'skinname', $this->skinname );
226 $tpl->setRef( 'stylename', $this->stylename );
227 $tpl->setRef( 'loggedin', $this->loggedin );
228 $tpl->set('nsclass', 'ns-'.$this->mTitle->getNamespace());
229 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
230 /* XXX currently unused, might get useful later
231 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
232 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
233 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
234 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
235 $tpl->set( "helppage", wfMsg('helppage'));
236 */
237 $tpl->set( 'searchaction', $this->escapeSearchLink() );
238 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
239 $tpl->setRef( 'stylepath', $wgStylePath );
240 $tpl->setRef( 'logopath', $wgLogo );
241 $tpl->setRef( "lang", $wgContLanguageCode );
242 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
243 $tpl->set( 'rtl', $wgContLang->isRTL() );
244 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
245 $tpl->setRef( 'username', $this->username );
246 $tpl->setRef( 'userpage', $this->userpage);
247 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
248 $tpl->setRef( 'usercss', $this->usercss);
249 $tpl->setRef( 'userjs', $this->userjs);
250 $tpl->setRef( 'userjsprev', $this->userjsprev);
251 global $wgUseSiteJs;
252 if ($wgUseSiteJs) {
253 if($this->loggedin) {
254 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
255 } else {
256 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
257 }
258 } else {
259 $tpl->set('jsvarurl', false);
260 }
261 if( $wgUser->getNewtalk() ) {
262 $usertitle = $this->mUser->getUserPage();
263 $usertalktitle = $usertitle->getTalkPage();
264 if( !$usertalktitle->equals( $this->mTitle ) ) {
265 $ntl = wfMsg( 'newmessages',
266 $this->makeKnownLinkObj(
267 $usertalktitle,
268 wfMsg('newmessageslink')
269 )
270 );
271 # Disable Cache
272 $wgOut->setSquidMaxage(0);
273 }
274 } else {
275 $ntl = '';
276 }
277 wfProfileOut( "$fname-stuff2" );
278
279 wfProfileIn( "$fname-stuff3" );
280 $tpl->setRef( 'newtalk', $ntl );
281 $tpl->setRef( 'skin', $this);
282 $tpl->set( 'logo', $this->logoText() );
283 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
284 if ( !$wgDisableCounters ) {
285 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
286 if ( $viewcount ) {
287 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
288 } else {
289 $tpl->set('viewcount', false);
290 }
291 } else {
292 $tpl->set('viewcount', false);
293 }
294
295 if ($wgPageShowWatchingUsers) {
296 $dbr =& wfGetDB( DB_SLAVE );
297 extract( $dbr->tableNames( 'watchlist' ) );
298 $sql = "SELECT COUNT(*) AS n FROM $watchlist
299 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBKey()) .
300 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
301 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
302 $x = $dbr->fetchObject( $res );
303 $numberofwatchingusers = $x->n;
304 if ($numberofwatchingusers > 0) {
305 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
306 } else {
307 $tpl->set('numberofwatchingusers', false);
308 }
309 } else {
310 $tpl->set('numberofwatchingusers', false);
311 }
312
313 $tpl->set('lastmod', $this->lastModified());
314 $tpl->set('copyright',$this->getCopyright());
315
316 $this->credits = false;
317
318 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
319 require_once("Credits.php");
320 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
321 }
322
323 $tpl->setRef( 'credits', $this->credits );
324
325 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
326 $tpl->set('copyright', $this->getCopyright());
327 $tpl->set('viewcount', false);
328 $tpl->set('lastmod', false);
329 $tpl->set('credits', false);
330 $tpl->set('numberofwatchingusers', false);
331 } else {
332 $tpl->set('copyright', false);
333 $tpl->set('viewcount', false);
334 $tpl->set('lastmod', false);
335 $tpl->set('credits', false);
336 $tpl->set('numberofwatchingusers', false);
337 }
338 wfProfileOut( "$fname-stuff3" );
339
340 wfProfileIn( "$fname-stuff4" );
341 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
342 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
343 $tpl->set( 'disclaimer', $this->disclaimerLink() );
344 $tpl->set( 'about', $this->aboutLink() );
345
346 $tpl->setRef( 'debug', $out->mDebugtext );
347 $tpl->set( 'reporttime', $out->reportTime() );
348 $tpl->set( 'sitenotice', wfGetSiteNotice() );
349
350 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
351 $out->mBodytext .= $printfooter ;
352 $tpl->setRef( 'bodytext', $out->mBodytext );
353
354 # Language links
355 $language_urls = array();
356 foreach( $wgOut->getLanguageLinks() as $l ) {
357 $nt = Title::newFromText( $l );
358 $language_urls[] = array('href' => $nt->getFullURL(),
359 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
360 'class' => $wgContLang->isRTL() ? 'rtl' : 'ltr');
361 }
362 if(count($language_urls)) {
363 $tpl->setRef( 'language_urls', $language_urls);
364 } else {
365 $tpl->set('language_urls', false);
366 }
367 wfProfileOut( "$fname-stuff4" );
368
369 # Personal toolbar
370 $tpl->set('personal_urls', $this->buildPersonalUrls());
371 $content_actions = $this->buildContentActionUrls();
372 $tpl->setRef('content_actions', $content_actions);
373
374 // XXX: attach this from javascript, same with section editing
375 if($this->iseditable && $wgUser->getOption("editondblclick") )
376 {
377 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
378 } else {
379 $tpl->set('body_ondblclick', false);
380 }
381 if( $this->iseditable && $wgUser->getOption( 'editsectiononrightclick' ) ) {
382 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
383 } else {
384 $tpl->set( 'body_onload', false );
385 }
386 $tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
387 $tpl->set( 'nav_urls', $this->buildNavUrls() );
388
389 // execute template
390 wfProfileIn( "$fname-execute" );
391 $res = $tpl->execute();
392 wfProfileOut( "$fname-execute" );
393
394 // result may be an error
395 $this->printOrError( $res );
396 wfProfileOut( $fname );
397 }
398
399 /**
400 * Output the string, or print error message if it's
401 * an error object of the appropriate type.
402 * For the base class, assume strings all around.
403 *
404 * @param mixed $str
405 * @access private
406 */
407 function printOrError( &$str ) {
408 echo $str;
409 }
410
411 /**
412 * build array of urls for personal toolbar
413 * @return array
414 * @access private
415 */
416 function buildPersonalUrls() {
417 $fname = 'SkinTemplate::buildPersonalUrls';
418 wfProfileIn( $fname );
419
420 /* set up the default links for the personal toolbar */
421 global $wgShowIPinHeader;
422 $personal_urls = array();
423 if ($this->loggedin) {
424 $personal_urls['userpage'] = array(
425 'text' => $this->username,
426 'href' => &$this->userpageUrlDetails['href'],
427 'class' => $this->userpageUrlDetails['exists']?false:'new'
428 );
429 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
430 $personal_urls['mytalk'] = array(
431 'text' => wfMsg('mytalk'),
432 'href' => &$usertalkUrlDetails['href'],
433 'class' => $usertalkUrlDetails['exists']?false:'new'
434 );
435 $personal_urls['preferences'] = array(
436 'text' => wfMsg('preferences'),
437 'href' => $this->makeSpecialUrl('Preferences')
438 );
439 $personal_urls['watchlist'] = array(
440 'text' => wfMsg('watchlist'),
441 'href' => $this->makeSpecialUrl('Watchlist')
442 );
443 $personal_urls['mycontris'] = array(
444 'text' => wfMsg('mycontris'),
445 'href' => $this->makeSpecialUrl("Contributions/$this->username")
446 );
447 $personal_urls['logout'] = array(
448 'text' => wfMsg('userlogout'),
449 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl )
450 );
451 } else {
452 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
453 $personal_urls['anonuserpage'] = array(
454 'text' => $this->username,
455 'href' => &$this->userpageUrlDetails['href'],
456 'class' => $this->userpageUrlDetails['exists']?false:'new'
457 );
458 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
459 $personal_urls['anontalk'] = array(
460 'text' => wfMsg('anontalk'),
461 'href' => &$usertalkUrlDetails['href'],
462 'class' => $usertalkUrlDetails['exists']?false:'new'
463 );
464 $personal_urls['anonlogin'] = array(
465 'text' => wfMsg('userlogin'),
466 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
467 );
468 } else {
469
470 $personal_urls['login'] = array(
471 'text' => wfMsg('userlogin'),
472 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
473 );
474 }
475 }
476 wfProfileOut( $fname );
477 return $personal_urls;
478 }
479
480
481 function tabAction( &$title, $message, $selected, $query='', $checkEdit=false ) {
482 $classes = array();
483 if( $selected ) {
484 $classes[] = 'selected';
485 }
486 if( $checkEdit && $title->getArticleId() == 0 ) {
487 $classes[] = 'new';
488 }
489 return array(
490 'class' => implode( ' ', $classes ),
491 'text' => wfMsg( $message ),
492 'href' => $title->getLocalUrl( $query ) );
493 }
494
495 function makeTalkUrlDetails( $name, $urlaction='' ) {
496 $title = Title::newFromText( $name );
497 $title = $title->getTalkPage();
498 $this->checkTitle($title, $name);
499 return array(
500 'href' => $title->getLocalURL( $urlaction ),
501 'exists' => $title->getArticleID() != 0?true:false
502 );
503 }
504
505 function makeArticleUrlDetails( $name, $urlaction='' ) {
506 $title = Title::newFromText( $name );
507 $title= $title->getSubjectPage();
508 $this->checkTitle($title, $name);
509 return array(
510 'href' => $title->getLocalURL( $urlaction ),
511 'exists' => $title->getArticleID() != 0?true:false
512 );
513 }
514
515 /**
516 * an array of edit links by default used for the tabs
517 * @return array
518 * @access private
519 */
520 function buildContentActionUrls () {
521 global $wgContLang, $wgUseValidation, $wgDBprefix;
522 $fname = 'SkinTemplate::buildContentActionUrls';
523 wfProfileIn( $fname );
524
525 global $wgUser, $wgRequest;
526 $action = $wgRequest->getText( 'action' );
527 $section = $wgRequest->getText( 'section' );
528 $oldid = $wgRequest->getVal( 'oldid' );
529 $diff = $wgRequest->getVal( 'diff' );
530 $content_actions = array();
531
532 if( $this->iscontent ) {
533
534 $nskey = $this->getNameSpaceKey();
535 $content_actions[$nskey] = $this->tabAction(
536 $this->mTitle->getSubjectPage(),
537 $nskey,
538 !$this->mTitle->isTalkPage() );
539
540 $content_actions['talk'] = $this->tabAction(
541 $this->mTitle->getTalkPage(),
542 'talk',
543 $this->mTitle->isTalkPage(),
544 '',
545 true);
546
547 wfProfileIn( "$fname-edit" );
548 if ( $this->mTitle->userCanEdit() ) {
549 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.IntVal( $oldid ) : false;
550 $istalk = $this->mTitle->isTalkPage();
551 $istalkclass = $istalk?' istalk':'';
552 $content_actions['edit'] = array(
553 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
554 'text' => wfMsg('edit'),
555 'href' => $this->mTitle->getLocalUrl( 'action=edit'.$oid )
556 );
557
558 if ( $istalk ) {
559 $content_actions['addsection'] = array(
560 'class' => $section == 'new'?'selected':false,
561 'text' => wfMsg('addsection'),
562 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
563 );
564 }
565 } else {
566 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.IntVal( $oldid ) : '';
567 $content_actions['viewsource'] = array(
568 'class' => ($action == 'edit') ? 'selected' : false,
569 'text' => wfMsg('viewsource'),
570 'href' => $this->mTitle->getLocalUrl( 'action=edit'.$oid )
571 );
572 }
573 wfProfileOut( "$fname-edit" );
574
575 wfProfileIn( "$fname-live" );
576 if ( $this->mTitle->getArticleId() ) {
577
578 $content_actions['history'] = array(
579 'class' => ($action == 'history') ? 'selected' : false,
580 'text' => wfMsg('history_short'),
581 'href' => $this->mTitle->getLocalUrl( 'action=history')
582 );
583
584 if($wgUser->isAllowed('protect')){
585 if(!$this->mTitle->isProtected()){
586 $content_actions['protect'] = array(
587 'class' => ($action == 'protect') ? 'selected' : false,
588 'text' => wfMsg('protect'),
589 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
590 );
591
592 } else {
593 $content_actions['unprotect'] = array(
594 'class' => ($action == 'unprotect') ? 'selected' : false,
595 'text' => wfMsg('unprotect'),
596 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
597 );
598 }
599 }
600 if($wgUser->isAllowed('delete')){
601 $content_actions['delete'] = array(
602 'class' => ($action == 'delete') ? 'selected' : false,
603 'text' => wfMsg('delete'),
604 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
605 );
606 }
607 if ( $wgUser->isLoggedIn() ) {
608 if ( $this->mTitle->userCanMove()) {
609 $content_actions['move'] = array(
610 'class' => ($this->mTitle->getDbKey() == 'Movepage' and $this->mTitle->getNamespace == NS_SPECIAL) ? 'selected' : false,
611 'text' => wfMsg('move'),
612 'href' => $this->makeSpecialUrl("Movepage/$this->thispage" )
613 );
614 }
615 }
616 } else {
617 //article doesn't exist or is deleted
618 if($wgUser->isAllowed('delete')){
619 if( $n = $this->mTitle->isDeleted() ) {
620 $content_actions['undelete'] = array(
621 'class' => false,
622 'text' => ($n == 1) ? wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
623 'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
624 );
625 }
626 }
627 }
628 wfProfileOut( "$fname-live" );
629
630 if( $wgUser->isLoggedIn() and $action != 'submit' ) {
631 if( !$this->mTitle->userIsWatching()) {
632 $content_actions['watch'] = array(
633 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
634 'text' => wfMsg('watch'),
635 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
636 );
637 } else {
638 $content_actions['unwatch'] = array(
639 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
640 'text' => wfMsg('unwatch'),
641 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
642 );
643 }
644
645 # Validate tab. TODO: add validation to logged-in user rights
646 if($wgUseValidation && ( $action == "" || $action=='view' ) ){ # && $wgUser->isAllowed('validate')){
647 if ( $oldid ) $oid = IntVal( $oldid ) ; # Use the oldid
648 else
649 {# Trying to get the current article revision through this weird stunt
650 $tid = $this->mTitle->getArticleID();
651 $tns = $this->mTitle->getNamespace();
652 $sql = "SELECT page_latest FROM {$wgDBprefix}page WHERE page_id={$tid} AND page_namespace={$tns}" ;
653 $res = wfQuery( $sql, DB_READ );
654 if( $s = wfFetchObject( $res ) )
655 $oid = $s->page_latest ;
656 else $oid = "" ; # Something's wrong, like the article has been deleted in the last 10 ns
657 }
658 if ( $oid != "" ) {
659 $oid = "&revision={$oid}" ;
660 $content_actions['validate'] = array(
661 'class' => ($action == 'validate') ? 'selected' : false,
662 'text' => wfMsg('val_tab'),
663 'href' => $this->mTitle->getLocalUrl( "action=validate{$oid}" )
664 );
665 }
666 }
667 }
668 } else {
669 /* show special page tab */
670
671 $content_actions['article'] = array(
672 'class' => 'selected',
673 'text' => wfMsg('specialpage'),
674 'href' => false
675 );
676 }
677
678 /* show links to different language variants */
679 global $wgDisableLangConversion;
680 $variants = $wgContLang->getVariants();
681 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
682 $preferred = $wgContLang->getPreferredVariant();
683 $actstr = '';
684 if( $action )
685 $actstr = 'action=' . $action . '&';
686 $vcount=0;
687 foreach( $variants as $code ) {
688 $varname = $wgContLang->getVariantname( $code );
689 if( $varname == 'disable' )
690 continue;
691 $selected = ( $code == $preferred )? 'selected' : false;
692 $content_actions['varlang-' . $vcount] = array(
693 'class' => $selected,
694 'text' => $varname,
695 'href' => $this->mTitle->getLocalUrl( $actstr . 'variant=' . $code )
696 );
697 $vcount ++;
698 }
699 }
700
701 wfProfileOut( $fname );
702 return $content_actions;
703 }
704
705 function getNavigationLinks() {
706 global $wgNavigationLinks;
707 return $wgNavigationLinks;
708 }
709
710 /**
711 * build array of global navigation links
712 * @return array
713 * @access private
714 */
715 function buildNavigationUrls () {
716 $fname = 'SkinTemplate::buildNavigationUrls';
717 wfProfileIn( $fname );
718
719 $links = $this->getNavigationLinks();
720
721 $result = array();
722 foreach ( $links as $link ) {
723 $text = wfMsg( $link['text'] );
724 wfProfileIn( "$fname-{$link['text']}" );
725 if ($text != '-') {
726 $dest = wfMsgForContent( $link['href'] );
727 wfProfileIn( "$fname-{$link['text']}2" );
728 $result[] = array(
729 'text' => $text,
730 'href' => $this->makeInternalOrExternalUrl( $dest ),
731 'id' => 'n-'.$link['text']
732 );
733 wfProfileOut( "$fname-{$link['text']}2" );
734 }
735 wfProfileOut( "$fname-{$link['text']}" );
736 }
737 wfProfileOut( $fname );
738 return $result;
739 }
740
741 /**
742 * build array of common navigation links
743 * @return array
744 * @access private
745 */
746 function buildNavUrls () {
747 $fname = 'SkinTemplate::buildNavUrls';
748 wfProfileIn( $fname );
749
750 global $wgUser, $wgRequest;
751 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
752
753 $action = $wgRequest->getText( 'action' );
754 $oldid = $wgRequest->getVal( 'oldid' );
755 $diff = $wgRequest->getVal( 'diff' );
756
757 $nav_urls = array();
758 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
759 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Random'));
760 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
761 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ? array('href' => $this->makeI18nUrl('currentevents')) : false;
762 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ? array('href' => $this->makeI18nUrl('portal-url')) : false;
763 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
764 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
765 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
766 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
767 if( $wgEnableUploads ) {
768 if ($wgUploadNavigationUrl) {
769 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
770 } else {
771 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
772 }
773 } else {
774 $nav_urls['upload'] = false;
775 }
776 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
777
778 if( $this->mTitle->getNamespace() != NS_SPECIAL) {
779 $nav_urls['whatlinkshere'] = array(
780 'href' => $this->makeSpecialUrl("Whatlinkshere/$this->thispage")
781 );
782 $nav_urls['recentchangeslinked'] = array(
783 'href' => $this->makeSpecialUrl("Recentchangeslinked/$this->thispage")
784 );
785 }
786
787 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
788 $id = User::idFromName($this->mTitle->getText());
789 $ip = User::isIP($this->mTitle->getText());
790 } else {
791 $id = 0;
792 $ip = false;
793 }
794
795 if($id || $ip) { # both anons and non-anons have contri list
796 $nav_urls['contributions'] = array(
797 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle->getText() )
798 );
799 } else {
800 $nav_urls['contributions'] = false;
801 }
802 $nav_urls['emailuser'] = false;
803 if( $this->showEmailUser( $id ) ) {
804 $nav_urls['emailuser'] = array(
805 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle->getText() )
806 );
807 }
808 wfProfileOut( $fname );
809 return $nav_urls;
810 }
811
812 /**
813 * Generate strings used for xml 'id' names
814 * @return string
815 * @private
816 */
817 function getNameSpaceKey () {
818 switch ($this->mTitle->getNamespace()) {
819 case NS_MAIN:
820 case NS_TALK:
821 return 'nstab-main';
822 case NS_USER:
823 case NS_USER_TALK:
824 return 'nstab-user';
825 case NS_MEDIA:
826 return 'nstab-media';
827 case NS_SPECIAL:
828 return 'nstab-special';
829 case NS_PROJECT:
830 case NS_PROJECT_TALK:
831 return 'nstab-wp';
832 case NS_IMAGE:
833 case NS_IMAGE_TALK:
834 return 'nstab-image';
835 case NS_MEDIAWIKI:
836 case NS_MEDIAWIKI_TALK:
837 return 'nstab-mediawiki';
838 case NS_TEMPLATE:
839 case NS_TEMPLATE_TALK:
840 return 'nstab-template';
841 case NS_HELP:
842 case NS_HELP_TALK:
843 return 'nstab-help';
844 case NS_CATEGORY:
845 case NS_CATEGORY_TALK:
846 return 'nstab-category';
847 default:
848 return 'nstab-main';
849 }
850 }
851
852 /**
853 * @access private
854 */
855 function setupUserCss() {
856 $fname = 'SkinTemplate::setupUserCss';
857 wfProfileIn( $fname );
858
859 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
860
861 $sitecss = '';
862 $usercss = '';
863 $siteargs = '&maxage=' . $wgSquidMaxage;
864
865 # Add user-specific code if this is a user and we allow that kind of thing
866
867 if ( $wgAllowUserCss && $this->loggedin ) {
868 $action = $wgRequest->getText('action');
869
870 # if we're previewing the CSS page, use it
871 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
872 $siteargs = "&smaxage=0&maxage=0";
873 $usercss = $wgRequest->getText('wpTextbox1');
874 } else {
875 $usercss = '@import "' .
876 $this->makeUrl($this->userpage . '/'.$this->skinname.'.css',
877 'action=raw&ctype=text/css') . '";' ."\n";
878 }
879
880 $siteargs .= '&ts=' . $wgUser->mTouched;
881 }
882
883 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename . '/rtl.css";' . "\n";
884
885 # If we use the site's dynamic CSS, throw that in, too
886 if ( $wgUseSiteCss ) {
887 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname) . '.css', 'action=raw&ctype=text/css&smaxage=' . $wgSquidMaxage, NS_MEDIAWIKI) . '";' . "\n";
888 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
889 }
890
891 # If we use any dynamic CSS, make a little CDATA block out of it.
892
893 if ( !empty($sitecss) || !empty($usercss) ) {
894 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
895 }
896 wfProfileOut( $fname );
897 }
898
899 /**
900 * @access private
901 */
902 function setupUserJs() {
903 $fname = 'SkinTemplate::setupUserJs';
904 wfProfileIn( $fname );
905
906 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
907 $action = $wgRequest->getText('action');
908
909 if( $wgAllowUserJs && $this->loggedin ) {
910 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
911 # XXX: additional security check/prompt?
912 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
913 } else {
914 $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
915 }
916 }
917 wfProfileOut( $fname );
918 }
919
920 /**
921 * returns css with user-specific options
922 * @access public
923 */
924
925 function getUserStylesheet() {
926 $fname = 'SkinTemplate::getUserStylesheet';
927 wfProfileIn( $fname );
928
929 global $wgUser;
930 $s = "/* generated user stylesheet */\n";
931 $s .= $this->reallyDoGetUserStyles();
932 wfProfileOut( $fname );
933 return $s;
934 }
935
936 /**
937 * @access public
938 */
939 function getUserJs() {
940 $fname = 'SkinTemplate::getUserJs';
941 wfProfileIn( $fname );
942
943 global $wgStylePath;
944 $s = '/* generated javascript */';
945 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
946 $s .= '/* MediaWiki:'.ucfirst($this->skinname)." */\n";
947
948 // avoid inclusion of non defined user JavaScript (with custom skins only)
949 // by checking for default message content
950 $msgKey = ucfirst($this->skinname).'.js';
951 $userJS = wfMsg($msgKey);
952 if ('&lt;'.$msgKey.'&gt;' != $userJS) {
953 $s .= $userJS;
954 }
955
956 wfProfileOut( $fname );
957 return $s;
958 }
959 }
960
961 /**
962 * Generic wrapper for template functions, with interface
963 * compatible with what we use of PHPTAL 0.7.
964 * @package MediaWiki
965 * @subpackage Skins
966 */
967 class QuickTemplate {
968 /**
969 * @access public
970 */
971 function QuickTemplate() {
972 $this->data = array();
973 $this->translator = new MediaWiki_I18N();
974 }
975
976 /**
977 * @access public
978 */
979 function set( $name, $value ) {
980 $this->data[$name] = $value;
981 }
982
983 /**
984 * @access public
985 */
986 function setRef($name, &$value) {
987 $this->data[$name] =& $value;
988 }
989
990 /**
991 * @access public
992 */
993 function setTranslator( &$t ) {
994 $this->translator = &$t;
995 }
996
997 /**
998 * @access public
999 */
1000 function execute() {
1001 echo "Override this function.";
1002 }
1003
1004
1005 /**
1006 * @access private
1007 */
1008 function text( $str ) {
1009 echo htmlspecialchars( $this->data[$str] );
1010 }
1011
1012 /**
1013 * @access private
1014 */
1015 function html( $str ) {
1016 echo $this->data[$str];
1017 }
1018
1019 /**
1020 * @access private
1021 */
1022 function msg( $str ) {
1023 echo htmlspecialchars( $this->translator->translate( $str ) );
1024 }
1025
1026 /**
1027 * @access private
1028 */
1029 function msgHtml( $str ) {
1030 echo $this->translator->translate( $str );
1031 }
1032
1033 /**
1034 * An ugly, ugly hack.
1035 * @access private
1036 */
1037 function msgWiki( $str ) {
1038 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
1039
1040 $text = $this->translator->translate( $str );
1041 $parserOutput = $wgParser->parse( $text, $wgTitle,
1042 $wgOut->mParserOptions, true );
1043 echo $parserOutput->getText();
1044 }
1045
1046 /**
1047 * @access private
1048 */
1049 function haveData( $str ) {
1050 return $this->data[$str];
1051 }
1052
1053 /**
1054 * @access private
1055 */
1056 function haveMsg( $str ) {
1057 $msg = $this->translator->translate( $str );
1058 return ($msg != '-') && ($msg != ''); # ????
1059 }
1060 }
1061
1062 } // end of if( defined( 'MEDIAWIKI' ) )
1063 ?>