9f8098c9175ca3b118a8bb32aca27a45770e05df
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();
430 if( !$usertalktitle->equals( $this->mTitle
) ) {
431 $newmessageslink = $this->link(
433 wfMsgHtml( 'newmessageslink' ),
435 array( 'redirect' => 'no' ),
436 array( 'known', 'noclasses' )
439 $newmessagesdifflink = $this->link(
441 wfMsgHtml( 'newmessagesdifflink' ),
443 array( 'diff' => 'cur' ),
444 array( 'known', 'noclasses' )
448 'youhavenewmessages',
454 $this->mOut
->setSquidMaxage(0);
456 } else if (count($newtalks)) {
457 $sep = str_replace("_", " ", wfMsgHtml("newtalkseparator"));
459 foreach ($newtalks as $newtalk) {
460 $msgs[] = wfElement("a",
461 array('href' => $newtalk["link"]), $newtalk["wiki"]);
463 $parts = implode($sep, $msgs);
464 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
465 $this->mOut
->setSquidMaxage(0);
469 return cbt_value( $ntl, 'dynamic' );
472 function showjumplinks() {
474 return cbt_value( $wgUser->getOption( 'showjumplinks' ) ?
'true' : '', 'user' );
477 function bodytext() {
478 return cbt_value( $this->mOut
->getHTML(), 'dynamic' );
481 function catlinks() {
482 if ( !isset( $this->mCatlinks
) ) {
483 $this->mCatlinks
= $this->getCategories();
485 return cbt_value( $this->mCatlinks
, 'dynamic' );
488 function extratabs( $itemTemplate ) {
489 global $wgContLang, $wgDisableLangConversion;
491 $etpl = cbt_escape( $itemTemplate );
493 /* show links to different language variants */
494 $variants = $wgContLang->getVariants();
496 if ( !$wgDisableLangConversion && count( $wgContLang->getVariants() ) > 1 ) {
498 foreach ( $variants as $code ) {
499 $name = $wgContLang->getVariantname( $code );
500 if ( $name == 'disable' ) {
503 $code = cbt_escape( $code );
504 $name = cbt_escape( $name );
505 $s .= "{ca_variant {{$code}} {{$name}} {{$vcount}} {{$etpl}}}\n";
509 return cbt_value( $s, array(), true );
512 function is_special() { return cbt_value( $this->mTitle
->getNamespace() == NS_SPECIAL
, 'title' ); }
513 function can_edit() { return cbt_value( (string)($this->mTitle
->userCan( 'edit' )), 'dynamic' ); }
514 function can_move() { return cbt_value( (string)($this->mTitle
->userCan( 'move' )), 'dynamic' ); }
515 function is_talk() { return cbt_value( (string)($this->mTitle
->isTalkPage()), 'title' ); }
516 function is_protected() { return cbt_value( (string)$this->mTitle
->isProtected(), 'dynamic' ); }
517 function nskey() { return cbt_value( $this->mTitle
->getNamespaceKey(), 'title' ); }
519 function request_url() {
521 return cbt_value( $wgRequest->getRequestURL(), 'dynamic' );
524 function subject_url() {
525 $title = $this->getSubjectPage();
526 if ( $title->exists() ) {
527 $url = $title->getLocalUrl();
529 $url = $title->getLocalUrl( 'action=edit' );
531 return cbt_value( $url, 'title' );
534 function talk_url() {
535 $title = $this->getTalkPage();
536 if ( $title->exists() ) {
537 $url = $title->getLocalUrl();
539 $url = $title->getLocalUrl( 'action=edit' );
541 return cbt_value( $url, 'title' );
544 function edit_url() {
545 return cbt_value( $this->getEditUrl(), array( 'title', 'nonview dynamic' ) );
548 function move_url() {
549 return cbt_value( $this->makeSpecialParamUrl( 'Movepage' ), array(), true );
552 function localurl( $query ) {
553 return cbt_value( $this->mTitle
->getLocalURL( $query ), 'title' );
556 function selecttab( $tab, $extraclass = '' ) {
557 if ( !isset( $this->mSelectedTab
) ) {
558 $prevent_active_tabs = false ;
559 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$preventActiveTabs ) );
564 'history' => 'history',
565 'protect' => 'protect',
566 'unprotect' => 'protect',
567 'delete' => 'delete',
569 'unwatch' => 'watch',
571 if ( $preventActiveTabs ) {
572 $this->mSelectedTab
= false;
574 $action = $this->getAction();
575 $section = $this->getSection();
577 if ( isset( $actionTabs[$action] ) ) {
578 $this->mSelectedTab
= $actionTabs[$action];
580 if ( $this->mSelectedTab
== 'edit' && $section == 'new' ) {
581 $this->mSelectedTab
= 'addsection';
583 } elseif ( $this->mTitle
->isTalkPage() ) {
584 $this->mSelectedTab
= 'talk';
586 $this->mSelectedTab
= 'subject';
591 if ( $this->mSelectedTab
== $tab ) {
592 $s = 'class="selected ' . htmlspecialchars( $extraclass ) . '"';
594 $s = 'class="' . htmlspecialchars( $extraclass ) . '"';
597 if ( $this->mSelectedTab
== $tab ) {
598 $s = 'class="selected"';
603 return cbt_value( $s, array( 'nonview dynamic', 'title' ) );
606 function subject_newclass() {
607 $title = $this->getSubjectPage();
608 $class = $title->exists() ?
'' : 'new';
609 return cbt_value( $class, 'dynamic' );
612 function talk_newclass() {
613 $title = $this->getTalkPage();
614 $class = $title->exists() ?
'' : 'new';
615 return cbt_value( $class, 'dynamic' );
618 function ca_variant( $code, $name, $index, $template ) {
620 $selected = ($code == $wgContLang->getPreferredVariant());
621 $action = $this->getAction();
624 $actstr = 'action=' . $action . '&';
625 $s = strtr( $template, array(
626 '$id' => htmlspecialchars( 'varlang-' . $index ),
627 '$class' => $selected ?
'class="selected"' : '',
629 '$href' => htmlspecialchars( $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code ) )
631 return cbt_value( $s, 'dynamic' );
634 function is_watching() {
635 return cbt_value( (string)$this->mTitle
->userIsWatching(), array( 'dynamic' ) );
639 function personal_urls( $itemTemplate ) {
640 global $wgShowIPinHeader, $wgContLang;
642 # Split this function up into many small functions, to obtain the
643 # best specificity in the dependencies of each one. The template below
644 # has no dependencies, so its generation, and any static subfunctions,
645 # can be optimised away.
646 $etpl = cbt_escape( $itemTemplate );
650 {preferences {{$etpl}}}
651 {watchlist {{$etpl}}}
652 {mycontris {{$etpl}}}
656 if ( $wgShowIPinHeader ) {
658 {anonuserpage {{$etpl}}}
660 {anonlogin {{$etpl}}}
663 $s .= "{login {{$etpl}}}\n";
666 return cbt_value( $s, array(), true /*this is a template*/ );
669 function userpage( $itemTemplate ) {
671 if ( $this->isLoggedIn() ) {
672 $userPage = $this->getUserPageTitle();
673 $s = $this->makeTemplateLink( $itemTemplate, 'userpage', $userPage, $wgUser->getName() );
677 return cbt_value( $s, 'user' );
680 function mytalk( $itemTemplate ) {
682 if ( $this->isLoggedIn() ) {
683 $userPage = $this->getUserPageTitle();
684 $talkPage = $userPage->getTalkPage();
685 $s = $this->makeTemplateLink( $itemTemplate, 'mytalk', $talkPage, wfMsg('mytalk') );
689 return cbt_value( $s, 'user' );
692 function preferences( $itemTemplate ) {
693 if ( $this->isLoggedIn() ) {
694 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'preferences',
695 'Preferences', wfMsg( 'preferences' ) );
699 return cbt_value( $s, array( 'loggedin', 'lang' ) );
702 function watchlist( $itemTemplate ) {
703 if ( $this->isLoggedIn() ) {
704 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'watchlist',
705 'Watchlist', wfMsg( 'watchlist' ) );
709 return cbt_value( $s, array( 'loggedin', 'lang' ) );
712 function mycontris( $itemTemplate ) {
713 if ( $this->isLoggedIn() ) {
715 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'mycontris',
716 "Contributions/" . $wgUser->getTitleKey(), wfMsg('mycontris') );
720 return cbt_value( $s, 'user' );
723 function logout( $itemTemplate ) {
724 if ( $this->isLoggedIn() ) {
725 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'logout',
726 'Userlogout', wfMsg( 'userlogout' ),
727 $this->mTitle
->getNamespace() === NS_SPECIAL
&& $this->mTitle
->getText() === 'Preferences'
728 ?
'' : "returnto=" . $this->mTitle
->getPrefixedURL() );
732 return cbt_value( $s, 'loggedin dynamic' );
735 function anonuserpage( $itemTemplate ) {
736 if ( $this->isLoggedIn() ) {
740 $userPage = $this->getUserPageTitle();
741 $s = $this->makeTemplateLink( $itemTemplate, 'userpage', $userPage, $wgUser->getName() );
743 return cbt_value( $s, '!loggedin dynamic' );
746 function anontalk( $itemTemplate ) {
747 if ( $this->isLoggedIn() ) {
750 $userPage = $this->getUserPageTitle();
751 $talkPage = $userPage->getTalkPage();
752 $s = $this->makeTemplateLink( $itemTemplate, 'mytalk', $talkPage, wfMsg('anontalk') );
754 return cbt_value( $s, '!loggedin dynamic' );
757 function anonlogin( $itemTemplate ) {
758 if ( $this->isLoggedIn() ) {
761 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'anonlogin', 'Userlogin',
762 wfMsg( 'userlogin' ), 'returnto=' . urlencode( $this->getThisPDBK() ) );
764 return cbt_value( $s, '!loggedin dynamic' );
767 function login( $itemTemplate ) {
768 if ( $this->isLoggedIn() ) {
771 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'login', 'Userlogin',
772 wfMsg( 'userlogin' ), 'returnto=' . urlencode( $this->getThisPDBK() ) );
774 return cbt_value( $s, '!loggedin dynamic' );
777 function logopath() { return $GLOBALS['wgLogo']; }
778 function mainpage() { return self
::makeMainPageUrl(); }
780 function sidebar( $startSection, $endSection, $innerTpl ) {
782 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
783 $firstSection = true;
784 foreach ($lines as $line) {
785 if (strpos($line, '*') !== 0)
787 if (strpos($line, '**') !== 0) {
788 $bar = trim($line, '* ');
789 $name = wfMsg( $bar );
790 if (wfEmptyMsg($bar, $name)) {
793 if ( $firstSection ) {
794 $firstSection = false;
798 $s .= strtr( $startSection,
800 '$bar' => htmlspecialchars( $bar ),
804 if (strpos($line, '|') !== false) { // sanity check
805 $line = explode( '|' , trim($line, '* '), 2 );
806 $link = wfMsgForContent( $line[0] );
809 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
811 if (wfEmptyMsg($line[0], $link))
813 $href = self
::makeInternalOrExternalUrl( $link );
815 $s .= strtr( $innerTpl,
817 '$text' => htmlspecialchars( $text ),
818 '$href' => htmlspecialchars( $href ),
819 '$id' => htmlspecialchars( 'n-' . strtr($line[1], ' ', '-') ),
825 if ( !$firstSection ) {
829 // Depends on user language only
830 return cbt_value( $s, 'lang' );
833 function searchaction() {
835 return $this->getSearchLink();
840 return cbt_value( trim( $this->getSearch() ), 'special dynamic' );
843 function notspecialpage() {
844 return cbt_value( $this->mTitle
->getNamespace() != NS_SPECIAL
, 'special' );
847 function nav_whatlinkshere() {
848 return cbt_value( $this->makeSpecialParamUrl('Whatlinkshere' ), array(), true );
851 function article_exists() {
852 return cbt_value( (string)($this->mTitle
->getArticleId() !== 0), 'title' );
855 function nav_recentchangeslinked() {
856 return cbt_value( $this->makeSpecialParamUrl('Recentchangeslinked' ), array(), true );
859 function feeds( $itemTemplate = '' ) {
860 if ( !$this->mOut
->isSyndicated() ) {
862 } elseif ( $itemTemplate == '' ) {
863 // boolean only required
867 global $wgFeedClasses, $wgRequest;
868 foreach( $wgFeedClasses as $format => $class ) {
869 $feeds .= strtr( $itemTemplate,
871 '$key' => htmlspecialchars( $format ),
873 '$href' => $wgRequest->appendQuery( "feed=$format" )
877 return cbt_value( $feeds, 'special dynamic' );
880 function is_userpage() {
881 list( $id, $ip ) = $this->getUserPageIdIp();
882 return cbt_value( (string)($id ||
$ip), 'title' );
885 function is_ns_mediawiki() {
886 return cbt_value( (string)$this->mTitle
->getNamespace() == NS_MEDIAWIKI
, 'title' );
889 function is_loggedin() {
891 return cbt_value( (string)($wgUser->isLoggedIn()), 'loggedin' );
894 function nav_contributions() {
895 $url = $this->makeSpecialParamUrl( 'Contributions', '', '{title_userurl}' );
896 return cbt_value( $url, array(), true );
899 function is_allowed( $right ) {
901 return cbt_value( (string)$wgUser->isAllowed( $right ), 'user' );
904 function nav_blockip() {
905 $url = $this->makeSpecialParamUrl( 'Blockip', '', '{title_userurl}' );
906 return cbt_value( $url, array(), true );
909 function nav_emailuser() {
910 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
911 if ( !$wgEnableEmail ||
!$wgEnableUserEmail ) return '';
913 $url = $this->makeSpecialParamUrl( 'Emailuser', '', '{title_userurl}' );
914 return cbt_value( $url, array(), true );
917 function nav_upload() {
918 global $wgEnableUploads, $wgUploadNavigationUrl;
919 if ( !$wgEnableUploads ) {
921 } elseif ( $wgUploadNavigationUrl ) {
922 return $wgUploadNavigationUrl;
924 return self
::makeSpecialUrl('Upload');
928 function nav_specialpages() {
929 return self
::makeSpecialUrl('Specialpages');
932 function nav_print() {
933 global $wgRequest, $wgArticle;
934 $action = $this->getAction();
936 if( $this->mTitle
->getNamespace() !== NS_SPECIAL
937 && ($action == '' ||
$action == 'view' ||
$action == 'purge' ) )
939 $revid = $wgArticle->getLatest();
941 $url = $wgRequest->appendQuery( 'printable=yes' );
944 return cbt_value( $url, array( 'nonview dynamic', 'title' ) );
947 function nav_permalink() {
948 $url = (string)$this->getPermalink();
949 return cbt_value( $url, 'dynamic' );
952 function nav_trackbacklink() {
953 global $wgUseTrackbacks;
954 if ( !$wgUseTrackbacks ) return '';
956 return cbt_value( $this->mTitle
->trackbackURL(), 'title' );
959 function is_permalink() {
960 return cbt_value( (string)($this->getPermalink() === false), 'nonview dynamic' );
963 function toolboxend() {
964 // This is where the MonoBookTemplateToolboxEnd hook went in the old skin
968 function language_urls( $outer, $inner ) {
969 global $wgHideInterlanguageLinks, $wgOut, $wgContLang;
970 if ( $wgHideInterlanguageLinks ) return '';
972 $links = $wgOut->getLanguageLinks();
974 if ( count( $links ) ) {
975 foreach( $links as $l ) {
976 $tmp = explode( ':', $l, 2 );
977 $nt = Title
::newFromText( $l );
980 '$class' => htmlspecialchars( 'interwiki-' . $tmp[0] ),
981 '$href' => htmlspecialchars( $nt->getFullURL() ),
982 '$text' => ($wgContLang->getLanguageName( $nt->getInterwiki() ) != ''?
983 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
987 $s = str_replace( '$body', $s, $outer );
989 return cbt_value( $s, 'dynamic' );
992 function poweredbyico() { return $this->getPoweredBy(); }
993 function copyrightico() { return $this->getCopyrightIcon(); }
996 global $wgMaxCredits;
997 if ( $wgMaxCredits ) return '';
999 if ( !isset( $this->mLastmod
) ) {
1000 if ( $this->isCurrentArticleView() ) {
1001 $this->mLastmod
= $this->lastModified();
1003 $this->mLastmod
= '';
1006 return cbt_value( $this->mLastmod
, 'dynamic' );
1009 function viewcount() {
1010 global $wgDisableCounters;
1011 if ( $wgDisableCounters ) return '';
1013 global $wgLang, $wgArticle;
1014 if ( is_object( $wgArticle ) ) {
1015 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
1017 $viewcount = wfMsg( "viewcount", $viewcount );
1024 return cbt_value( $viewcount, 'dynamic' );
1027 function numberofwatchingusers() {
1028 global $wgPageShowWatchingUsers;
1029 if ( !$wgPageShowWatchingUsers ) return '';
1031 $dbr = wfGetDB( DB_SLAVE
);
1032 extract( $dbr->tableNames( 'watchlist' ) );
1033 $sql = "SELECT COUNT(*) AS n FROM $watchlist
1034 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBkey()) .
1035 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
1036 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
1037 $row = $dbr->fetchObject( $res );
1040 $s = wfMsg('number_of_watching_users_pageview', $num);
1044 return cbt_value( $s, 'dynamic' );
1047 function credits() {
1048 global $wgMaxCredits;
1049 if ( !$wgMaxCredits ) return '';
1051 if ( $this->isCurrentArticleView() ) {
1052 require_once("Credits.php");
1053 global $wgArticle, $wgShowCreditsIfMax;
1054 $credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
1058 return cbt_value( $credits, 'view dynamic' );
1061 function normalcopyright() {
1062 return $this->getCopyright( 'normal' );
1065 function historycopyright() {
1066 return $this->getCopyright( 'history' );
1069 function is_currentview() {
1071 return cbt_value( (string)$this->isCurrentArticleView(), 'view' );
1074 function usehistorycopyright() {
1076 if ( wfMsgForContent( 'history_copyright' ) == '-' ) return '';
1078 $oldid = $this->getOldId();
1079 $diff = $this->getDiff();
1080 $use = (string)(!is_null( $oldid ) && is_null( $diff ));
1081 return cbt_value( $use, 'nonview dynamic' );
1084 function privacy() {
1085 return cbt_value( $this->privacyLink(), 'lang' );
1088 return cbt_value( $this->aboutLink(), 'lang' );
1090 function disclaimer() {
1091 return cbt_value( $this->disclaimerLink(), 'lang' );
1093 function tagline() {
1094 # A reference to this tag existed in the old MonoBook.php, but the
1095 # template data wasn't set anywhere
1098 function reporttime() {
1099 return cbt_value( $this->mOut
->reportTime(), 'dynamic' );
1102 function msg( $name ) {
1103 return cbt_value( wfMsg( $name ), 'lang' );
1106 function fallbackmsg( $name, $fallback ) {
1107 $text = wfMsg( $name );
1108 if ( wfEmptyMsg( $name, $text ) ) {
1111 return cbt_value( $text, 'lang' );
1114 /******************************************************
1115 * Utility functions *
1116 ******************************************************/
1118 /** Return true if this request is a valid, secure CSS preview */
1119 function isCssPreview() {
1120 if ( !isset( $this->mCssPreview
) ) {
1121 global $wgRequest, $wgAllowUserCss, $wgUser;
1122 $this->mCssPreview
=
1124 $wgUser->isLoggedIn() &&
1125 $this->mTitle
->isCssSubpage() &&
1126 $this->userCanPreview( $this->getAction() );
1128 return $this->mCssPreview
;
1131 /** Return true if this request is a valid, secure JS preview */
1132 function isJsPreview() {
1133 if ( !isset( $this->mJsPreview
) ) {
1134 global $wgRequest, $wgAllowUserJs, $wgUser;
1137 $wgUser->isLoggedIn() &&
1138 $this->mTitle
->isJsSubpage() &&
1139 $this->userCanPreview( $this->getAction() );
1141 return $this->mJsPreview
;
1144 /** Get the title of the $wgUser's user page */
1145 function getUserPageTitle() {
1146 if ( !isset( $this->mUserPageTitle
) ) {
1148 $this->mUserPageTitle
= $wgUser->getUserPage();
1150 return $this->mUserPageTitle
;
1153 /** Get the text of the user page title */
1154 function getUserPageText() {
1155 if ( !isset( $this->mUserPageText
) ) {
1156 $userPage = $this->getUserPageTitle();
1157 $this->mUserPageText
= $userPage->getPrefixedText();
1159 return $this->mUserPageText
;
1162 /** Make an HTML element for a stylesheet link */
1163 function makeStylesheetLink( $url ) {
1164 return '<link rel="stylesheet" type="text/css" href="' . htmlspecialchars( $url ) . "\"/>";
1167 /** Make an XHTML element for inline CSS */
1168 function makeStylesheetCdata( $style ) {
1169 return "<style type=\"text/css\"> /*<![CDATA[*/ {$style} /*]]>*/ </style>";
1172 /** Get the edit URL for this page */
1173 function getEditUrl() {
1174 if ( !isset( $this->mEditUrl
) ) {
1175 $this->mEditUrl
= $this->mTitle
->getLocalUrl( $this->editUrlOptions() );
1177 return $this->mEditUrl
;
1180 /** Get the prefixed DB key for this page */
1181 function getThisPDBK() {
1182 if ( !isset( $this->mThisPDBK
) ) {
1183 $this->mThisPDBK
= $this->mTitle
->getPrefixedDbKey();
1185 return $this->mThisPDBK
;
1188 function getThisTitleUrlForm() {
1189 if ( !isset( $this->mThisTitleUrlForm
) ) {
1190 $this->mThisTitleUrlForm
= $this->mTitle
->getPrefixedURL();
1192 return $this->mThisTitleUrlForm
;
1196 * If the current page is a user page, get the user's ID and IP. Otherwise return array(0,false)
1198 function getUserPageIdIp() {
1199 if ( !isset( $this->mUserPageId
) ) {
1200 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
1201 $this->mUserPageId
= User
::idFromName($this->mTitle
->getText());
1202 $this->mUserPageIp
= User
::isIP($this->mTitle
->getText());
1204 $this->mUserPageId
= 0;
1205 $this->mUserPageIp
= false;
1208 return array( $this->mUserPageId
, $this->mUserPageIp
);
1212 * Returns a permalink URL, or false if the current page is already a
1213 * permalink, or blank if a permalink shouldn't be displayed
1215 function getPermalink() {
1216 if ( !isset( $this->mPermalink
) ) {
1217 global $wgRequest, $wgArticle;
1218 $action = $this->getAction();
1219 $oldid = $this->getOldId();
1221 if( $this->mTitle
->getNamespace() !== NS_SPECIAL
1222 && $this->mTitle
->getArticleId() != 0
1223 && ($action == '' ||
$action == 'view' ||
$action == 'purge' ) )
1226 $revid = $wgArticle->getLatest();
1227 $url = $this->mTitle
->getLocalURL( "oldid=$revid" );
1239 * Returns true if the current page is an article, not a special page,
1240 * and we are viewing a revision, not a diff
1242 function isArticleView() {
1243 global $wgOut, $wgArticle, $wgRequest;
1244 if ( !isset( $this->mIsArticleView
) ) {
1245 $oldid = $this->getOldId();
1246 $diff = $this->getDiff();
1247 $this->mIsArticleView
= $wgOut->isArticle() and
1248 (!is_null( $oldid ) or is_null( $diff )) and 0 != $wgArticle->getID();
1250 return $this->mIsArticleView
;
1253 function isCurrentArticleView() {
1254 if ( !isset( $this->mIsCurrentArticleView
) ) {
1255 global $wgOut, $wgArticle, $wgRequest;
1256 $oldid = $this->getOldId();
1257 $this->mIsCurrentArticleView
= $wgOut->isArticle() && is_null( $oldid ) && 0 != $wgArticle->getID();
1259 return $this->mIsCurrentArticleView
;
1264 * Return true if the current page is editable; if edit section on right
1265 * click should be enabled.
1267 function isEditable() {
1269 $action = $this->getAction();
1270 return ($this->mTitle
->getNamespace() != NS_SPECIAL
and !($action == 'edit' or $action == 'submit'));
1273 /** Return true if the user is logged in */
1274 function isLoggedIn() {
1276 return $wgUser->isLoggedIn();
1279 /** Get the local URL of the current page */
1280 function getPageUrl() {
1281 if ( !isset( $this->mPageUrl
) ) {
1282 $this->mPageUrl
= $this->mTitle
->getLocalURL();
1284 return $this->mPageUrl
;
1287 /** Make a link to a title using a template */
1288 function makeTemplateLink( $template, $key, $title, $text ) {
1289 $url = $title->getLocalUrl();
1290 return strtr( $template,
1293 '$classactive' => ($url == $this->getPageUrl()) ?
'class="active"' : '',
1294 '$class' => $title->getArticleID() == 0 ?
'class="new"' : '',
1295 '$href' => htmlspecialchars( $url ),
1300 /** Make a link to a URL using a template */
1301 function makeTemplateLinkUrl( $template, $key, $url, $text ) {
1302 return strtr( $template,
1305 '$classactive' => ($url == $this->getPageUrl()) ?
'class="active"' : '',
1307 '$href' => htmlspecialchars( $url ),
1312 /** Make a link to a special page using a template */
1313 function makeSpecialTemplateLink( $template, $key, $specialName, $text, $query = '' ) {
1314 $url = self
::makeSpecialUrl( $specialName, $query );
1315 // Ignore the query when comparing
1316 $active = ($this->mTitle
->getNamespace() == NS_SPECIAL
&& $this->mTitle
->getDBkey() == $specialName);
1317 return strtr( $template,
1320 '$classactive' => $active ?
'class="active"' : '',
1322 '$href' => htmlspecialchars( $url ),
1327 function loadRequestValues() {
1329 $this->mAction
= $wgRequest->getText( 'action' );
1330 $this->mOldId
= $wgRequest->getVal( 'oldid' );
1331 $this->mDiff
= $wgRequest->getVal( 'diff' );
1332 $this->mSection
= $wgRequest->getVal( 'section' );
1333 $this->mSearch
= $wgRequest->getVal( 'search' );
1334 $this->mRequestValuesLoaded
= true;
1339 /** Get the action parameter of the request */
1340 function getAction() {
1341 if ( !isset( $this->mRequestValuesLoaded
) ) {
1342 $this->loadRequestValues();
1344 return $this->mAction
;
1347 /** Get the oldid parameter */
1348 function getOldId() {
1349 if ( !isset( $this->mRequestValuesLoaded
) ) {
1350 $this->loadRequestValues();
1352 return $this->mOldId
;
1355 /** Get the diff parameter */
1356 function getDiff() {
1357 if ( !isset( $this->mRequestValuesLoaded
) ) {
1358 $this->loadRequestValues();
1360 return $this->mDiff
;
1363 function getSection() {
1364 if ( !isset( $this->mRequestValuesLoaded
) ) {
1365 $this->loadRequestValues();
1367 return $this->mSection
;
1370 function getSearch() {
1371 if ( !isset( $this->mRequestValuesLoaded
) ) {
1372 $this->loadRequestValues();
1374 return $this->mSearch
;
1377 /** Make a special page URL of the form [[Special:Somepage/{title_urlform}]] */
1378 function makeSpecialParamUrl( $name, $query = '', $param = '{title_urlform}' ) {
1379 // Abuse makeTitle's lax validity checking to slip a control character into the URL
1380 $title = Title
::makeTitle( NS_SPECIAL
, "$name/\x1a" );
1381 $url = cbt_escape( $title->getLocalURL( $query ) );
1382 // Now replace it with the parameter
1383 return str_replace( '%1A', $param, $url );
1386 function getSubjectPage() {
1387 if ( !isset( $this->mSubjectPage
) ) {
1388 $this->mSubjectPage
= $this->mTitle
->getSubjectPage();
1390 return $this->mSubjectPage
;
1393 function getTalkPage() {
1394 if ( !isset( $this->mTalkPage
) ) {
1395 $this->mTalkPage
= $this->mTitle
->getTalkPage();
1397 return $this->mTalkPage
;