3 if ( !defined( 'MEDIAWIKI' ) ) {
4 die( "This file is part of MediaWiki, it is not a valid entry point\n" );
7 require_once( 'includes/cbt/CBTProcessor.php' );
8 require_once( 'includes/cbt/CBTCompiler.php' );
9 require_once( 'includes/SkinTemplate.php' );
12 * MonoBook clone using the new dependency-tracking template processor.
13 * EXPERIMENTAL - use only for testing and profiling at this stage.
15 * See includes/cbt/README for an explanation.
17 * The main thing that's missing is cache invalidation, on change of:
21 * * source code and configuration files
23 * The other thing is that lots of dependencies that are declared in the callbacks
24 * are not intelligently handled. There's some room for improvement there.
26 * The class is derived from SkinTemplate, but that's only temporary. Eventually
27 * it'll be derived from Skin, and I've avoided using SkinTemplate functions as
28 * much as possible. In fact, the only SkinTemplate dependencies I know of at the
29 * moment are the functions to generate the gen=css and gen=js files.
32 class SkinMonoBookCBT
extends SkinTemplate
{
34 var $mStyleName = 'monobook';
35 var $mCompiling = false;
36 var $mFunctionCache = array();
38 /******************************************************
40 ******************************************************/
42 /** Execute the template and write out the result */
43 function outputPage( &$out ) {
44 echo $this->execute( $out );
47 function execute( &$out ) {
48 global $wgTitle, $wgStyleDirectory, $wgParserCacheType;
49 $fname = 'SkinMonoBookCBT::execute';
50 wfProfileIn( $fname );
51 wfProfileIn( "$fname-setup" );
52 Skin
::initPage( $out );
55 $this->mTitle
=& $wgTitle;
57 $sourceFile = "$wgStyleDirectory/MonoBook.tpl";
59 wfProfileOut( "$fname-setup" );
61 if ( $wgParserCacheType == CACHE_NONE
) {
62 $template = file_get_contents( $sourceFile );
63 $text = $this->executeTemplate( $template );
65 $compiled = $this->getCompiledTemplate( $sourceFile );
67 wfProfileIn( "$fname-eval" );
68 $text = eval( $compiled );
69 wfProfileOut( "$fname-eval" );
71 wfProfileOut( $fname );
75 function getCompiledTemplate( $sourceFile ) {
76 global $wgDBname, $wgMemc, $wgRequest, $wgUser, $parserMemc;
77 $fname = 'SkinMonoBookCBT::getCompiledTemplate';
81 // Sandbox template execution
82 if ( $this->mCompiling
) {
86 wfProfileIn( $fname );
88 // Is the request an ordinary page view?
89 if ( $wgRequest->wasPosted() ||
90 count( array_diff( array_keys( $_GET ), array( 'title', 'useskin', 'recompile' ) ) ) != 0 )
97 // Per-user compiled template
98 // Put all logged-out users on the same cache key
99 $cacheKey = "$wgDBname:monobookcbt:$type:" . $wgUser->getId();
101 $recompile = $wgRequest->getVal( 'recompile' );
102 if ( $recompile == 'user' ) {
103 $recompileUser = true;
104 $recompileGeneric = false;
105 } elseif ( $recompile ) {
106 $recompileUser = true;
107 $recompileGeneric = true;
109 $recompileUser = false;
110 $recompileGeneric = false;
113 if ( !$recompileUser ) {
114 $php = $parserMemc->get( $cacheKey );
116 if ( $recompileUser ||
!$php ) {
117 if ( $wgUser->isLoggedIn() ) {
118 // Perform staged compilation
119 // First compile a generic template for all logged-in users
120 $genericKey = "$wgDBname:monobookcbt:$type:loggedin";
121 if ( !$recompileGeneric ) {
122 $template = $parserMemc->get( $genericKey );
124 if ( $recompileGeneric ||
!$template ) {
125 $template = file_get_contents( $sourceFile );
126 $ignore = array( 'loggedin', '!loggedin dynamic' );
127 if ( $type == 'view' ) {
128 $ignore[] = 'nonview dynamic';
130 $template = $this->compileTemplate( $template, $ignore );
131 $parserMemc->set( $genericKey, $template, $expiry );
134 $template = file_get_contents( $sourceFile );
137 $ignore = array( 'lang', 'loggedin', 'user' );
138 if ( $wgUser->isLoggedIn() ) {
139 $ignore[] = '!loggedin dynamic';
141 $ignore[] = 'loggedin dynamic';
143 if ( $type == 'view' ) {
144 $ignore[] = 'nonview dynamic';
146 $compiled = $this->compileTemplate( $template, $ignore );
149 // This is done here instead of in CBTProcessor because we can be
150 // more sure it is safe here.
151 $compiled = preg_replace( '/^[ \t]+/m', '', $compiled );
152 $compiled = preg_replace( '/[\r\n]+/', "\n", $compiled );
155 $compiler = new CBTCompiler( $compiled );
156 $ret = $compiler->compile();
157 if ( $ret !== true ) {
161 $php = $compiler->generatePHP( '$this' );
163 $parserMemc->set( $cacheKey, $php, $expiry );
165 wfProfileOut( $fname );
169 function compileTemplate( $template, $ignore ) {
170 $tp = new CBTProcessor( $template, $this, $ignore );
171 $tp->mFunctionCache
= $this->mFunctionCache
;
173 $this->mCompiling
= true;
174 $compiled = $tp->compile();
175 $this->mCompiling
= false;
177 if ( $tp->getLastError() ) {
178 // If there was a compile error, don't save the template
179 // Instead just print the error and exit
183 $this->mFunctionCache
= $tp->mFunctionCache
;
187 function executeTemplate( $template ) {
188 $fname = 'SkinMonoBookCBT::executeTemplate';
189 wfProfileIn( $fname );
190 $tp = new CBTProcessor( $template, $this );
191 $tp->mFunctionCache
= $this->mFunctionCache
;
193 $this->mCompiling
= true;
194 $text = $tp->execute();
195 $this->mCompiling
= false;
197 $this->mFunctionCache
= $tp->mFunctionCache
;
198 wfProfileOut( $fname );
202 /******************************************************
204 ******************************************************/
206 function lang() { return $GLOBALS['wgContLanguageCode']; }
210 return $wgContLang->isRTL() ?
'rtl' : 'ltr';
213 function mimetype() { return $GLOBALS['wgMimeType']; }
214 function charset() { return $GLOBALS['wgOutputEncoding']; }
215 function headlinks() {
216 return cbt_value( $this->mOut
->getHeadLinks(), 'dynamic' );
218 function headscripts() {
219 return cbt_value( $this->mOut
->getScript(), 'dynamic' );
222 function pagetitle() {
223 return cbt_value( $this->mOut
->getHTMLTitle(), array( 'title', 'lang' ) );
226 function stylepath() { return $GLOBALS['wgStylePath']; }
227 function stylename() { return $this->mStyleName
; }
229 function notprintable() {
231 return cbt_value( !$wgRequest->getBool( 'printable' ), 'nonview dynamic' );
234 function jsmimetype() { return $GLOBALS['wgJsMimeType']; }
236 function jsvarurl() {
237 global $wgUseSiteJs, $wgUser;
238 if ( !$wgUseSiteJs ) return '';
240 if ( $wgUser->isLoggedIn() ) {
241 $url = self
::makeUrl( '-','action=raw&smaxage=0&gen=js' );
243 $url = self
::makeUrl( '-','action=raw&gen=js' );
245 return cbt_value( $url, 'loggedin' );
252 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
254 // Unknown dependencies
255 return cbt_value( $out, 'dynamic' );
259 if ( $this->isCssPreview() ) {
261 $usercss = $this->makeStylesheetCdata( $wgRequest->getText('wpTextbox1') );
263 $usercss = $this->makeStylesheetLink( self
::makeUrl($this->getUserPageText() .
264 '/'.$this->mStyleName
.'.css', 'action=raw&ctype=text/css' ) );
267 // Dynamic when not an ordinary page view, also depends on the username
268 return cbt_value( $usercss, array( 'nonview dynamic', 'user' ) );
272 global $wgUseSiteCss;
273 if ( !$wgUseSiteCss ) {
277 global $wgSquidMaxage, $wgContLang, $wgStylePath;
279 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
282 if ( $wgContLang->isRTL() ) {
283 $sitecss .= $this->makeStylesheetLink( $wgStylePath . '/' . $this->mStyleName
. '/rtl.css' ) . "\n";
286 $sitecss .= $this->makeStylesheetLink( self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) ) . "\n";
287 $sitecss .= $this->makeStylesheetLink( self
::makeNSUrl( ucfirst( $this->mStyleName
) . '.css', $query, NS_MEDIAWIKI
) ) . "\n";
294 global $wgUseSiteCss;
295 if ( !$wgUseSiteCss ) return '';
297 global $wgSquidMaxage, $wgUser, $wgAllowUserCss;
298 if ( $this->isCssPreview() ) {
299 $siteargs = '&smaxage=0&maxage=0';
301 $siteargs = '&maxage=' . $wgSquidMaxage;
303 if ( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
304 $siteargs .= '&ts={user_touched}';
310 $link = $this->makeStylesheetLink( self
::makeUrl('-','action=raw&gen=css' . $siteargs) ) . "\n";
312 if ( $wgAllowUserCss ) {
317 return cbt_value( $link, $deps, $isTemplate );
320 function user_touched() {
322 return cbt_value( $wgUser->mTouched
, 'dynamic' );
326 global $wgAllowUserJs, $wgJsMimeType;
327 if ( !$wgAllowUserJs ) return '';
329 if ( $this->isJsPreview() ) {
332 $url = self
::makeUrl($this->getUserPageText().'/'.$this->mStyleName
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
334 return cbt_value( $url, array( 'nonview dynamic', 'user' ) );
337 function userjsprev() {
338 global $wgAllowUserJs, $wgRequest;
339 if ( !$wgAllowUserJs ) return '';
340 if ( $this->isJsPreview() ) {
341 $js = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
345 return cbt_value( $js, array( 'nonview dynamic' ) );
348 function trackbackhtml() {
349 global $wgUseTrackbacks;
350 if ( !$wgUseTrackbacks ) return '';
352 if ( $this->mOut
->isArticleRelated() ) {
353 $tb = $this->mTitle
->trackbackRDF();
357 return cbt_value( $tb, 'dynamic' );
360 function body_ondblclick() {
362 if( $this->isEditable() && $wgUser->getOption("editondblclick") ) {
363 $js = 'document.location = "' . $this->getEditUrl() .'";';
368 if ( User
::getDefaultOption('editondblclick') ) {
369 return cbt_value( $js, 'user', 'title' );
371 // Optimise away for logged-out users
372 return cbt_value( $js, 'loggedin dynamic' );
376 function body_onload() {
378 if ( $this->isEditable() && $wgUser->getOption( 'editsectiononrightclick' ) ) {
379 $js = 'setupRightClickEdit()';
383 return cbt_value( $js, 'loggedin dynamic' );
387 return cbt_value( 'ns-' . $this->mTitle
->getNamespace(), 'title' );
390 function sitenotice() {
391 // Perhaps this could be given special dependencies using our knowledge of what
392 // wfGetSiteNotice() depends on.
393 return cbt_value( wfGetSiteNotice(), 'dynamic' );
397 return cbt_value( $this->mOut
->getPageTitle(), array( 'title', 'lang' ) );
400 function title_urlform() {
401 return cbt_value( $this->getThisTitleUrlForm(), 'title' );
404 function title_userurl() {
405 return cbt_value( urlencode( $this->mTitle
->getDBkey() ), 'title' );
408 function subtitle() {
409 $subpagestr = $this->subPageSubtitle();
410 if ( !empty( $subpagestr ) ) {
411 $s = '<span class="subpages">'.$subpagestr.'</span>'.$this->mOut
->getSubtitle();
413 $s = $this->mOut
->getSubtitle();
415 return cbt_value( $s, array( 'title', 'nonview dynamic' ) );
418 function undelete() {
419 return cbt_value( $this->getUndeleteLink(), array( 'title', 'lang' ) );
423 global $wgUser, $wgDBname;
424 $newtalks = $wgUser->getNewMessageLinks();
426 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === $wgDBname) {
427 $usertitle = $this->getUserPageTitle();
428 $usertalktitle = $usertitle->getTalkPage();
429 if( !$usertalktitle->equals( $this->mTitle
) ) {
430 $ntl = wfMsg( 'youhavenewmessages',
431 $this->makeKnownLinkObj(
433 wfMsgHtml( 'newmessageslink' ),
436 $this->makeKnownLinkObj(
438 wfMsgHtml( 'newmessagesdifflink' ),
443 $this->mOut
->setSquidMaxage(0);
445 } else if (count($newtalks)) {
446 $sep = str_replace("_", " ", wfMsgHtml("newtalkseparator"));
448 foreach ($newtalks as $newtalk) {
449 $msgs[] = wfElement("a",
450 array('href' => $newtalk["link"]), $newtalk["wiki"]);
452 $parts = implode($sep, $msgs);
453 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
454 $this->mOut
->setSquidMaxage(0);
458 return cbt_value( $ntl, 'dynamic' );
461 function showjumplinks() {
463 return cbt_value( $wgUser->getOption( 'showjumplinks' ) ?
'true' : '', 'user' );
466 function bodytext() {
467 return cbt_value( $this->mOut
->getHTML(), 'dynamic' );
470 function catlinks() {
471 if ( !isset( $this->mCatlinks
) ) {
472 $this->mCatlinks
= $this->getCategories();
474 return cbt_value( $this->mCatlinks
, 'dynamic' );
477 function extratabs( $itemTemplate ) {
478 global $wgContLang, $wgDisableLangConversion;
480 $etpl = cbt_escape( $itemTemplate );
482 /* show links to different language variants */
483 $variants = $wgContLang->getVariants();
485 if ( !$wgDisableLangConversion && count( $wgContLang->getVariants() ) > 1 ) {
487 foreach ( $variants as $code ) {
488 $name = $wgContLang->getVariantname( $code );
489 if ( $name == 'disable' ) {
492 $code = cbt_escape( $code );
493 $name = cbt_escape( $name );
494 $s .= "{ca_variant {{$code}} {{$name}} {{$vcount}} {{$etpl}}}\n";
498 return cbt_value( $s, array(), true );
501 function is_special() { return cbt_value( $this->mTitle
->getNamespace() == NS_SPECIAL
, 'title' ); }
502 function can_edit() { return cbt_value( (string)($this->mTitle
->userCan( 'edit' )), 'dynamic' ); }
503 function can_move() { return cbt_value( (string)($this->mTitle
->userCan( 'move' )), 'dynamic' ); }
504 function is_talk() { return cbt_value( (string)($this->mTitle
->isTalkPage()), 'title' ); }
505 function is_protected() { return cbt_value( (string)$this->mTitle
->isProtected(), 'dynamic' ); }
506 function nskey() { return cbt_value( $this->mTitle
->getNamespaceKey(), 'title' ); }
508 function request_url() {
510 return cbt_value( $wgRequest->getRequestURL(), 'dynamic' );
513 function subject_url() {
514 $title = $this->getSubjectPage();
515 if ( $title->exists() ) {
516 $url = $title->getLocalUrl();
518 $url = $title->getLocalUrl( 'action=edit' );
520 return cbt_value( $url, 'title' );
523 function talk_url() {
524 $title = $this->getTalkPage();
525 if ( $title->exists() ) {
526 $url = $title->getLocalUrl();
528 $url = $title->getLocalUrl( 'action=edit' );
530 return cbt_value( $url, 'title' );
533 function edit_url() {
534 return cbt_value( $this->getEditUrl(), array( 'title', 'nonview dynamic' ) );
537 function move_url() {
538 return cbt_value( $this->makeSpecialParamUrl( 'Movepage' ), array(), true );
541 function localurl( $query ) {
542 return cbt_value( $this->mTitle
->getLocalURL( $query ), 'title' );
545 function selecttab( $tab, $extraclass = '' ) {
546 if ( !isset( $this->mSelectedTab
) ) {
547 $prevent_active_tabs = false ;
548 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$preventActiveTabs ) );
553 'history' => 'history',
554 'protect' => 'protect',
555 'unprotect' => 'protect',
556 'delete' => 'delete',
558 'unwatch' => 'watch',
560 if ( $preventActiveTabs ) {
561 $this->mSelectedTab
= false;
563 $action = $this->getAction();
564 $section = $this->getSection();
566 if ( isset( $actionTabs[$action] ) ) {
567 $this->mSelectedTab
= $actionTabs[$action];
569 if ( $this->mSelectedTab
== 'edit' && $section == 'new' ) {
570 $this->mSelectedTab
= 'addsection';
572 } elseif ( $this->mTitle
->isTalkPage() ) {
573 $this->mSelectedTab
= 'talk';
575 $this->mSelectedTab
= 'subject';
580 if ( $this->mSelectedTab
== $tab ) {
581 $s = 'class="selected ' . htmlspecialchars( $extraclass ) . '"';
583 $s = 'class="' . htmlspecialchars( $extraclass ) . '"';
586 if ( $this->mSelectedTab
== $tab ) {
587 $s = 'class="selected"';
592 return cbt_value( $s, array( 'nonview dynamic', 'title' ) );
595 function subject_newclass() {
596 $title = $this->getSubjectPage();
597 $class = $title->exists() ?
'' : 'new';
598 return cbt_value( $class, 'dynamic' );
601 function talk_newclass() {
602 $title = $this->getTalkPage();
603 $class = $title->exists() ?
'' : 'new';
604 return cbt_value( $class, 'dynamic' );
607 function ca_variant( $code, $name, $index, $template ) {
609 $selected = ($code == $wgContLang->getPreferredVariant());
610 $action = $this->getAction();
613 $actstr = 'action=' . $action . '&';
614 $s = strtr( $template, array(
615 '$id' => htmlspecialchars( 'varlang-' . $index ),
616 '$class' => $selected ?
'class="selected"' : '',
618 '$href' => htmlspecialchars( $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code ) )
620 return cbt_value( $s, 'dynamic' );
623 function is_watching() {
624 return cbt_value( (string)$this->mTitle
->userIsWatching(), array( 'dynamic' ) );
628 function personal_urls( $itemTemplate ) {
629 global $wgShowIPinHeader, $wgContLang;
631 # Split this function up into many small functions, to obtain the
632 # best specificity in the dependencies of each one. The template below
633 # has no dependencies, so its generation, and any static subfunctions,
634 # can be optimised away.
635 $etpl = cbt_escape( $itemTemplate );
639 {preferences {{$etpl}}}
640 {watchlist {{$etpl}}}
641 {mycontris {{$etpl}}}
645 if ( $wgShowIPinHeader ) {
647 {anonuserpage {{$etpl}}}
649 {anonlogin {{$etpl}}}
652 $s .= "{login {{$etpl}}}\n";
655 return cbt_value( $s, array(), true /*this is a template*/ );
658 function userpage( $itemTemplate ) {
660 if ( $this->isLoggedIn() ) {
661 $userPage = $this->getUserPageTitle();
662 $s = $this->makeTemplateLink( $itemTemplate, 'userpage', $userPage, $wgUser->getName() );
666 return cbt_value( $s, 'user' );
669 function mytalk( $itemTemplate ) {
671 if ( $this->isLoggedIn() ) {
672 $userPage = $this->getUserPageTitle();
673 $talkPage = $userPage->getTalkPage();
674 $s = $this->makeTemplateLink( $itemTemplate, 'mytalk', $talkPage, wfMsg('mytalk') );
678 return cbt_value( $s, 'user' );
681 function preferences( $itemTemplate ) {
682 if ( $this->isLoggedIn() ) {
683 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'preferences',
684 'Preferences', wfMsg( 'preferences' ) );
688 return cbt_value( $s, array( 'loggedin', 'lang' ) );
691 function watchlist( $itemTemplate ) {
692 if ( $this->isLoggedIn() ) {
693 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'watchlist',
694 'Watchlist', wfMsg( 'watchlist' ) );
698 return cbt_value( $s, array( 'loggedin', 'lang' ) );
701 function mycontris( $itemTemplate ) {
702 if ( $this->isLoggedIn() ) {
704 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'mycontris',
705 "Contributions/" . $wgUser->getTitleKey(), wfMsg('mycontris') );
709 return cbt_value( $s, 'user' );
712 function logout( $itemTemplate ) {
713 if ( $this->isLoggedIn() ) {
714 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'logout',
715 'Userlogout', wfMsg( 'userlogout' ),
716 $this->mTitle
->getNamespace() === NS_SPECIAL
&& $this->mTitle
->getText() === 'Preferences'
717 ?
'' : "returnto=" . $this->mTitle
->getPrefixedURL() );
721 return cbt_value( $s, 'loggedin dynamic' );
724 function anonuserpage( $itemTemplate ) {
725 if ( $this->isLoggedIn() ) {
729 $userPage = $this->getUserPageTitle();
730 $s = $this->makeTemplateLink( $itemTemplate, 'userpage', $userPage, $wgUser->getName() );
732 return cbt_value( $s, '!loggedin dynamic' );
735 function anontalk( $itemTemplate ) {
736 if ( $this->isLoggedIn() ) {
739 $userPage = $this->getUserPageTitle();
740 $talkPage = $userPage->getTalkPage();
741 $s = $this->makeTemplateLink( $itemTemplate, 'mytalk', $talkPage, wfMsg('anontalk') );
743 return cbt_value( $s, '!loggedin dynamic' );
746 function anonlogin( $itemTemplate ) {
747 if ( $this->isLoggedIn() ) {
750 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'anonlogin', 'Userlogin',
751 wfMsg( 'userlogin' ), 'returnto=' . urlencode( $this->getThisPDBK() ) );
753 return cbt_value( $s, '!loggedin dynamic' );
756 function login( $itemTemplate ) {
757 if ( $this->isLoggedIn() ) {
760 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'login', 'Userlogin',
761 wfMsg( 'userlogin' ), 'returnto=' . urlencode( $this->getThisPDBK() ) );
763 return cbt_value( $s, '!loggedin dynamic' );
766 function logopath() { return $GLOBALS['wgLogo']; }
767 function mainpage() { return self
::makeMainPageUrl(); }
769 function sidebar( $startSection, $endSection, $innerTpl ) {
771 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
772 $firstSection = true;
773 foreach ($lines as $line) {
774 if (strpos($line, '*') !== 0)
776 if (strpos($line, '**') !== 0) {
777 $bar = trim($line, '* ');
778 $name = wfMsg( $bar );
779 if (wfEmptyMsg($bar, $name)) {
782 if ( $firstSection ) {
783 $firstSection = false;
787 $s .= strtr( $startSection,
789 '$bar' => htmlspecialchars( $bar ),
793 if (strpos($line, '|') !== false) { // sanity check
794 $line = explode( '|' , trim($line, '* '), 2 );
795 $link = wfMsgForContent( $line[0] );
798 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
800 if (wfEmptyMsg($line[0], $link))
802 $href = self
::makeInternalOrExternalUrl( $link );
804 $s .= strtr( $innerTpl,
806 '$text' => htmlspecialchars( $text ),
807 '$href' => htmlspecialchars( $href ),
808 '$id' => htmlspecialchars( 'n-' . strtr($line[1], ' ', '-') ),
814 if ( !$firstSection ) {
818 // Depends on user language only
819 return cbt_value( $s, 'lang' );
822 function searchaction() {
824 return $this->getSearchLink();
829 return cbt_value( trim( $this->getSearch() ), 'special dynamic' );
832 function notspecialpage() {
833 return cbt_value( $this->mTitle
->getNamespace() != NS_SPECIAL
, 'special' );
836 function nav_whatlinkshere() {
837 return cbt_value( $this->makeSpecialParamUrl('Whatlinkshere' ), array(), true );
840 function article_exists() {
841 return cbt_value( (string)($this->mTitle
->getArticleId() !== 0), 'title' );
844 function nav_recentchangeslinked() {
845 return cbt_value( $this->makeSpecialParamUrl('Recentchangeslinked' ), array(), true );
848 function feeds( $itemTemplate = '' ) {
849 if ( !$this->mOut
->isSyndicated() ) {
851 } elseif ( $itemTemplate == '' ) {
852 // boolean only required
856 global $wgFeedClasses, $wgRequest;
857 foreach( $wgFeedClasses as $format => $class ) {
858 $feeds .= strtr( $itemTemplate,
860 '$key' => htmlspecialchars( $format ),
862 '$href' => $wgRequest->appendQuery( "feed=$format" )
866 return cbt_value( $feeds, 'special dynamic' );
869 function is_userpage() {
870 list( $id, $ip ) = $this->getUserPageIdIp();
871 return cbt_value( (string)($id ||
$ip), 'title' );
874 function is_ns_mediawiki() {
875 return cbt_value( (string)$this->mTitle
->getNamespace() == NS_MEDIAWIKI
, 'title' );
878 function is_loggedin() {
880 return cbt_value( (string)($wgUser->isLoggedIn()), 'loggedin' );
883 function nav_contributions() {
884 $url = $this->makeSpecialParamUrl( 'Contributions', '', '{title_userurl}' );
885 return cbt_value( $url, array(), true );
888 function is_allowed( $right ) {
890 return cbt_value( (string)$wgUser->isAllowed( $right ), 'user' );
893 function nav_blockip() {
894 $url = $this->makeSpecialParamUrl( 'Blockip', '', '{title_userurl}' );
895 return cbt_value( $url, array(), true );
898 function nav_emailuser() {
899 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
900 if ( !$wgEnableEmail ||
!$wgEnableUserEmail ) return '';
902 $url = $this->makeSpecialParamUrl( 'Emailuser', '', '{title_userurl}' );
903 return cbt_value( $url, array(), true );
906 function nav_upload() {
907 global $wgEnableUploads, $wgUploadNavigationUrl;
908 if ( !$wgEnableUploads ) {
910 } elseif ( $wgUploadNavigationUrl ) {
911 return $wgUploadNavigationUrl;
913 return self
::makeSpecialUrl('Upload');
917 function nav_specialpages() {
918 return self
::makeSpecialUrl('Specialpages');
921 function nav_print() {
922 global $wgRequest, $wgArticle;
923 $action = $this->getAction();
925 if( $this->mTitle
->getNamespace() !== NS_SPECIAL
926 && ($action == '' ||
$action == 'view' ||
$action == 'purge' ) )
928 $revid = $wgArticle->getLatest();
930 $url = $wgRequest->appendQuery( 'printable=yes' );
933 return cbt_value( $url, array( 'nonview dynamic', 'title' ) );
936 function nav_permalink() {
937 $url = (string)$this->getPermalink();
938 return cbt_value( $url, 'dynamic' );
941 function nav_trackbacklink() {
942 global $wgUseTrackbacks;
943 if ( !$wgUseTrackbacks ) return '';
945 return cbt_value( $this->mTitle
->trackbackURL(), 'title' );
948 function is_permalink() {
949 return cbt_value( (string)($this->getPermalink() === false), 'nonview dynamic' );
952 function toolboxend() {
953 // This is where the MonoBookTemplateToolboxEnd hook went in the old skin
957 function language_urls( $outer, $inner ) {
958 global $wgHideInterlanguageLinks, $wgOut, $wgContLang;
959 if ( $wgHideInterlanguageLinks ) return '';
961 $links = $wgOut->getLanguageLinks();
963 if ( count( $links ) ) {
964 foreach( $links as $l ) {
965 $tmp = explode( ':', $l, 2 );
966 $nt = Title
::newFromText( $l );
969 '$class' => htmlspecialchars( 'interwiki-' . $tmp[0] ),
970 '$href' => htmlspecialchars( $nt->getFullURL() ),
971 '$text' => ($wgContLang->getLanguageName( $nt->getInterwiki() ) != ''?
972 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
976 $s = str_replace( '$body', $s, $outer );
978 return cbt_value( $s, 'dynamic' );
981 function poweredbyico() { return $this->getPoweredBy(); }
982 function copyrightico() { return $this->getCopyrightIcon(); }
985 global $wgMaxCredits;
986 if ( $wgMaxCredits ) return '';
988 if ( !isset( $this->mLastmod
) ) {
989 if ( $this->isCurrentArticleView() ) {
990 $this->mLastmod
= $this->lastModified();
992 $this->mLastmod
= '';
995 return cbt_value( $this->mLastmod
, 'dynamic' );
998 function viewcount() {
999 global $wgDisableCounters;
1000 if ( $wgDisableCounters ) return '';
1002 global $wgLang, $wgArticle;
1003 if ( is_object( $wgArticle ) ) {
1004 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
1006 $viewcount = wfMsg( "viewcount", $viewcount );
1013 return cbt_value( $viewcount, 'dynamic' );
1016 function numberofwatchingusers() {
1017 global $wgPageShowWatchingUsers;
1018 if ( !$wgPageShowWatchingUsers ) return '';
1020 $dbr = wfGetDB( DB_SLAVE
);
1021 extract( $dbr->tableNames( 'watchlist' ) );
1022 $sql = "SELECT COUNT(*) AS n FROM $watchlist
1023 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBkey()) .
1024 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
1025 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
1026 $row = $dbr->fetchObject( $res );
1029 $s = wfMsg('number_of_watching_users_pageview', $num);
1033 return cbt_value( $s, 'dynamic' );
1036 function credits() {
1037 global $wgMaxCredits;
1038 if ( !$wgMaxCredits ) return '';
1040 if ( $this->isCurrentArticleView() ) {
1041 require_once("Credits.php");
1042 global $wgArticle, $wgShowCreditsIfMax;
1043 $credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
1047 return cbt_value( $credits, 'view dynamic' );
1050 function normalcopyright() {
1051 return $this->getCopyright( 'normal' );
1054 function historycopyright() {
1055 return $this->getCopyright( 'history' );
1058 function is_currentview() {
1060 return cbt_value( (string)$this->isCurrentArticleView(), 'view' );
1063 function usehistorycopyright() {
1065 if ( wfMsgForContent( 'history_copyright' ) == '-' ) return '';
1067 $oldid = $this->getOldId();
1068 $diff = $this->getDiff();
1069 $use = (string)(!is_null( $oldid ) && is_null( $diff ));
1070 return cbt_value( $use, 'nonview dynamic' );
1073 function privacy() {
1074 return cbt_value( $this->privacyLink(), 'lang' );
1077 return cbt_value( $this->aboutLink(), 'lang' );
1079 function disclaimer() {
1080 return cbt_value( $this->disclaimerLink(), 'lang' );
1082 function tagline() {
1083 # A reference to this tag existed in the old MonoBook.php, but the
1084 # template data wasn't set anywhere
1087 function reporttime() {
1088 return cbt_value( $this->mOut
->reportTime(), 'dynamic' );
1091 function msg( $name ) {
1092 return cbt_value( wfMsg( $name ), 'lang' );
1095 function fallbackmsg( $name, $fallback ) {
1096 $text = wfMsg( $name );
1097 if ( wfEmptyMsg( $name, $text ) ) {
1100 return cbt_value( $text, 'lang' );
1103 /******************************************************
1104 * Utility functions *
1105 ******************************************************/
1107 /** Return true if this request is a valid, secure CSS preview */
1108 function isCssPreview() {
1109 if ( !isset( $this->mCssPreview
) ) {
1110 global $wgRequest, $wgAllowUserCss, $wgUser;
1111 $this->mCssPreview
=
1113 $wgUser->isLoggedIn() &&
1114 $this->mTitle
->isCssSubpage() &&
1115 $this->userCanPreview( $this->getAction() );
1117 return $this->mCssPreview
;
1120 /** Return true if this request is a valid, secure JS preview */
1121 function isJsPreview() {
1122 if ( !isset( $this->mJsPreview
) ) {
1123 global $wgRequest, $wgAllowUserJs, $wgUser;
1126 $wgUser->isLoggedIn() &&
1127 $this->mTitle
->isJsSubpage() &&
1128 $this->userCanPreview( $this->getAction() );
1130 return $this->mJsPreview
;
1133 /** Get the title of the $wgUser's user page */
1134 function getUserPageTitle() {
1135 if ( !isset( $this->mUserPageTitle
) ) {
1137 $this->mUserPageTitle
= $wgUser->getUserPage();
1139 return $this->mUserPageTitle
;
1142 /** Get the text of the user page title */
1143 function getUserPageText() {
1144 if ( !isset( $this->mUserPageText
) ) {
1145 $userPage = $this->getUserPageTitle();
1146 $this->mUserPageText
= $userPage->getPrefixedText();
1148 return $this->mUserPageText
;
1151 /** Make an HTML element for a stylesheet link */
1152 function makeStylesheetLink( $url ) {
1153 return '<link rel="stylesheet" type="text/css" href="' . htmlspecialchars( $url ) . "\"/>";
1156 /** Make an XHTML element for inline CSS */
1157 function makeStylesheetCdata( $style ) {
1158 return "<style type=\"text/css\"> /*<![CDATA[*/ {$style} /*]]>*/ </style>";
1161 /** Get the edit URL for this page */
1162 function getEditUrl() {
1163 if ( !isset( $this->mEditUrl
) ) {
1164 $this->mEditUrl
= $this->mTitle
->getLocalUrl( $this->editUrlOptions() );
1166 return $this->mEditUrl
;
1169 /** Get the prefixed DB key for this page */
1170 function getThisPDBK() {
1171 if ( !isset( $this->mThisPDBK
) ) {
1172 $this->mThisPDBK
= $this->mTitle
->getPrefixedDbKey();
1174 return $this->mThisPDBK
;
1177 function getThisTitleUrlForm() {
1178 if ( !isset( $this->mThisTitleUrlForm
) ) {
1179 $this->mThisTitleUrlForm
= $this->mTitle
->getPrefixedURL();
1181 return $this->mThisTitleUrlForm
;
1185 * If the current page is a user page, get the user's ID and IP. Otherwise return array(0,false)
1187 function getUserPageIdIp() {
1188 if ( !isset( $this->mUserPageId
) ) {
1189 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
1190 $this->mUserPageId
= User
::idFromName($this->mTitle
->getText());
1191 $this->mUserPageIp
= User
::isIP($this->mTitle
->getText());
1193 $this->mUserPageId
= 0;
1194 $this->mUserPageIp
= false;
1197 return array( $this->mUserPageId
, $this->mUserPageIp
);
1201 * Returns a permalink URL, or false if the current page is already a
1202 * permalink, or blank if a permalink shouldn't be displayed
1204 function getPermalink() {
1205 if ( !isset( $this->mPermalink
) ) {
1206 global $wgRequest, $wgArticle;
1207 $action = $this->getAction();
1208 $oldid = $this->getOldId();
1210 if( $this->mTitle
->getNamespace() !== NS_SPECIAL
1211 && $this->mTitle
->getArticleId() != 0
1212 && ($action == '' ||
$action == 'view' ||
$action == 'purge' ) )
1215 $revid = $wgArticle->getLatest();
1216 $url = $this->mTitle
->getLocalURL( "oldid=$revid" );
1228 * Returns true if the current page is an article, not a special page,
1229 * and we are viewing a revision, not a diff
1231 function isArticleView() {
1232 global $wgOut, $wgArticle, $wgRequest;
1233 if ( !isset( $this->mIsArticleView
) ) {
1234 $oldid = $this->getOldId();
1235 $diff = $this->getDiff();
1236 $this->mIsArticleView
= $wgOut->isArticle() and
1237 (!is_null( $oldid ) or is_null( $diff )) and 0 != $wgArticle->getID();
1239 return $this->mIsArticleView
;
1242 function isCurrentArticleView() {
1243 if ( !isset( $this->mIsCurrentArticleView
) ) {
1244 global $wgOut, $wgArticle, $wgRequest;
1245 $oldid = $this->getOldId();
1246 $this->mIsCurrentArticleView
= $wgOut->isArticle() && is_null( $oldid ) && 0 != $wgArticle->getID();
1248 return $this->mIsCurrentArticleView
;
1253 * Return true if the current page is editable; if edit section on right
1254 * click should be enabled.
1256 function isEditable() {
1258 $action = $this->getAction();
1259 return ($this->mTitle
->getNamespace() != NS_SPECIAL
and !($action == 'edit' or $action == 'submit'));
1262 /** Return true if the user is logged in */
1263 function isLoggedIn() {
1265 return $wgUser->isLoggedIn();
1268 /** Get the local URL of the current page */
1269 function getPageUrl() {
1270 if ( !isset( $this->mPageUrl
) ) {
1271 $this->mPageUrl
= $this->mTitle
->getLocalURL();
1273 return $this->mPageUrl
;
1276 /** Make a link to a title using a template */
1277 function makeTemplateLink( $template, $key, $title, $text ) {
1278 $url = $title->getLocalUrl();
1279 return strtr( $template,
1282 '$classactive' => ($url == $this->getPageUrl()) ?
'class="active"' : '',
1283 '$class' => $title->getArticleID() == 0 ?
'class="new"' : '',
1284 '$href' => htmlspecialchars( $url ),
1289 /** Make a link to a URL using a template */
1290 function makeTemplateLinkUrl( $template, $key, $url, $text ) {
1291 return strtr( $template,
1294 '$classactive' => ($url == $this->getPageUrl()) ?
'class="active"' : '',
1296 '$href' => htmlspecialchars( $url ),
1301 /** Make a link to a special page using a template */
1302 function makeSpecialTemplateLink( $template, $key, $specialName, $text, $query = '' ) {
1303 $url = self
::makeSpecialUrl( $specialName, $query );
1304 // Ignore the query when comparing
1305 $active = ($this->mTitle
->getNamespace() == NS_SPECIAL
&& $this->mTitle
->getDBkey() == $specialName);
1306 return strtr( $template,
1309 '$classactive' => $active ?
'class="active"' : '',
1311 '$href' => htmlspecialchars( $url ),
1316 function loadRequestValues() {
1318 $this->mAction
= $wgRequest->getText( 'action' );
1319 $this->mOldId
= $wgRequest->getVal( 'oldid' );
1320 $this->mDiff
= $wgRequest->getVal( 'diff' );
1321 $this->mSection
= $wgRequest->getVal( 'section' );
1322 $this->mSearch
= $wgRequest->getVal( 'search' );
1323 $this->mRequestValuesLoaded
= true;
1328 /** Get the action parameter of the request */
1329 function getAction() {
1330 if ( !isset( $this->mRequestValuesLoaded
) ) {
1331 $this->loadRequestValues();
1333 return $this->mAction
;
1336 /** Get the oldid parameter */
1337 function getOldId() {
1338 if ( !isset( $this->mRequestValuesLoaded
) ) {
1339 $this->loadRequestValues();
1341 return $this->mOldId
;
1344 /** Get the diff parameter */
1345 function getDiff() {
1346 if ( !isset( $this->mRequestValuesLoaded
) ) {
1347 $this->loadRequestValues();
1349 return $this->mDiff
;
1352 function getSection() {
1353 if ( !isset( $this->mRequestValuesLoaded
) ) {
1354 $this->loadRequestValues();
1356 return $this->mSection
;
1359 function getSearch() {
1360 if ( !isset( $this->mRequestValuesLoaded
) ) {
1361 $this->loadRequestValues();
1363 return $this->mSearch
;
1366 /** Make a special page URL of the form [[Special:Somepage/{title_urlform}]] */
1367 function makeSpecialParamUrl( $name, $query = '', $param = '{title_urlform}' ) {
1368 // Abuse makeTitle's lax validity checking to slip a control character into the URL
1369 $title = Title
::makeTitle( NS_SPECIAL
, "$name/\x1a" );
1370 $url = cbt_escape( $title->getLocalURL( $query ) );
1371 // Now replace it with the parameter
1372 return str_replace( '%1A', $param, $url );
1375 function getSubjectPage() {
1376 if ( !isset( $this->mSubjectPage
) ) {
1377 $this->mSubjectPage
= $this->mTitle
->getSubjectPage();
1379 return $this->mSubjectPage
;
1382 function getTalkPage() {
1383 if ( !isset( $this->mTalkPage
) ) {
1384 $this->mTalkPage
= $this->mTitle
->getTalkPage();
1386 return $this->mTalkPage
;