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 = $this->makeUrl('-','action=raw&smaxage=0&gen=js');
243 $url = $this->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( $this->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( $this->makeNSUrl('Common.css', $query, NS_MEDIAWIKI
) ) . "\n";
287 $sitecss .= $this->makeStylesheetLink( $this->makeNSUrl(
288 ucfirst($this->mStyleName
) . '.css', $query, NS_MEDIAWIKI
) ) . "\n";
295 global $wgUseSiteCss;
296 if ( !$wgUseSiteCss ) return '';
298 global $wgSquidMaxage, $wgUser, $wgAllowUserCss;
299 if ( $this->isCssPreview() ) {
300 $siteargs = '&smaxage=0&maxage=0';
302 $siteargs = '&maxage=' . $wgSquidMaxage;
304 if ( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
305 $siteargs .= '&ts={user_touched}';
311 $link = $this->makeStylesheetLink( $this->makeUrl('-','action=raw&gen=css' . $siteargs) ) . "\n";
313 if ( $wgAllowUserCss ) {
318 return cbt_value( $link, $deps, $isTemplate );
321 function user_touched() {
323 return cbt_value( $wgUser->mTouched
, 'dynamic' );
327 global $wgAllowUserJs, $wgJsMimeType;
328 if ( !$wgAllowUserJs ) return '';
330 if ( $this->isJsPreview() ) {
333 $url = $this->makeUrl($this->getUserPageText().'/'.$this->mStyleName
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
335 return cbt_value( $url, array( 'nonview dynamic', 'user' ) );
338 function userjsprev() {
339 global $wgAllowUserJs, $wgRequest;
340 if ( !$wgAllowUserJs ) return '';
341 if ( $this->isJsPreview() ) {
342 $js = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
346 return cbt_value( $js, array( 'nonview dynamic' ) );
349 function trackbackhtml() {
350 global $wgUseTrackbacks;
351 if ( !$wgUseTrackbacks ) return '';
353 if ( $this->mOut
->isArticleRelated() ) {
354 $tb = $this->mTitle
->trackbackRDF();
358 return cbt_value( $tb, 'dynamic' );
361 function body_ondblclick() {
363 if( $this->isEditable() && $wgUser->getOption("editondblclick") ) {
364 $js = 'document.location = "' . $this->getEditUrl() .'";';
369 if ( User
::getDefaultOption('editondblclick') ) {
370 return cbt_value( $js, 'user', 'title' );
372 // Optimise away for logged-out users
373 return cbt_value( $js, 'loggedin dynamic' );
377 function body_onload() {
379 if ( $this->isEditable() && $wgUser->getOption( 'editsectiononrightclick' ) ) {
380 $js = 'setupRightClickEdit()';
384 return cbt_value( $js, 'loggedin dynamic' );
388 return cbt_value( 'ns-' . $this->mTitle
->getNamespace(), 'title' );
391 function sitenotice() {
392 // Perhaps this could be given special dependencies using our knowledge of what
393 // wfGetSiteNotice() depends on.
394 return cbt_value( wfGetSiteNotice(), 'dynamic' );
398 return cbt_value( $this->mOut
->getPageTitle(), array( 'title', 'lang' ) );
401 function title_urlform() {
402 return cbt_value( $this->getThisTitleUrlForm(), 'title' );
405 function title_userurl() {
406 return cbt_value( urlencode( $this->mTitle
->getDBkey() ), 'title' );
409 function subtitle() {
410 $subpagestr = $this->subPageSubtitle();
411 if ( !empty( $subpagestr ) ) {
412 $s = '<span class="subpages">'.$subpagestr.'</span>'.$this->mOut
->getSubtitle();
414 $s = $this->mOut
->getSubtitle();
416 return cbt_value( $s, array( 'title', 'nonview dynamic' ) );
419 function undelete() {
420 return cbt_value( $this->getUndeleteLink(), array( 'title', 'lang' ) );
424 global $wgUser, $wgDBname;
425 $newtalks = $wgUser->getNewMessageLinks();
427 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === $wgDBname) {
428 $usertitle = $this->getUserPageTitle();
429 $usertalktitle = $usertitle->getTalkPage();
430 if( !$usertalktitle->equals( $this->mTitle
) ) {
431 $ntl = wfMsg( 'youhavenewmessages',
432 $this->makeKnownLinkObj(
434 wfMsgHtml( 'newmessageslink' ),
437 $this->makeKnownLinkObj(
439 wfMsgHtml( 'newmessagesdifflink' ),
444 $this->mOut
->setSquidMaxage(0);
446 } else if (count($newtalks)) {
447 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
449 foreach ($newtalks as $newtalk) {
450 $msgs[] = wfElement("a",
451 array('href' => $newtalk["link"]), $newtalk["wiki"]);
453 $parts = implode($sep, $msgs);
454 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
455 $this->mOut
->setSquidMaxage(0);
459 return cbt_value( $ntl, 'dynamic' );
462 function showjumplinks() {
464 return cbt_value( $wgUser->getOption( 'showjumplinks' ) ?
'true' : '', 'user' );
467 function bodytext() {
468 return cbt_value( $this->mOut
->getHTML(), 'dynamic' );
471 function catlinks() {
472 if ( !isset( $this->mCatlinks
) ) {
473 $this->mCatlinks
= $this->getCategories();
475 return cbt_value( $this->mCatlinks
, 'dynamic' );
478 function extratabs( $itemTemplate ) {
479 global $wgContLang, $wgDisableLangConversion;
481 $etpl = cbt_escape( $itemTemplate );
483 /* show links to different language variants */
484 $variants = $wgContLang->getVariants();
486 if ( !$wgDisableLangConversion && count( $wgContLang->getVariants() ) > 1 ) {
488 foreach ( $variants as $code ) {
489 $name = $wgContLang->getVariantname( $code );
490 if ( $name == 'disable' ) {
493 $code = cbt_escape( $code );
494 $name = cbt_escape( $name );
495 $s .= "{ca_variant {{$code}} {{$name}} {{$vcount}} {{$etpl}}}\n";
499 return cbt_value( $s, array(), true );
502 function is_special() { return cbt_value( $this->mTitle
->getNamespace() == NS_SPECIAL
, 'title' ); }
503 function can_edit() { return cbt_value( (string)($this->mTitle
->userCanEdit()), 'dynamic' ); }
504 function can_move() { return cbt_value( (string)($this->mTitle
->userCanMove()), 'dynamic' ); }
505 function is_talk() { return cbt_value( (string)($this->mTitle
->isTalkPage()), 'title' ); }
506 function is_protected() { return cbt_value( (string)$this->mTitle
->isProtected(), 'dynamic' ); }
507 function nskey() { return cbt_value( $this->mTitle
->getNamespaceKey(), 'title' ); }
509 function request_url() {
511 return cbt_value( $wgRequest->getRequestURL(), 'dynamic' );
514 function subject_url() {
515 $title = $this->getSubjectPage();
516 if ( $title->exists() ) {
517 $url = $title->getLocalUrl();
519 $url = $title->getLocalUrl( 'action=edit' );
521 return cbt_value( $url, 'title' );
524 function talk_url() {
525 $title = $this->getTalkPage();
526 if ( $title->exists() ) {
527 $url = $title->getLocalUrl();
529 $url = $title->getLocalUrl( 'action=edit' );
531 return cbt_value( $url, 'title' );
534 function edit_url() {
535 return cbt_value( $this->getEditUrl(), array( 'title', 'nonview dynamic' ) );
538 function move_url() {
539 return cbt_value( $this->makeSpecialParamUrl( 'Movepage' ), array(), true );
542 function localurl( $query ) {
543 return cbt_value( $this->mTitle
->getLocalURL( $query ), 'title' );
546 function selecttab( $tab, $extraclass = '' ) {
547 if ( !isset( $this->mSelectedTab
) ) {
548 $prevent_active_tabs = false ;
549 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$preventActiveTabs ) );
554 'history' => 'history',
555 'protect' => 'protect',
556 'unprotect' => 'protect',
557 'delete' => 'delete',
559 'unwatch' => 'watch',
561 if ( $preventActiveTabs ) {
562 $this->mSelectedTab
= false;
564 $action = $this->getAction();
565 $section = $this->getSection();
567 if ( isset( $actionTabs[$action] ) ) {
568 $this->mSelectedTab
= $actionTabs[$action];
570 if ( $this->mSelectedTab
== 'edit' && $section == 'new' ) {
571 $this->mSelectedTab
= 'addsection';
573 } elseif ( $this->mTitle
->isTalkPage() ) {
574 $this->mSelectedTab
= 'talk';
576 $this->mSelectedTab
= 'subject';
581 if ( $this->mSelectedTab
== $tab ) {
582 $s = 'class="selected ' . htmlspecialchars( $extraclass ) . '"';
584 $s = 'class="' . htmlspecialchars( $extraclass ) . '"';
587 if ( $this->mSelectedTab
== $tab ) {
588 $s = 'class="selected"';
593 return cbt_value( $s, array( 'nonview dynamic', 'title' ) );
596 function subject_newclass() {
597 $title = $this->getSubjectPage();
598 $class = $title->exists() ?
'' : 'new';
599 return cbt_value( $class, 'dynamic' );
602 function talk_newclass() {
603 $title = $this->getTalkPage();
604 $class = $title->exists() ?
'' : 'new';
605 return cbt_value( $class, 'dynamic' );
608 function ca_variant( $code, $name, $index, $template ) {
610 $selected = ($code == $wgContLang->getPreferredVariant());
611 $action = $this->getAction();
614 $actstr = 'action=' . $action . '&';
615 $s = strtr( $template, array(
616 '$id' => htmlspecialchars( 'varlang-' . $index ),
617 '$class' => $selected ?
'class="selected"' : '',
619 '$href' => htmlspecialchars( $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code ) )
621 return cbt_value( $s, 'dynamic' );
624 function is_watching() {
625 return cbt_value( (string)$this->mTitle
->userIsWatching(), array( 'dynamic' ) );
629 function personal_urls( $itemTemplate ) {
630 global $wgShowIPinHeader, $wgContLang;
632 # Split this function up into many small functions, to obtain the
633 # best specificity in the dependencies of each one. The template below
634 # has no dependencies, so its generation, and any static subfunctions,
635 # can be optimised away.
636 $etpl = cbt_escape( $itemTemplate );
640 {preferences {{$etpl}}}
641 {watchlist {{$etpl}}}
642 {mycontris {{$etpl}}}
646 if ( $wgShowIPinHeader ) {
648 {anonuserpage {{$etpl}}}
650 {anonlogin {{$etpl}}}
653 $s .= "{login {{$etpl}}}\n";
656 return cbt_value( $s, array(), true /*this is a template*/ );
659 function userpage( $itemTemplate ) {
661 if ( $this->isLoggedIn() ) {
662 $userPage = $this->getUserPageTitle();
663 $s = $this->makeTemplateLink( $itemTemplate, 'userpage', $userPage, $wgUser->getName() );
667 return cbt_value( $s, 'user' );
670 function mytalk( $itemTemplate ) {
672 if ( $this->isLoggedIn() ) {
673 $userPage = $this->getUserPageTitle();
674 $talkPage = $userPage->getTalkPage();
675 $s = $this->makeTemplateLink( $itemTemplate, 'mytalk', $talkPage, wfMsg('mytalk') );
679 return cbt_value( $s, 'user' );
682 function preferences( $itemTemplate ) {
683 if ( $this->isLoggedIn() ) {
684 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'preferences',
685 'Preferences', wfMsg( 'preferences' ) );
689 return cbt_value( $s, array( 'loggedin', 'lang' ) );
692 function watchlist( $itemTemplate ) {
693 if ( $this->isLoggedIn() ) {
694 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'watchlist',
695 'Watchlist', wfMsg( 'watchlist' ) );
699 return cbt_value( $s, array( 'loggedin', 'lang' ) );
702 function mycontris( $itemTemplate ) {
703 if ( $this->isLoggedIn() ) {
705 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'mycontris',
706 "Contributions/" . $wgUser->getTitleKey(), wfMsg('mycontris') );
710 return cbt_value( $s, 'user' );
713 function logout( $itemTemplate ) {
714 if ( $this->isLoggedIn() ) {
715 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'logout',
716 'Userlogout', wfMsg( 'userlogout' ),
717 $this->mTitle
->getNamespace() === NS_SPECIAL
&& $this->mTitle
->getText() === 'Preferences'
718 ?
'' : "returnto=" . $this->mTitle
->getPrefixedURL() );
722 return cbt_value( $s, 'loggedin dynamic' );
725 function anonuserpage( $itemTemplate ) {
726 if ( $this->isLoggedIn() ) {
730 $userPage = $this->getUserPageTitle();
731 $s = $this->makeTemplateLink( $itemTemplate, 'userpage', $userPage, $wgUser->getName() );
733 return cbt_value( $s, '!loggedin dynamic' );
736 function anontalk( $itemTemplate ) {
737 if ( $this->isLoggedIn() ) {
740 $userPage = $this->getUserPageTitle();
741 $talkPage = $userPage->getTalkPage();
742 $s = $this->makeTemplateLink( $itemTemplate, 'mytalk', $talkPage, wfMsg('anontalk') );
744 return cbt_value( $s, '!loggedin dynamic' );
747 function anonlogin( $itemTemplate ) {
748 if ( $this->isLoggedIn() ) {
751 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'anonlogin', 'Userlogin',
752 wfMsg( 'userlogin' ), 'returnto=' . urlencode( $this->getThisPDBK() ) );
754 return cbt_value( $s, '!loggedin dynamic' );
757 function login( $itemTemplate ) {
758 if ( $this->isLoggedIn() ) {
761 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'login', 'Userlogin',
762 wfMsg( 'userlogin' ), 'returnto=' . urlencode( $this->getThisPDBK() ) );
764 return cbt_value( $s, '!loggedin dynamic' );
767 function logopath() { return $GLOBALS['wgLogo']; }
768 function mainpage() { return $this->makeI18nUrl( 'mainpage' ); }
770 function sidebar( $startSection, $endSection, $innerTpl ) {
772 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
773 $firstSection = true;
774 foreach ($lines as $line) {
775 if (strpos($line, '*') !== 0)
777 if (strpos($line, '**') !== 0) {
778 $bar = trim($line, '* ');
779 $name = wfMsg( $bar );
780 if (wfEmptyMsg($bar, $name)) {
783 if ( $firstSection ) {
784 $firstSection = false;
788 $s .= strtr( $startSection,
790 '$bar' => htmlspecialchars( $bar ),
794 if (strpos($line, '|') !== false) { // sanity check
795 $line = explode( '|' , trim($line, '* '), 2 );
796 $link = wfMsgForContent( $line[0] );
799 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
801 if (wfEmptyMsg($line[0], $link))
803 $href = $this->makeInternalOrExternalUrl( $link );
805 $s .= strtr( $innerTpl,
807 '$text' => htmlspecialchars( $text ),
808 '$href' => htmlspecialchars( $href ),
809 '$id' => htmlspecialchars( 'n-' . strtr($line[1], ' ', '-') ),
815 if ( !$firstSection ) {
819 // Depends on user language only
820 return cbt_value( $s, 'lang' );
823 function searchaction() {
825 return $this->getSearchLink();
830 return cbt_value( trim( $this->getSearch() ), 'special dynamic' );
833 function notspecialpage() {
834 return cbt_value( $this->mTitle
->getNamespace() != NS_SPECIAL
, 'special' );
837 function nav_whatlinkshere() {
838 return cbt_value( $this->makeSpecialParamUrl('Whatlinkshere' ), array(), true );
841 function article_exists() {
842 return cbt_value( (string)($this->mTitle
->getArticleId() !== 0), 'title' );
845 function nav_recentchangeslinked() {
846 return cbt_value( $this->makeSpecialParamUrl('Recentchangeslinked' ), array(), true );
849 function feeds( $itemTemplate = '' ) {
850 if ( !$this->mOut
->isSyndicated() ) {
852 } elseif ( $itemTemplate == '' ) {
853 // boolean only required
857 global $wgFeedClasses, $wgRequest;
858 foreach( $wgFeedClasses as $format => $class ) {
859 $feeds .= strtr( $itemTemplate,
861 '$key' => htmlspecialchars( $format ),
863 '$href' => $wgRequest->appendQuery( "feed=$format" )
867 return cbt_value( $feeds, 'special dynamic' );
870 function is_userpage() {
871 list( $id, $ip ) = $this->getUserPageIdIp();
872 return cbt_value( (string)($id ||
$ip), 'title' );
875 function is_ns_mediawiki() {
876 return cbt_value( (string)$this->mTitle
->getNamespace() == NS_MEDIAWIKI
, 'title' );
879 function is_loggedin() {
881 return cbt_value( (string)($wgUser->isLoggedIn()), 'loggedin' );
884 function nav_contributions() {
885 $url = $this->makeSpecialParamUrl( 'Contributions', '', '{title_userurl}' );
886 return cbt_value( $url, array(), true );
889 function is_allowed( $right ) {
891 return cbt_value( (string)$wgUser->isAllowed( $right ), 'user' );
894 function nav_blockip() {
895 $url = $this->makeSpecialParamUrl( 'Blockip', '', '{title_userurl}' );
896 return cbt_value( $url, array(), true );
899 function nav_emailuser() {
900 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
901 if ( !$wgEnableEmail ||
!$wgEnableUserEmail ) return '';
903 $url = $this->makeSpecialParamUrl( 'Emailuser', '', '{title_userurl}' );
904 return cbt_value( $url, array(), true );
907 function nav_upload() {
908 global $wgEnableUploads, $wgUploadNavigationUrl;
909 if ( !$wgEnableUploads ) {
911 } elseif ( $wgUploadNavigationUrl ) {
912 return $wgUploadNavigationUrl;
914 return $this->makeSpecialUrl('Upload');
918 function nav_specialpages() {
919 return $this->makeSpecialUrl('Specialpages');
922 function nav_print() {
923 global $wgRequest, $wgArticle;
924 $action = $this->getAction();
926 if( $this->mTitle
->getNamespace() !== NS_SPECIAL
927 && ($action == '' ||
$action == 'view' ||
$action == 'purge' ) )
929 $revid = $wgArticle->getLatest();
931 $url = $wgRequest->appendQuery( 'printable=yes' );
934 return cbt_value( $url, array( 'nonview dynamic', 'title' ) );
937 function nav_permalink() {
938 $url = (string)$this->getPermalink();
939 return cbt_value( $url, 'dynamic' );
942 function nav_trackbacklink() {
943 global $wgUseTrackbacks;
944 if ( !$wgUseTrackbacks ) return '';
946 return cbt_value( $this->mTitle
->trackbackURL(), 'title' );
949 function is_permalink() {
950 return cbt_value( (string)($this->getPermalink() === false), 'nonview dynamic' );
953 function toolboxend() {
954 // This is where the MonoBookTemplateToolboxEnd hook went in the old skin
958 function language_urls( $outer, $inner ) {
959 global $wgHideInterlanguageLinks, $wgOut, $wgContLang;
960 if ( $wgHideInterlanguageLinks ) return '';
962 $links = $wgOut->getLanguageLinks();
964 if ( count( $links ) ) {
965 foreach( $links as $l ) {
966 $tmp = explode( ':', $l, 2 );
967 $nt = Title
::newFromText( $l );
970 '$class' => htmlspecialchars( 'interwiki-' . $tmp[0] ),
971 '$href' => htmlspecialchars( $nt->getFullURL() ),
972 '$text' => ($wgContLang->getLanguageName( $nt->getInterwiki() ) != ''?
973 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
977 $s = str_replace( '$body', $s, $outer );
979 return cbt_value( $s, 'dynamic' );
982 function poweredbyico() { return $this->getPoweredBy(); }
983 function copyrightico() { return $this->getCopyrightIcon(); }
986 global $wgMaxCredits;
987 if ( $wgMaxCredits ) return '';
989 if ( !isset( $this->mLastmod
) ) {
990 if ( $this->isCurrentArticleView() ) {
991 $this->mLastmod
= $this->lastModified();
993 $this->mLastmod
= '';
996 return cbt_value( $this->mLastmod
, 'dynamic' );
999 function viewcount() {
1000 global $wgDisableCounters;
1001 if ( $wgDisableCounters ) return '';
1003 global $wgLang, $wgArticle;
1004 if ( is_object( $wgArticle ) ) {
1005 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
1007 $viewcount = wfMsg( "viewcount", $viewcount );
1014 return cbt_value( $viewcount, 'dynamic' );
1017 function numberofwatchingusers() {
1018 global $wgPageShowWatchingUsers;
1019 if ( !$wgPageShowWatchingUsers ) return '';
1021 $dbr =& wfGetDB( DB_SLAVE
);
1022 extract( $dbr->tableNames( 'watchlist' ) );
1023 $sql = "SELECT COUNT(*) AS n FROM $watchlist
1024 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
1025 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
1026 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
1027 $row = $dbr->fetchObject( $res );
1030 $s = wfMsg('number_of_watching_users_pageview', $num);
1034 return cbt_value( $s, 'dynamic' );
1037 function credits() {
1038 global $wgMaxCredits;
1039 if ( !$wgMaxCredits ) return '';
1041 if ( $this->isCurrentArticleView() ) {
1042 require_once("Credits.php");
1043 global $wgArticle, $wgShowCreditsIfMax;
1044 $credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
1048 return cbt_value( $credits, 'view dynamic' );
1051 function normalcopyright() {
1052 return $this->getCopyright( 'normal' );
1055 function historycopyright() {
1056 return $this->getCopyright( 'history' );
1059 function is_currentview() {
1061 return cbt_value( (string)$this->isCurrentArticleView(), 'view' );
1064 function usehistorycopyright() {
1066 if ( wfMsgForContent( 'history_copyright' ) == '-' ) return '';
1068 $oldid = $this->getOldId();
1069 $diff = $this->getDiff();
1070 $use = (string)(!is_null( $oldid ) && is_null( $diff ));
1071 return cbt_value( $use, 'nonview dynamic' );
1074 function privacy() {
1075 return cbt_value( $this->privacyLink(), 'lang' );
1078 return cbt_value( $this->aboutLink(), 'lang' );
1080 function disclaimer() {
1081 return cbt_value( $this->disclaimerLink(), 'lang' );
1083 function tagline() {
1084 # A reference to this tag existed in the old MonoBook.php, but the
1085 # template data wasn't set anywhere
1088 function reporttime() {
1089 return cbt_value( $this->mOut
->reportTime(), 'dynamic' );
1092 function msg( $name ) {
1093 return cbt_value( wfMsg( $name ), 'lang' );
1096 function fallbackmsg( $name, $fallback ) {
1097 $text = wfMsg( $name );
1098 if ( wfEmptyMsg( $name, $text ) ) {
1101 return cbt_value( $text, 'lang' );
1104 /******************************************************
1105 * Utility functions *
1106 ******************************************************/
1108 /** Return true if this request is a valid, secure CSS preview */
1109 function isCssPreview() {
1110 if ( !isset( $this->mCssPreview
) ) {
1111 global $wgRequest, $wgAllowUserCss, $wgUser;
1112 $this->mCssPreview
=
1114 $wgUser->isLoggedIn() &&
1115 $this->mTitle
->isCssSubpage() &&
1116 $this->userCanPreview( $this->getAction() );
1118 return $this->mCssPreview
;
1121 /** Return true if this request is a valid, secure JS preview */
1122 function isJsPreview() {
1123 if ( !isset( $this->mJsPreview
) ) {
1124 global $wgRequest, $wgAllowUserJs, $wgUser;
1127 $wgUser->isLoggedIn() &&
1128 $this->mTitle
->isJsSubpage() &&
1129 $this->userCanPreview( $this->getAction() );
1131 return $this->mJsPreview
;
1134 /** Get the title of the $wgUser's user page */
1135 function getUserPageTitle() {
1136 if ( !isset( $this->mUserPageTitle
) ) {
1138 $this->mUserPageTitle
= $wgUser->getUserPage();
1140 return $this->mUserPageTitle
;
1143 /** Get the text of the user page title */
1144 function getUserPageText() {
1145 if ( !isset( $this->mUserPageText
) ) {
1146 $userPage = $this->getUserPageTitle();
1147 $this->mUserPageText
= $userPage->getPrefixedText();
1149 return $this->mUserPageText
;
1152 /** Make an HTML element for a stylesheet link */
1153 function makeStylesheetLink( $url ) {
1154 return '<link rel="stylesheet" type="text/css" href="' . htmlspecialchars( $url ) . "\"/>";
1157 /** Make an XHTML element for inline CSS */
1158 function makeStylesheetCdata( $style ) {
1159 return "<style type=\"text/css\"> /*<![CDATA[*/ {$style} /*]]>*/ </style>";
1162 /** Get the edit URL for this page */
1163 function getEditUrl() {
1164 if ( !isset( $this->mEditUrl
) ) {
1165 $this->mEditUrl
= $this->mTitle
->getLocalUrl( $this->editUrlOptions() );
1167 return $this->mEditUrl
;
1170 /** Get the prefixed DB key for this page */
1171 function getThisPDBK() {
1172 if ( !isset( $this->mThisPDBK
) ) {
1173 $this->mThisPDBK
= $this->mTitle
->getPrefixedDbKey();
1175 return $this->mThisPDBK
;
1178 function getThisTitleUrlForm() {
1179 if ( !isset( $this->mThisTitleUrlForm
) ) {
1180 $this->mThisTitleUrlForm
= $this->mTitle
->getPrefixedURL();
1182 return $this->mThisTitleUrlForm
;
1186 * If the current page is a user page, get the user's ID and IP. Otherwise return array(0,false)
1188 function getUserPageIdIp() {
1189 if ( !isset( $this->mUserPageId
) ) {
1190 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
1191 $this->mUserPageId
= User
::idFromName($this->mTitle
->getText());
1192 $this->mUserPageIp
= User
::isIP($this->mTitle
->getText());
1194 $this->mUserPageId
= 0;
1195 $this->mUserPageIp
= false;
1198 return array( $this->mUserPageId
, $this->mUserPageIp
);
1202 * Returns a permalink URL, or false if the current page is already a
1203 * permalink, or blank if a permalink shouldn't be displayed
1205 function getPermalink() {
1206 if ( !isset( $this->mPermalink
) ) {
1207 global $wgRequest, $wgArticle;
1208 $action = $this->getAction();
1209 $oldid = $this->getOldId();
1211 if( $this->mTitle
->getNamespace() !== NS_SPECIAL
1212 && $this->mTitle
->getArticleId() != 0
1213 && ($action == '' ||
$action == 'view' ||
$action == 'purge' ) )
1216 $revid = $wgArticle->getLatest();
1217 $url = $this->mTitle
->getLocalURL( "oldid=$revid" );
1229 * Returns true if the current page is an article, not a special page,
1230 * and we are viewing a revision, not a diff
1232 function isArticleView() {
1233 global $wgOut, $wgArticle, $wgRequest;
1234 if ( !isset( $this->mIsArticleView
) ) {
1235 $oldid = $this->getOldId();
1236 $diff = $this->getDiff();
1237 $this->mIsArticleView
= $wgOut->isArticle() and
1238 (!is_null( $oldid ) or is_null( $diff )) and 0 != $wgArticle->getID();
1240 return $this->mIsArticleView
;
1243 function isCurrentArticleView() {
1244 if ( !isset( $this->mIsCurrentArticleView
) ) {
1245 global $wgOut, $wgArticle, $wgRequest;
1246 $oldid = $this->getOldId();
1247 $this->mIsCurrentArticleView
= $wgOut->isArticle() && is_null( $oldid ) && 0 != $wgArticle->getID();
1249 return $this->mIsCurrentArticleView
;
1254 * Return true if the current page is editable; if edit section on right
1255 * click should be enabled.
1257 function isEditable() {
1259 $action = $this->getAction();
1260 return ($this->mTitle
->getNamespace() != NS_SPECIAL
and !($action == 'edit' or $action == 'submit'));
1263 /** Return true if the user is logged in */
1264 function isLoggedIn() {
1266 return $wgUser->isLoggedIn();
1269 /** Get the local URL of the current page */
1270 function getPageUrl() {
1271 if ( !isset( $this->mPageUrl
) ) {
1272 $this->mPageUrl
= $this->mTitle
->getLocalURL();
1274 return $this->mPageUrl
;
1277 /** Make a link to a title using a template */
1278 function makeTemplateLink( $template, $key, $title, $text ) {
1279 $url = $title->getLocalUrl();
1280 return strtr( $template,
1283 '$classactive' => ($url == $this->getPageUrl()) ?
'class="active"' : '',
1284 '$class' => $title->getArticleID() == 0 ?
'class="new"' : '',
1285 '$href' => htmlspecialchars( $url ),
1290 /** Make a link to a URL using a template */
1291 function makeTemplateLinkUrl( $template, $key, $url, $text ) {
1292 return strtr( $template,
1295 '$classactive' => ($url == $this->getPageUrl()) ?
'class="active"' : '',
1297 '$href' => htmlspecialchars( $url ),
1302 /** Make a link to a special page using a template */
1303 function makeSpecialTemplateLink( $template, $key, $specialName, $text, $query = '' ) {
1304 $url = $this->makeSpecialUrl( $specialName, $query );
1305 // Ignore the query when comparing
1306 $active = ($this->mTitle
->getNamespace() == NS_SPECIAL
&& $this->mTitle
->getDBkey() == $specialName);
1307 return strtr( $template,
1310 '$classactive' => $active ?
'class="active"' : '',
1312 '$href' => htmlspecialchars( $url ),
1317 function loadRequestValues() {
1319 $this->mAction
= $wgRequest->getText( 'action' );
1320 $this->mOldId
= $wgRequest->getVal( 'oldid' );
1321 $this->mDiff
= $wgRequest->getVal( 'diff' );
1322 $this->mSection
= $wgRequest->getVal( 'section' );
1323 $this->mSearch
= $wgRequest->getVal( 'search' );
1324 $this->mRequestValuesLoaded
= true;
1329 /** Get the action parameter of the request */
1330 function getAction() {
1331 if ( !isset( $this->mRequestValuesLoaded
) ) {
1332 $this->loadRequestValues();
1334 return $this->mAction
;
1337 /** Get the oldid parameter */
1338 function getOldId() {
1339 if ( !isset( $this->mRequestValuesLoaded
) ) {
1340 $this->loadRequestValues();
1342 return $this->mOldId
;
1345 /** Get the diff parameter */
1346 function getDiff() {
1347 if ( !isset( $this->mRequestValuesLoaded
) ) {
1348 $this->loadRequestValues();
1350 return $this->mDiff
;
1353 function getSection() {
1354 if ( !isset( $this->mRequestValuesLoaded
) ) {
1355 $this->loadRequestValues();
1357 return $this->mSection
;
1360 function getSearch() {
1361 if ( !isset( $this->mRequestValuesLoaded
) ) {
1362 $this->loadRequestValues();
1364 return $this->mSearch
;
1367 /** Make a special page URL of the form [[Special:Somepage/{title_urlform}]] */
1368 function makeSpecialParamUrl( $name, $query = '', $param = '{title_urlform}' ) {
1369 // Abuse makeTitle's lax validity checking to slip a control character into the URL
1370 $title = Title
::makeTitle( NS_SPECIAL
, "$name/\x1a" );
1371 $url = cbt_escape( $title->getLocalURL( $query ) );
1372 // Now replace it with the parameter
1373 return str_replace( '%1A', $param, $url );
1376 function getSubjectPage() {
1377 if ( !isset( $this->mSubjectPage
) ) {
1378 $this->mSubjectPage
= $this->mTitle
->getSubjectPage();
1380 return $this->mSubjectPage
;
1383 function getTalkPage() {
1384 if ( !isset( $this->mTalkPage
) ) {
1385 $this->mTalkPage
= $this->mTitle
->getTalkPage();
1387 return $this->mTalkPage
;