(bug 3047) Don't mention talk pages on Special:Movepage when there isn't one
[mediawiki.git] / skins / disabled / MonoBookCBT.php
bloba5d5b545346ca5378f05fc943d9bc7ea58f21cab
1 <?php
3 if ( !defined( 'MEDIAWIKI' ) ) {
4 die( "This file is part of MediaWiki, it is not a valid entry point\n" );
7 require_once( dirname(__FILE__) . '/../includes/CBTProcessor.php' );
8 require_once( dirname(__FILE__) . '/../includes/SkinTemplate.php' );
11 /**
12 * MonoBook clone using the new dependency-tracking template processor.
13 * EXPERIMENTAL - use only for testing and profiling at this stage
15 * The main thing that's missing is cache invalidation, on change of:
16 * * messages
17 * * user preferences
18 * * source template
19 * * source code and configuration files
21 * The other thing is that lots of dependencies that are declared in the callbacks
22 * are not intelligently handled. There's some room for improvement there.
24 * The class is derived from SkinTemplate, but that's only temporary. Eventually
25 * it'll be derived from Skin, and I've avoided using SkinTemplate functions as
26 * much as possible. In fact, the only SkinTemplate dependencies I know of at the
27 * moment are the functions to generate the gen=css and gen=js files.
29 * It assumes that $wgMemc is valid, if not, performance will be glacial as it will
30 * compile the skin on every invocation.
32 class SkinMonoBookCBT extends SkinTemplate {
33 var $mOut, $mTitle;
34 var $mStyleName = 'monobook';
35 var $mCompiling = false;
37 /******************************************************
38 * General functions *
39 ******************************************************/
41 /** Execute the template and write out the result */
42 function outputPage( &$out ) {
43 echo $this->execute( $out );
46 function execute( &$out ) {
47 global $wgTitle, $wgStyleDirectory, $wgParserCacheType;
48 $fname = 'SkinMonoBookCBT::execute';
49 wfProfileIn( $fname );
50 wfProfileIn( "$fname-setup" );
51 Skin::initPage( $out );
53 $this->mOut =& $out;
54 $this->mTitle =& $wgTitle;
56 $sourceFile = "$wgStyleDirectory/MonoBook.tpl";
58 wfProfileOut( "$fname-setup" );
60 if ( $wgParserCacheType == CACHE_NONE ) {
61 $template = file_get_contents( $sourceFile );
62 $text = $this->executeTemplate( $template );
63 } else {
64 $compiled = $this->getCompiledTemplate( $sourceFile );
65 $text = $this->executeTemplate( $compiled );
67 wfProfileOut( $fname );
68 return $text;
71 function getCompiledTemplate( $sourceFile ) {
72 global $wgDBname, $wgMemc, $wgRequest, $wgUser, $parserMemc;
73 $fname = 'SkinMonoBookCBT::getCompiledTemplate';
75 // Sandbox template execution
76 if ( $this->mCompiling ) {
77 return;
80 wfProfileIn( $fname );
82 // Is the request an ordinary page view?
83 if ( $wgRequest->wasPosted() ||
84 count( array_diff( array_keys( $_GET ), array( 'title', 'useskin', 'recompile' ) ) ) != 0 )
86 $type = 'nonview';
87 } else {
88 $type = 'view';
91 // Per-user compiled template
92 // Put all logged-out users on the same cache key
93 $cacheKey = "$wgDBname:monobookcbt:$type:" . $wgUser->getId();
95 $recompile = $wgRequest->getVal( 'recompile' );
96 if ( !$recompile ) {
97 $compiled = $parserMemc->get( $cacheKey );
99 if ( $recompile || !$compiled ) {
100 $template = file_get_contents( $sourceFile );
102 $ignore = array( 'lang', 'loggedin', 'user' );
103 if ( $wgUser->isLoggedIn() ) {
104 $ignore[] = '!loggedin dynamic';
105 } else {
106 $ignore[] = 'loggedin dynamic';
108 if ( $type == 'view' ) {
109 $ignore[] = 'nonview dynamic';
111 $tp = new CBTProcessor( $template, $this, $ignore );
112 $this->mCompiling = true;
113 $compiled = $tp->compile();
114 $this->mCompiling = false;
115 if ( $tp->getLastError() ) {
116 // If there was a compile error, don't save the template
117 // Instead just print the error and exit
118 echo $compiled;
119 wfErrorExit();
122 // Reduce whitespace
123 // This is done here instead of in CBTProcessor because we can be
124 // more sure it is safe here.
125 $compiled = preg_replace( '/^[ \t]+/m', '', $compiled );
126 $compiled = preg_replace( '/[\r\n]+/', "\n", $compiled );
127 $parserMemc->set( $cacheKey, $compiled, 3600 );
129 wfProfileOut( $fname );
130 return $compiled;
133 function executeTemplate( $template ) {
134 $fname = 'SkinMonoBookCBT::executeTemplate';
135 wfProfileIn( $fname );
136 $tp = new CBTProcessor( $template, $this );
137 $this->mCompiling = true;
138 $text = $tp->execute();
139 $this->mCompiling = false;
140 wfProfileOut( $fname );
141 return $text;
144 /******************************************************
145 * Callbacks *
146 ******************************************************/
148 function lang() { return $GLOBALS['wgContLanguageCode']; }
150 function dir() {
151 global $wgContLang;
152 return $wgContLang->isRTL() ? 'rtl' : 'ltr';
155 function mimetype() { return $GLOBALS['wgMimeType']; }
156 function charset() { return $GLOBALS['wgOutputEncoding']; }
157 function headlinks() {
158 return new TplValue( $this->mOut->getHeadLinks(), 'dynamic' );
160 function headscripts() {
161 return new TplValue( $this->mOut->getScript(), 'dynamic' );
164 function pagetitle() {
165 return new TplValue( $this->mOut->getHTMLTitle(), array( 'title', 'lang' ) );
168 function stylepath() { return $GLOBALS['wgStylePath']; }
169 function stylename() { return $this->mStyleName; }
171 function notprintable() {
172 global $wgRequest;
173 return new TplValue( !$wgRequest->getBool( 'printable' ), 'nonview dynamic' );
176 function jsmimetype() { return $GLOBALS['wgJsMimeType']; }
178 function jsvarurl() {
179 global $wgUseSiteJs, $wgUser;
180 if ( !$wgUseSiteJs ) return '';
182 if ( $wgUser->isLoggedIn() ) {
183 $url = $this->makeUrl('-','action=raw&smaxage=0&gen=js');
184 } else {
185 $url = $this->makeUrl('-','action=raw&gen=js');
187 return new TplValue( $url, 'loggedin' );
190 function pagecss() {
191 global $wgHooks;
193 $out = false;
194 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
196 // Unknown dependencies
197 return new TplValue( $out, 'dynamic' );
200 function usercss() {
201 if ( $this->isCssPreview() ) {
202 global $wgRequest;
203 $usercss = $this->makeStylesheetCdata( $wgRequest->getText('wpTextbox1') );
204 } else {
205 $usercss = $this->makeStylesheetLink( $this->makeUrl($this->getUserPageText() .
206 '/'.$this->mStyleName.'.css', 'action=raw&ctype=text/css' ) );
209 // Dynamic when not an ordinary page view, also depends on the username
210 return new TplValue( $usercss, array( 'nonview dynamic', 'user' ) );
213 function sitecss() {
214 global $wgUseSiteCss;
215 if ( !$wgUseSiteCss ) {
216 return '';
219 global $wgSquidMaxage, $wgContLang, $wgStylePath;
221 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
223 $sitecss = '';
224 if ( $wgContLang->isRTL() ) {
225 $sitecss .= $this->makeStylesheetLink( $wgStylePath . '/' . $this->mStyleName . '/rtl.css' ) . "\n";
228 $sitecss .= $this->makeStylesheetLink( $this->makeNSUrl('Common.css', $query, NS_MEDIAWIKI) ) . "\n";
229 $sitecss .= $this->makeStylesheetLink( $this->makeNSUrl(
230 ucfirst($this->mStyleName) . '.css', $query, NS_MEDIAWIKI) ) . "\n";
232 // No deps
233 return $sitecss;
236 function gencss() {
237 global $wgUseSiteCss;
238 if ( !$wgUseSiteCss ) return '';
240 global $wgSquidMaxage, $wgUser, $wgAllowUserCss;
241 if ( $this->isCssPreview() ) {
242 $siteargs = '&smaxage=0&maxage=0';
243 } else {
244 $siteargs = '&maxage=' . $wgSquidMaxage;
246 if ( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
247 $siteargs .= '&ts={user_touched}';
248 $isTemplate = true;
249 } else {
250 $isTemplate = false;
253 $link = $this->makeStylesheetLink( $this->makeUrl('-','action=raw&gen=css' . $siteargs) ) . "\n";
255 if ( $wgAllowUserCss ) {
256 $deps = 'loggedin';
257 } else {
258 $deps = array();
260 return new TplValue( $link, $deps, $isTemplate );
263 function user_touched() {
264 global $wgUser;
265 return new TplValue( $wgUser->mTouched, 'dynamic' );
268 function userjs() {
269 global $wgAllowUserJs, $wgJsMimeType;
270 if ( !$wgAllowUserJs ) return '';
272 if ( $this->isJsPreview() ) {
273 $url = '';
274 } else {
275 $url = $this->makeUrl($this->getUserPageText().'/'.$this->mStyleName.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
277 return new TplValue( $url, array( 'nonview dynamic', 'user' ) );
280 function userjsprev() {
281 global $wgAllowUserJs, $wgRequest;
282 if ( !$wgAllowUserJs ) return '';
283 if ( $this->isJsPreview() ) {
284 $js = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
285 } else {
286 $js = '';
288 return new TplValue( $js, array( 'nonview dynamic' ) );
291 function trackbackhtml() {
292 global $wgUseTrackbacks;
293 if ( !$wgUseTrackbacks ) return '';
295 if ( $this->mOut->isArticleRelated() ) {
296 $tb = $this->mTitle->trackbackRDF();
297 } else {
298 $tb = '';
300 return new TplValue( $tb, 'dynamic' );
303 function body_ondblclick() {
304 global $wgUser;
305 if( $this->isEditable() && $wgUser->getOption("editondblclick") ) {
306 $js = 'document.location = "' . $this->getEditUrl() .'";';
307 } else {
308 $js = '';
311 if ( User::getDefaultOption('editondblclick') ) {
312 return new TplValue( $js, 'user', 'title' );
313 } else {
314 // Optimise away for logged-out users
315 return new TplValue( $js, 'loggedin dynamic' );
319 function body_onload() {
320 global $wgUser;
321 if ( $this->isEditable() && $wgUser->getOption( 'editsectiononrightclick' ) ) {
322 $js = 'setupRightClickEdit()';
323 } else {
324 $js = '';
326 return new TplValue( $js, 'loggedin dynamic' );
329 function nsclass() {
330 return new TplValue( 'ns-' . $this->mTitle->getNamespace(), 'title' );
333 function sitenotice() {
334 // Perhaps this could be given special dependencies using our knowledge of what
335 // wfGetSiteNotice() depends on.
336 return new TplValue( wfGetSiteNotice(), 'dynamic' );
339 function title() {
340 return new TplValue( $this->mOut->getPageTitle(), array( 'title', 'lang' ) );
343 function title_urlform() {
344 return new TplValue( $this->getThisTitleUrlForm(), 'title' );
347 function title_userurl() {
348 return new TplValue( urlencode( $this->mTitle->getDBkey() ), 'title' );
351 function subtitle() {
352 $subpagestr = $this->subPageSubtitle();
353 if ( !empty( $subpagestr ) ) {
354 $s = '<span class="subpages">'.$subpagestr.'</span>'.$this->mOut->getSubtitle();
355 } else {
356 $s = $this->mOut->getSubtitle();
358 return new TplValue( $s, array( 'title', 'nonview dynamic' ) );
361 function undelete() {
362 return new TplValue( $this->getUndeleteLink(), array( 'title', 'lang' ) );
365 function newtalk() {
366 global $wgUser, $wgDBname;
367 $newtalks = $wgUser->getNewMessageLinks();
369 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === $wgDBname) {
370 $usertitle = $this->getUserPageTitle();
371 $usertalktitle = $usertitle->getTalkPage();
372 if( !$usertalktitle->equals( $this->mTitle ) ) {
373 $ntl = wfMsg( 'youhavenewmessages',
374 $this->makeKnownLinkObj(
375 $usertalktitle,
376 wfMsgHtml( 'newmessageslink' ),
377 'redirect=no'
379 $this->makeKnownLinkObj(
380 $usertalktitle,
381 wfMsgHtml( 'newmessagesdifflink' ),
382 'diff=cur'
385 # Disable Cache
386 $this->mOut->setSquidMaxage(0);
388 } else if (count($newtalks)) {
389 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
390 $msgs = array();
391 foreach ($newtalks as $newtalk) {
392 $msgs[] = wfElement("a",
393 array('href' => $newtalk["link"]), $newtalk["wiki"]);
395 $parts = implode($sep, $msgs);
396 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
397 $this->mOut->setSquidMaxage(0);
398 } else {
399 $ntl = '';
401 return new TplValue( $ntl, 'dynamic' );
404 function showjumplinks() {
405 global $wgUser;
406 return new TplValue( $wgUser->getOption( 'showjumplinks' ) ? 'true' : '', 'user' );
409 function bodytext() {
410 return new TplValue( $this->mOut->getHTML(), 'dynamic' );
413 function catlinks() {
414 return new TplValue( $this->getCategories(), 'dynamic' );
417 function extratabs( $itemTemplate ) {
418 global $wgContLang, $wgDisableLangConversion;
420 $etpl = templateEscape( $itemTemplate );
422 /* show links to different language variants */
423 $variants = $wgContLang->getVariants();
424 $s = '';
425 if ( !$wgDisableLangConversion && count( $wgContLang->getVariants() ) > 1 ) {
426 $vcount=0;
427 foreach ( $variants as $code ) {
428 $name = $wgContLang->getVariantname( $code );
429 if ( $name == 'disable' ) {
430 continue;
432 $name = templateEscape( $name );
433 $s .= "{ca_variant {{$code}} {{$name}} {{$vcount}} {{$etpl}}}\n";
434 $vcount ++;
437 return new TplValue( $s, array(), true );
440 function is_special() { return new TplValue( $this->mTitle->getNamespace() == NS_SPECIAL, 'title' ); }
441 function can_edit() { return new TplValue( (string)($this->mTitle->userCanEdit()), 'dynamic' ); }
442 function can_move() { return new TplValue( (string)($this->mTitle->userCanMove()), 'dynamic' ); }
443 function is_talk() { return new TplValue( (string)($this->mTitle->isTalkPage()), 'title' ); }
444 function is_protected() { return new TplValue( (string)$this->mTitle->isProtected(), 'dynamic' ); }
445 function nskey() { return new TplValue( $this->mTitle->getNamespaceKey(), 'title' ); }
447 function request_url() {
448 global $wgRequest;
449 return new TplValue( $wgRequest->getRequestURL(), 'dynamic' );
452 function subject_url() {
453 $title = $this->getSubjectPage();
454 if ( $title->exists() ) {
455 $url = $title->getLocalUrl();
456 } else {
457 $url = $title->getLocalUrl( 'action=edit' );
459 return new TplValue( $url, 'title' );
462 function talk_url() {
463 $title = $this->getTalkPage();
464 if ( $title->exists() ) {
465 $url = $title->getLocalUrl();
466 } else {
467 $url = $title->getLocalUrl( 'action=edit' );
469 return new TplValue( $url, 'title' );
472 function edit_url() {
473 return new TplValue( $this->getEditUrl(), array( 'title', 'nonview dynamic' ) );
476 function move_url() {
477 return new TplValue( $this->makeSpecialParamUrl( 'Movepage' ), array(), true );
480 function localurl( $query ) {
481 return new TplValue( $this->mTitle->getLocalURL( $query ), 'title' );
484 function selecttab( $tab, $extraclass = '' ) {
485 if ( !isset( $this->mSelectedTab ) ) {
486 $prevent_active_tabs = false ;
487 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$preventActiveTabs ) );
489 $actionTabs = array(
490 'edit' => 'edit',
491 'submit' => 'edit',
492 'history' => 'history',
493 'protect' => 'protect',
494 'unprotect' => 'protect',
495 'delete' => 'delete',
496 'watch' => 'watch',
497 'unwatch' => 'watch',
499 if ( $preventActiveTabs ) {
500 $this->mSelectedTab = false;
501 } else {
502 $action = $this->getAction();
503 $section = $this->getSection();
505 if ( isset( $actionTabs[$action] ) ) {
506 $this->mSelectedTab = $actionTabs[$action];
508 if ( $this->mSelectedTab == 'edit' && $section == 'new' ) {
509 $this->mSelectedTab = 'addsection';
511 } elseif ( $this->mTitle->isTalkPage() ) {
512 $this->mSelectedTab = 'talk';
513 } else {
514 $this->mSelectedTab = 'subject';
518 if ( $extraclass ) {
519 if ( $this->mSelectedTab == $tab ) {
520 $s = 'class="selected ' . htmlspecialchars( $extraclass ) . '"';
521 } else {
522 $s = 'class="' . htmlspecialchars( $extraclass ) . '"';
524 } else {
525 if ( $this->mSelectedTab == $tab ) {
526 $s = 'class="selected"';
527 } else {
528 $s = '';
531 return new TplValue( $s, array( 'nonview dynamic', 'title' ) );
534 function subject_newclass() {
535 $title = $this->getSubjectPage();
536 $class = $title->exists() ? '' : 'new';
537 return new TplValue( $class, 'dynamic' );
540 function talk_newclass() {
541 $title = $this->getTalkPage();
542 $class = $title->exists() ? '' : 'new';
543 return new TplValue( $class, 'dynamic' );
546 function ca_variant( $code, $name, $index, $template ) {
547 global $wgContLang;
548 $selected = ($code == $wgContLang->getPreferredVariant());
549 $action = $this->getAction();
550 $actstr = '';
551 if( $action )
552 $actstr = 'action=' . $action . '&';
553 $s = strtr( $template, array(
554 '$id' => htmlspecialchars( 'varlang-' . $index ),
555 '$class' => $selected ? 'class="selected"' : '',
556 '$text' => $name,
557 '$href' => htmlspecialchars( $this->mTitle->getLocalUrl( $actstr . 'variant=' . $code ) )
559 return new TplValue( $s, 'dynamic' );
562 function is_watching() {
563 return new TplValue( (string)$this->mTitle->userIsWatching(), array( 'dynamic' ) );
567 function personal_urls( $itemTemplate ) {
568 global $wgShowIPinHeader, $wgContLang;
570 # Split this function up into many small functions, to obtain the
571 # best specificity in the dependencies of each one. The template below
572 # has no dependencies, so its generation, and any static subfunctions,
573 # can be optimised away.
574 $etpl = templateEscape( $itemTemplate );
575 $s = "
576 {userpage {{$etpl}}}
577 {mytalk {{$etpl}}}
578 {preferences {{$etpl}}}
579 {watchlist {{$etpl}}}
580 {mycontris {{$etpl}}}
581 {logout {{$etpl}}}
585 if ( $wgShowIPinHeader ) {
586 $s .= "
587 {anonuserpage {{$etpl}}}
588 {anontalk {{$etpl}}}
589 {anonlogin {{$etpl}}}
591 } else {
592 $s .= "{login {{$etpl}}\n";
594 // No dependencies
595 return new TplValue( $s, array(), true /*this is a template*/ );
598 function userpage( $itemTemplate ) {
599 global $wgUser;
600 if ( $this->isLoggedIn() ) {
601 $userPage = $this->getUserPageTitle();
602 $s = $this->makeTemplateLink( $itemTemplate, 'userpage', $userPage, $wgUser->getName() );
603 } else {
604 $s = '';
606 return new TplValue( $s, 'user' );
609 function mytalk( $itemTemplate ) {
610 global $wgUser;
611 if ( $this->isLoggedIn() ) {
612 $userPage = $this->getUserPageTitle();
613 $talkPage = $userPage->getTalkPage();
614 $s = $this->makeTemplateLink( $itemTemplate, 'mytalk', $talkPage, wfMsg('mytalk') );
615 } else {
616 $s = '';
618 return new TplValue( $s, 'user' );
621 function preferences( $itemTemplate ) {
622 if ( $this->isLoggedIn() ) {
623 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'preferences',
624 'Preferences', wfMsg( 'preferences' ) );
625 } else {
626 $s = '';
628 return new TplValue( $s, array( 'loggedin', 'lang' ) );
631 function watchlist( $itemTemplate ) {
632 if ( $this->isLoggedIn() ) {
633 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'watchlist',
634 'Watchlist', wfMsg( 'watchlist' ) );
635 } else {
636 $s = '';
638 return new TplValue( $s, array( 'loggedin', 'lang' ) );
641 function mycontris( $itemTemplate ) {
642 if ( $this->isLoggedIn() ) {
643 global $wgUser;
644 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'mycontris',
645 "Contributions/" . $wgUser->getTitleKey(), wfMsg('mycontris') );
646 } else {
647 $s = '';
649 return new TplValue( $s, 'user' );
652 function logout( $itemTemplate ) {
653 if ( $this->isLoggedIn() ) {
654 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'logout',
655 'Userlogout', wfMsg( 'userlogout' ),
656 $this->mTitle->getNamespace() === NS_SPECIAL && $this->mTitle->getText() === 'Preferences'
657 ? '' : "returnto=" . $this->mTitle->getPrefixedURL() );
658 } else {
659 $s = '';
661 return new TplValue( $s, 'loggedin dynamic' );
664 function anonuserpage( $itemTemplate ) {
665 if ( $this->isLoggedIn() ) {
666 $s = '';
667 } else {
668 global $wgUser;
669 $userPage = $this->getUserPageTitle();
670 $s = $this->makeTemplateLink( $itemTemplate, 'userpage', $userPage, $wgUser->getName() );
672 return new TplValue( $s, '!loggedin dynamic' );
675 function anontalk( $itemTemplate ) {
676 if ( $this->isLoggedIn() ) {
677 $s = '';
678 } else {
679 $userPage = $this->getUserPageTitle();
680 $talkPage = $userPage->getTalkPage();
681 $s = $this->makeTemplateLink( $itemTemplate, 'mytalk', $talkPage, wfMsg('anontalk') );
683 return new TplValue( $s, '!loggedin dynamic' );
686 function anonlogin( $itemTemplate ) {
687 if ( $this->isLoggedIn() ) {
688 $s = '';
689 } else {
690 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'anonlogin', 'Userlogin',
691 wfMsg( 'userlogin' ), 'returnto=' . urlencode( $this->getThisPDBK() ) );
693 return new TplValue( $s, '!loggedin dynamic' );
696 function login( $itemTemplate ) {
697 if ( $this->isLoggedIn() ) {
698 $s = '';
699 } else {
700 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'login', 'Userlogin',
701 wfMsg( 'userlogin' ), 'returnto=' . urlencode( $this->getThisPDBK() ) );
703 return new TplValue( $s, '!loggedin dynamic' );
706 function logopath() { return $GLOBALS['wgLogo']; }
707 function mainpage() { return $this->makeI18nUrl( 'mainpage' ); }
709 function sidebar( $startSection, $endSection, $innerTpl ) {
710 $s = '';
711 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
712 $firstSection = true;
713 foreach ($lines as $line) {
714 if (strpos($line, '*') !== 0)
715 continue;
716 if (strpos($line, '**') !== 0) {
717 $bar = trim($line, '* ');
718 $name = wfMsg( $bar );
719 if (wfEmptyMsg($bar, $name)) {
720 $name = $bar;
722 if ( $firstSection ) {
723 $firstSection = false;
724 } else {
725 $s .= $endSection;
727 $s .= strtr( $startSection,
728 array(
729 '$bar' => htmlspecialchars( $bar ),
730 '$barname' => $name
731 ) );
732 } else {
733 if (strpos($line, '|') !== false) { // sanity check
734 $line = explode( '|' , trim($line, '* '), 2 );
735 $link = wfMsgForContent( $line[0] );
736 if ($link == '-')
737 continue;
738 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
739 $text = $line[1];
740 if (wfEmptyMsg($line[0], $link))
741 $link = $line[0];
742 $href = $this->makeInternalOrExternalUrl( $link );
744 $s .= strtr( $innerTpl,
745 array(
746 '$text' => htmlspecialchars( $text ),
747 '$href' => htmlspecialchars( $href ),
748 '$id' => htmlspecialchars( 'n-' . strtr($line[1], ' ', '-') ),
749 '$classactive' => ''
750 ) );
751 } else { continue; }
754 if ( !$firstSection ) {
755 $s .= $endSection;
758 // Depends on user language only
759 return new TplValue( $s, 'lang' );
762 function searchaction() {
763 // Static link
764 return $this->getSearchLink();
767 function search() {
768 global $wgRequest;
769 return new TplValue( trim( $this->getSearch() ), 'special dynamic' );
772 function notspecialpage() {
773 return new TplValue( $this->mTitle->getNamespace() != NS_SPECIAL, 'special' );
776 function nav_whatlinkshere() {
777 return new TplValue( $this->makeSpecialParamUrl('Whatlinkshere' ), array(), true );
780 function article_exists() {
781 return new TplValue( (string)($this->mTitle->getArticleId() !== 0), 'title' );
784 function nav_recentchangeslinked() {
785 return new TplValue( $this->makeSpecialParamUrl('Recentchangeslinked' ), array(), true );
788 function feeds( $itemTemplate = '' ) {
789 if ( !$this->mOut->isSyndicated() ) {
790 $feeds = '';
791 } elseif ( $itemTemplate == '' ) {
792 // boolean only required
793 $feeds = 'true';
794 } else {
795 $feeds = '';
796 global $wgFeedClasses, $wgRequest;
797 foreach( $wgFeedClasses as $format => $class ) {
798 $feeds .= strtr( $itemTemplate,
799 array(
800 '$key' => htmlspecialchars( $format ),
801 '$text' => $format,
802 '$href' => $wgRequest->appendQuery( "feed=$format" )
803 ) );
806 return new TplValue( $feeds, 'special dynamic' );
809 function is_userpage() {
810 list( $id, $ip ) = $this->getUserPageIdIp();
811 return new TplValue( (string)($id || $ip), 'title' );
814 function is_ns_mediawiki() {
815 return new TplValue( (string)$this->mTitle->getNamespace() == NS_MEDIAWIKI, 'title' );
818 function is_loggedin() {
819 global $wgUser;
820 return new TplValue( (string)($wgUser->isLoggedIn()), 'loggedin' );
823 function nav_contributions() {
824 $url = $this->makeSpecialParamUrl( 'Contributions', '', '{title_userurl}' );
825 return new TplValue( $url, array(), true );
828 function is_allowed( $right ) {
829 global $wgUser;
830 return new TplValue( (string)$wgUser->isAllowed( $right ), 'user' );
833 function nav_blockip() {
834 $url = $this->makeSpecialParamUrl( 'Blockip', '', '{title_userurl}' );
835 return new TplValue( $url, array(), true );
838 function nav_emailuser() {
839 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
840 if ( !$wgEnableEmail || !$wgEnableUserEmail ) return '';
842 $url = $this->makeSpecialParamUrl( 'Emailuser', '', '{title_userurl}' );
843 return new TplValue( $url, array(), true );
846 function nav_upload() {
847 global $wgEnableUploads, $wgUploadNavigationUrl;
848 if ( !$wgEnableUploads ) {
849 return '';
850 } elseif ( $wgUploadNavigationUrl ) {
851 return $wgUploadNavigationUrl;
852 } else {
853 return $this->makeSpecialUrl('Upload');
857 function nav_specialpages() {
858 return $this->makeSpecialUrl('Specialpages');
861 function nav_print() {
862 global $wgRequest, $wgArticle;
863 $action = $this->getAction();
864 $url = '';
865 if( $this->mTitle->getNamespace() !== NS_SPECIAL
866 && ($action == '' || $action == 'view' || $action == 'purge' ) )
868 $revid = $wgArticle->getLatest();
869 if ( $revid != 0 ) {
870 $url = $wgRequest->appendQuery( 'printable=yes' );
873 return new TplValue( $url, array( 'nonview dynamic', 'title' ) );
876 function nav_permalink() {
877 $url = (string)$this->getPermalink();
878 return new TplValue( $url, 'dynamic' );
881 function nav_trackbacklink() {
882 global $wgUseTrackbacks;
883 if ( !$wgUseTrackbacks ) return '';
885 return new TplValue( $this->mTitle->trackbackURL(), 'title' );
888 function is_permalink() {
889 return new TplValue( (string)($this->getPermalink() === false), 'nonview dynamic' );
892 function toolboxend() {
893 // This is where the MonoBookTemplateToolboxEnd hook went in the old skin
894 return '';
897 function language_urls( $outer, $inner ) {
898 global $wgHideInterlanguageLinks, $wgOut, $wgContLang;
899 if ( $wgHideInterlanguageLinks ) return '';
901 $links = $wgOut->getLanguageLinks();
902 $s = '';
903 if ( count( $links ) ) {
904 foreach( $links as $l ) {
905 $tmp = explode( ':', $l, 2 );
906 $nt = Title::newFromText( $l );
907 $s .= strtr( $inner,
908 array(
909 '$class' => htmlspecialchars( 'interwiki-' . $tmp[0] ),
910 '$href' => htmlspecialchars( $nt->getFullURL() ),
911 '$text' => ($wgContLang->getLanguageName( $nt->getInterwiki() ) != ''?
912 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
916 $s = str_replace( '$body', $s, $outer );
918 return new TplValue( $s, 'dynamic' );
921 function poweredbyico() { return $this->getPoweredBy(); }
922 function copyrightico() { return $this->getCopyrightIcon(); }
924 function lastmod() {
925 global $wgMaxCredits;
926 if ( $wgMaxCredits ) return '';
928 if ( $this->isCurrentArticleView() ) {
929 $s = $this->lastModified();
930 } else {
931 $s = '';
933 return new TplValue( $s, 'dynamic' );
936 function viewcount() {
937 global $wgDisableCounters;
938 if ( $wgDisableCounters ) return '';
940 global $wgLang, $wgArticle;
941 if ( is_object( $wgArticle ) ) {
942 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
943 if ( $viewcount ) {
944 $viewcount = wfMsg( "viewcount", $viewcount );
945 } else {
946 $viewcount = '';
948 } else {
949 $viewcount = '';
951 return new TplValue( $viewcount, 'dynamic' );
954 function numberofwatchingusers() {
955 global $wgPageShowWatchingUsers;
956 if ( !$wgPageShowWatchingUsers ) return '';
958 $dbr =& wfGetDB( DB_SLAVE );
959 extract( $dbr->tableNames( 'watchlist' ) );
960 $sql = "SELECT COUNT(*) AS n FROM $watchlist
961 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBKey()) .
962 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
963 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
964 $row = $dbr->fetchObject( $res );
965 $num = $row->n;
966 if ($num > 0) {
967 $s = wfMsg('number_of_watching_users_pageview', $num);
968 } else {
969 $s = '';
971 return new TplValue( $s, 'dynamic' );
974 function credits() {
975 global $wgMaxCredits;
976 if ( !$wgMaxCredits ) return '';
978 if ( $this->isCurrentArticleView() ) {
979 require_once("Credits.php");
980 global $wgArticle, $wgShowCreditsIfMax;
981 $credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
982 } else {
983 $credits = '';
985 return new TplValue( $credits, 'view dynamic' );
988 function normalcopyright() {
989 return $this->getCopyright( 'normal' );
992 function historycopyright() {
993 return $this->getCopyright( 'history' );
996 function is_currentview() {
997 global $wgRequest;
998 return new TplValue( (string)$this->isCurrentArticleView(), 'view' );
1001 function usehistorycopyright() {
1002 global $wgRequest;
1003 if ( wfMsgForContent( 'history_copyright' ) == '-' ) return '';
1005 $oldid = $this->getOldId();
1006 $diff = $this->getDiff();
1007 $use = (string)(!is_null( $oldid ) && is_null( $diff ));
1008 return new TplValue( $use, 'nonview dynamic' );
1011 function privacy() {
1012 return new TplValue( $this->privacyLink(), 'lang' );
1014 function about() {
1015 return new TplValue( $this->aboutLink(), 'lang' );
1017 function disclaimer() {
1018 return new TplValue( $this->disclaimerLink(), 'lang' );
1020 function tagline() {
1021 # A reference to this tag existed in the old MonoBook.php, but the
1022 # template data wasn't set anywhere
1023 return '';
1025 function reporttime() {
1026 return new TplValue( $this->mOut->reportTime(), 'dynamic' );
1029 function msg( $name ) {
1030 return new TplValue( wfMsg( $name ), 'lang' );
1033 function fallbackmsg( $name, $fallback ) {
1034 $text = wfMsg( $name );
1035 if ( wfEmptyMsg( $name, $text ) ) {
1036 $text = $fallback;
1038 return new TplValue( $text, 'lang' );
1041 /******************************************************
1042 * Utility functions *
1043 ******************************************************/
1045 /** Return true if this request is a valid, secure CSS preview */
1046 function isCssPreview() {
1047 if ( !isset( $this->mCssPreview ) ) {
1048 global $wgRequest, $wgAllowUserCss, $wgUser;
1049 $this->mCssPreview =
1050 $wgAllowUserCss &&
1051 $wgUser->isLoggedIn() &&
1052 $this->mTitle->isCssSubpage() &&
1053 $this->userCanPreview( $this->getAction() );
1055 return $this->mCssPreview;
1058 /** Return true if this request is a valid, secure JS preview */
1059 function isJsPreview() {
1060 if ( !isset( $this->mJsPreview ) ) {
1061 global $wgRequest, $wgAllowUserJs, $wgUser;
1062 $this->mJsPreview =
1063 $wgAllowUserJs &&
1064 $wgUser->isLoggedIn() &&
1065 $this->mTitle->isJsSubpage() &&
1066 $this->userCanPreview( $this->getAction() );
1068 return $this->mJsPreview;
1071 /** Get the title of the $wgUser's user page */
1072 function getUserPageTitle() {
1073 if ( !isset( $this->mUserPageTitle ) ) {
1074 global $wgUser;
1075 $this->mUserPageTitle = $wgUser->getUserPage();
1077 return $this->mUserPageTitle;
1080 /** Get the text of the user page title */
1081 function getUserPageText() {
1082 if ( !isset( $this->mUserPageText ) ) {
1083 $userPage = $this->getUserPageTitle();
1084 $this->mUserPageText = $userPage->getPrefixedText();
1086 return $this->mUserPageText;
1089 /** Make an HTML element for a stylesheet link */
1090 function makeStylesheetLink( $url ) {
1091 return '<link rel="stylesheet" type="text/css" href="' . htmlspecialchars( $url ) . "\"/>";
1094 /** Make an XHTML element for inline CSS */
1095 function makeStylesheetCdata( $style ) {
1096 return "<style type=\"text/css\"> /*<![CDATA[*/ {$style} /*]]>*/ </style>";
1099 /** Get the edit URL for this page */
1100 function getEditUrl() {
1101 if ( !isset( $this->mEditUrl ) ) {
1102 $this->mEditUrl = $this->mTitle->getLocalUrl( $this->editUrlOptions() );
1104 return $this->mEditUrl;
1107 /** Get the prefixed DB key for this page */
1108 function getThisPDBK() {
1109 if ( !isset( $this->mThisPDBK ) ) {
1110 $this->mThisPDBK = $this->mTitle->getPrefixedDbKey();
1112 return $this->mThisPDBK;
1115 function getThisTitleUrlForm() {
1116 if ( !isset( $this->mThisTitleUrlForm ) ) {
1117 $this->mThisTitleUrlForm = $this->mTitle->getPrefixedURL();
1119 return $this->mThisTitleUrlForm;
1122 /**
1123 * If the current page is a user page, get the user's ID and IP. Otherwise return array(0,false)
1125 function getUserPageIdIp() {
1126 if ( !isset( $this->mUserPageId ) ) {
1127 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
1128 $this->mUserPageId = User::idFromName($this->mTitle->getText());
1129 $this->mUserPageIp = User::isIP($this->mTitle->getText());
1130 } else {
1131 $this->mUserPageId = 0;
1132 $this->mUserPageIp = false;
1135 return array( $this->mUserPageId, $this->mUserPageIp );
1139 * Returns a permalink URL, or false if the current page is already a
1140 * permalink, or blank if a permalink shouldn't be displayed
1142 function getPermalink() {
1143 if ( !isset( $this->mPermalink ) ) {
1144 global $wgRequest, $wgArticle;
1145 $action = $this->getAction();
1146 $oldid = $this->getOldId();
1147 $url = '';
1148 if( $this->mTitle->getNamespace() !== NS_SPECIAL
1149 && $this->mTitle->getArticleId() != 0
1150 && ($action == '' || $action == 'view' || $action == 'purge' ) )
1152 if ( !$oldid ) {
1153 $revid = $wgArticle->getLatest();
1154 $url = $this->mTitle->getLocalURL( "oldid=$revid" );
1155 } else {
1156 $url = false;
1158 } else {
1159 $url = '';
1162 return $url;
1166 * Returns true if the current page is an article, not a special page,
1167 * and we are viewing a revision, not a diff
1169 function isArticleView() {
1170 global $wgOut, $wgArticle, $wgRequest;
1171 if ( !isset( $this->mIsArticleView ) ) {
1172 $oldid = $this->getOldId();
1173 $diff = $this->getDiff();
1174 $this->mIsArticleView = $wgOut->isArticle() and
1175 (!is_null( $oldid ) or is_null( $diff )) and 0 != $wgArticle->getID();
1177 return $this->mIsArticleView;
1180 function isCurrentArticleView() {
1181 if ( !isset( $this->mIsCurrentArticleView ) ) {
1182 global $wgOut, $wgArticle, $wgRequest;
1183 $oldid = $this->getOldId();
1184 $this->mIsCurrentArticleView = $wgOut->isArticle() && is_null( $oldid ) && 0 != $wgArticle->getID();
1186 return $this->mIsCurrentArticleView;
1191 * Return true if the current page is editable; if edit section on right
1192 * click should be enabled.
1194 function isEditable() {
1195 global $wgRequest;
1196 $action = $this->getAction();
1197 return ($this->mTitle->getNamespace() != NS_SPECIAL and !($action == 'edit' or $action == 'submit'));
1200 /** Return true if the user is logged in */
1201 function isLoggedIn() {
1202 global $wgUser;
1203 return $wgUser->isLoggedIn();
1206 /** Get the local URL of the current page */
1207 function getPageUrl() {
1208 if ( !isset( $this->mPageUrl ) ) {
1209 $this->mPageUrl = $this->mTitle->getLocalURL();
1211 return $this->mPageUrl;
1214 /** Make a link to a title using a template */
1215 function makeTemplateLink( $template, $key, $title, $text ) {
1216 $url = $title->getLocalUrl();
1217 return strtr( $template,
1218 array(
1219 '$key' => $key,
1220 '$classactive' => ($url == $this->getPageUrl()) ? 'class="active"' : '',
1221 '$class' => $title->getArticleID() == 0 ? 'class="new"' : '',
1222 '$href' => htmlspecialchars( $url ),
1223 '$text' => $text
1224 ) );
1227 /** Make a link to a URL using a template */
1228 function makeTemplateLinkUrl( $template, $key, $url, $text ) {
1229 return strtr( $template,
1230 array(
1231 '$key' => $key,
1232 '$classactive' => ($url == $this->getPageUrl()) ? 'class="active"' : '',
1233 '$class' => '',
1234 '$href' => htmlspecialchars( $url ),
1235 '$text' => $text
1236 ) );
1239 /** Make a link to a special page using a template */
1240 function makeSpecialTemplateLink( $template, $key, $specialName, $text, $query = '' ) {
1241 $url = $this->makeSpecialUrl( $specialName, $query );
1242 // Ignore the query when comparing
1243 $active = ($this->mTitle->getNamespace() == NS_SPECIAL && $this->mTitle->getDBkey() == $specialName);
1244 return strtr( $template,
1245 array(
1246 '$key' => $key,
1247 '$classactive' => $active ? 'class="active"' : '',
1248 '$class' => '',
1249 '$href' => htmlspecialchars( $url ),
1250 '$text' => $text
1251 ) );
1254 function loadRequestValues() {
1255 global $wgRequest;
1256 $this->mAction = $wgRequest->getText( 'action' );
1257 $this->mOldId = $wgRequest->getVal( 'oldid' );
1258 $this->mDiff = $wgRequest->getVal( 'diff' );
1259 $this->mSection = $wgRequest->getVal( 'section' );
1260 $this->mSearch = $wgRequest->getVal( 'search' );
1261 $this->mRequestValuesLoaded = true;
1266 /** Get the action parameter of the request */
1267 function getAction() {
1268 if ( !isset( $this->mRequestValuesLoaded ) ) {
1269 $this->loadRequestValues();
1271 return $this->mAction;
1274 /** Get the oldid parameter */
1275 function getOldId() {
1276 if ( !isset( $this->mRequestValuesLoaded ) ) {
1277 $this->loadRequestValues();
1279 return $this->mOldId;
1282 /** Get the diff parameter */
1283 function getDiff() {
1284 if ( !isset( $this->mRequestValuesLoaded ) ) {
1285 $this->loadRequestValues();
1287 return $this->mDiff;
1290 function getSection() {
1291 if ( !isset( $this->mRequestValuesLoaded ) ) {
1292 $this->loadRequestValues();
1294 return $this->mSection;
1297 function getSearch() {
1298 if ( !isset( $this->mRequestValuesLoaded ) ) {
1299 $this->loadRequestValues();
1301 return $this->mSearch;
1304 /** Make a special page URL of the form [[Special:Somepage/{title_urlform}]] */
1305 function makeSpecialParamUrl( $name, $query = '', $param = '{title_urlform}' ) {
1306 // Abuse makeTitle's lax validity checking to slip a control character into the URL
1307 $title = Title::makeTitle( NS_SPECIAL, "$name/\x1a" );
1308 $url = templateEscape( $title->getLocalURL( $query ) );
1309 // Now replace it with the parameter
1310 return str_replace( '%1A', $param, $url );
1313 function getSubjectPage() {
1314 if ( !isset( $this->mSubjectPage ) ) {
1315 $this->mSubjectPage = $this->mTitle->getSubjectPage();
1317 return $this->mSubjectPage;
1320 function getTalkPage() {
1321 if ( !isset( $this->mTalkPage ) ) {
1322 $this->mTalkPage = $this->mTitle->getTalkPage();
1324 return $this->mTalkPage;