3 if ( !defined( 'MEDIAWIKI' ) ) {
4 die( "This file is part of MediaWiki, it is not a valid entry point\n" );
7 require_once( dirname(__FILE__
) . '/../includes/cbt/CBTProcessor.php' );
8 require_once( dirname(__FILE__
) . '/../includes/cbt/CBTCompiler.php' );
9 require_once( dirname(__FILE__
) . '/../includes/SkinTemplate.php' );
13 * MonoBook clone using the new dependency-tracking template processor.
14 * EXPERIMENTAL - use only for testing and profiling at this stage
16 * The main thing that's missing is cache invalidation, on change of:
20 * * source code and configuration files
22 * The other thing is that lots of dependencies that are declared in the callbacks
23 * are not intelligently handled. There's some room for improvement there.
25 * The class is derived from SkinTemplate, but that's only temporary. Eventually
26 * it'll be derived from Skin, and I've avoided using SkinTemplate functions as
27 * much as possible. In fact, the only SkinTemplate dependencies I know of at the
28 * moment are the functions to generate the gen=css and gen=js files.
31 class SkinMonoBookCBT
extends SkinTemplate
{
33 var $mStyleName = 'monobook';
34 var $mCompiling = false;
36 /******************************************************
38 ******************************************************/
40 /** Execute the template and write out the result */
41 function outputPage( &$out ) {
42 echo $this->execute( $out );
45 function execute( &$out ) {
46 global $wgTitle, $wgStyleDirectory, $wgParserCacheType;
47 $fname = 'SkinMonoBookCBT::execute';
48 wfProfileIn( $fname );
49 wfProfileIn( "$fname-setup" );
50 Skin
::initPage( $out );
53 $this->mTitle
=& $wgTitle;
55 $sourceFile = "$wgStyleDirectory/MonoBook.tpl";
57 wfProfileOut( "$fname-setup" );
59 if ( $wgParserCacheType == CACHE_NONE
) {
60 $template = file_get_contents( $sourceFile );
61 $text = $this->executeTemplate( $template );
63 $compiled = $this->getCompiledTemplate( $sourceFile );
65 #$text = $this->executeTemplate( $compiled );
66 $text = eval( $compiled );
68 wfProfileOut( $fname );
72 function getCompiledTemplate( $sourceFile ) {
73 global $wgDBname, $wgMemc, $wgRequest, $wgUser, $parserMemc;
74 $fname = 'SkinMonoBookCBT::getCompiledTemplate';
76 // Sandbox template execution
77 if ( $this->mCompiling
) {
81 wfProfileIn( $fname );
83 // Is the request an ordinary page view?
84 if ( $wgRequest->wasPosted() ||
85 count( array_diff( array_keys( $_GET ), array( 'title', 'useskin', 'recompile' ) ) ) != 0 )
92 // Per-user compiled template
93 // Put all logged-out users on the same cache key
94 $cacheKey = "$wgDBname:monobookcbt:$type:" . $wgUser->getId();
96 $recompile = $wgRequest->getVal( 'recompile' );
98 $php = $parserMemc->get( $cacheKey );
100 if ( $recompile ||
!$php ) {
101 $template = file_get_contents( $sourceFile );
103 $ignore = array( 'lang', 'loggedin', 'user' );
104 if ( $wgUser->isLoggedIn() ) {
105 $ignore[] = '!loggedin dynamic';
107 $ignore[] = 'loggedin dynamic';
109 if ( $type == 'view' ) {
110 $ignore[] = 'nonview dynamic';
112 $tp = new CBTProcessor( $template, $this, $ignore );
113 $this->mCompiling
= true;
114 $compiled = $tp->compile();
115 $this->mCompiling
= false;
116 if ( $tp->getLastError() ) {
117 // If there was a compile error, don't save the template
118 // Instead just print the error and exit
124 // This is done here instead of in CBTProcessor because we can be
125 // more sure it is safe here.
126 $compiled = preg_replace( '/^[ \t]+/m', '', $compiled );
127 $compiled = preg_replace( '/[\r\n]+/', "\n", $compiled );
130 $compiler = new CBTCompiler( $compiled );
131 $compiler->compile();
132 $php = 'return ' . $compiler->generatePHP( '$this' ) . ";\n";
134 if ( !php_check_syntax( $php, $error ) ) {
135 print "$error <pre>" . htmlspecialchars( $php ) . '</pre>';
140 $parserMemc->set( $cacheKey, $php, 3600 );
142 wfProfileOut( $fname );
146 function executeTemplate( $template ) {
147 $fname = 'SkinMonoBookCBT::executeTemplate';
148 wfProfileIn( $fname );
149 $tp = new CBTProcessor( $template, $this );
150 $this->mCompiling
= true;
151 $text = $tp->execute();
152 $this->mCompiling
= false;
153 wfProfileOut( $fname );
157 /******************************************************
159 ******************************************************/
161 function lang() { return $GLOBALS['wgContLanguageCode']; }
165 return $wgContLang->isRTL() ?
'rtl' : 'ltr';
168 function mimetype() { return $GLOBALS['wgMimeType']; }
169 function charset() { return $GLOBALS['wgOutputEncoding']; }
170 function headlinks() {
171 return new CBTValue( $this->mOut
->getHeadLinks(), 'dynamic' );
173 function headscripts() {
174 return new CBTValue( $this->mOut
->getScript(), 'dynamic' );
177 function pagetitle() {
178 return new CBTValue( $this->mOut
->getHTMLTitle(), array( 'title', 'lang' ) );
181 function stylepath() { return $GLOBALS['wgStylePath']; }
182 function stylename() { return $this->mStyleName
; }
184 function notprintable() {
186 return new CBTValue( !$wgRequest->getBool( 'printable' ), 'nonview dynamic' );
189 function jsmimetype() { return $GLOBALS['wgJsMimeType']; }
191 function jsvarurl() {
192 global $wgUseSiteJs, $wgUser;
193 if ( !$wgUseSiteJs ) return '';
195 if ( $wgUser->isLoggedIn() ) {
196 $url = $this->makeUrl('-','action=raw&smaxage=0&gen=js');
198 $url = $this->makeUrl('-','action=raw&gen=js');
200 return new CBTValue( $url, 'loggedin' );
207 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
209 // Unknown dependencies
210 return new CBTValue( $out, 'dynamic' );
214 if ( $this->isCssPreview() ) {
216 $usercss = $this->makeStylesheetCdata( $wgRequest->getText('wpTextbox1') );
218 $usercss = $this->makeStylesheetLink( $this->makeUrl($this->getUserPageText() .
219 '/'.$this->mStyleName
.'.css', 'action=raw&ctype=text/css' ) );
222 // Dynamic when not an ordinary page view, also depends on the username
223 return new CBTValue( $usercss, array( 'nonview dynamic', 'user' ) );
227 global $wgUseSiteCss;
228 if ( !$wgUseSiteCss ) {
232 global $wgSquidMaxage, $wgContLang, $wgStylePath;
234 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
237 if ( $wgContLang->isRTL() ) {
238 $sitecss .= $this->makeStylesheetLink( $wgStylePath . '/' . $this->mStyleName
. '/rtl.css' ) . "\n";
241 $sitecss .= $this->makeStylesheetLink( $this->makeNSUrl('Common.css', $query, NS_MEDIAWIKI
) ) . "\n";
242 $sitecss .= $this->makeStylesheetLink( $this->makeNSUrl(
243 ucfirst($this->mStyleName
) . '.css', $query, NS_MEDIAWIKI
) ) . "\n";
250 global $wgUseSiteCss;
251 if ( !$wgUseSiteCss ) return '';
253 global $wgSquidMaxage, $wgUser, $wgAllowUserCss;
254 if ( $this->isCssPreview() ) {
255 $siteargs = '&smaxage=0&maxage=0';
257 $siteargs = '&maxage=' . $wgSquidMaxage;
259 if ( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
260 $siteargs .= '&ts={user_touched}';
266 $link = $this->makeStylesheetLink( $this->makeUrl('-','action=raw&gen=css' . $siteargs) ) . "\n";
268 if ( $wgAllowUserCss ) {
273 return new CBTValue( $link, $deps, $isTemplate );
276 function user_touched() {
278 return new CBTValue( $wgUser->mTouched
, 'dynamic' );
282 global $wgAllowUserJs, $wgJsMimeType;
283 if ( !$wgAllowUserJs ) return '';
285 if ( $this->isJsPreview() ) {
288 $url = $this->makeUrl($this->getUserPageText().'/'.$this->mStyleName
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
290 return new CBTValue( $url, array( 'nonview dynamic', 'user' ) );
293 function userjsprev() {
294 global $wgAllowUserJs, $wgRequest;
295 if ( !$wgAllowUserJs ) return '';
296 if ( $this->isJsPreview() ) {
297 $js = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
301 return new CBTValue( $js, array( 'nonview dynamic' ) );
304 function trackbackhtml() {
305 global $wgUseTrackbacks;
306 if ( !$wgUseTrackbacks ) return '';
308 if ( $this->mOut
->isArticleRelated() ) {
309 $tb = $this->mTitle
->trackbackRDF();
313 return new CBTValue( $tb, 'dynamic' );
316 function body_ondblclick() {
318 if( $this->isEditable() && $wgUser->getOption("editondblclick") ) {
319 $js = 'document.location = "' . $this->getEditUrl() .'";';
324 if ( User
::getDefaultOption('editondblclick') ) {
325 return new CBTValue( $js, 'user', 'title' );
327 // Optimise away for logged-out users
328 return new CBTValue( $js, 'loggedin dynamic' );
332 function body_onload() {
334 if ( $this->isEditable() && $wgUser->getOption( 'editsectiononrightclick' ) ) {
335 $js = 'setupRightClickEdit()';
339 return new CBTValue( $js, 'loggedin dynamic' );
343 return new CBTValue( 'ns-' . $this->mTitle
->getNamespace(), 'title' );
346 function sitenotice() {
347 // Perhaps this could be given special dependencies using our knowledge of what
348 // wfGetSiteNotice() depends on.
349 return new CBTValue( wfGetSiteNotice(), 'dynamic' );
353 return new CBTValue( $this->mOut
->getPageTitle(), array( 'title', 'lang' ) );
356 function title_urlform() {
357 return new CBTValue( $this->getThisTitleUrlForm(), 'title' );
360 function title_userurl() {
361 return new CBTValue( urlencode( $this->mTitle
->getDBkey() ), 'title' );
364 function subtitle() {
365 $subpagestr = $this->subPageSubtitle();
366 if ( !empty( $subpagestr ) ) {
367 $s = '<span class="subpages">'.$subpagestr.'</span>'.$this->mOut
->getSubtitle();
369 $s = $this->mOut
->getSubtitle();
371 return new CBTValue( $s, array( 'title', 'nonview dynamic' ) );
374 function undelete() {
375 return new CBTValue( $this->getUndeleteLink(), array( 'title', 'lang' ) );
379 global $wgUser, $wgDBname;
380 $newtalks = $wgUser->getNewMessageLinks();
382 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === $wgDBname) {
383 $usertitle = $this->getUserPageTitle();
384 $usertalktitle = $usertitle->getTalkPage();
385 if( !$usertalktitle->equals( $this->mTitle
) ) {
386 $ntl = wfMsg( 'youhavenewmessages',
387 $this->makeKnownLinkObj(
389 wfMsgHtml( 'newmessageslink' ),
392 $this->makeKnownLinkObj(
394 wfMsgHtml( 'newmessagesdifflink' ),
399 $this->mOut
->setSquidMaxage(0);
401 } else if (count($newtalks)) {
402 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
404 foreach ($newtalks as $newtalk) {
405 $msgs[] = wfElement("a",
406 array('href' => $newtalk["link"]), $newtalk["wiki"]);
408 $parts = implode($sep, $msgs);
409 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
410 $this->mOut
->setSquidMaxage(0);
414 return new CBTValue( $ntl, 'dynamic' );
417 function showjumplinks() {
419 return new CBTValue( $wgUser->getOption( 'showjumplinks' ) ?
'true' : '', 'user' );
422 function bodytext() {
423 return new CBTValue( $this->mOut
->getHTML(), 'dynamic' );
426 function catlinks() {
427 return new CBTValue( $this->getCategories(), 'dynamic' );
430 function extratabs( $itemTemplate ) {
431 global $wgContLang, $wgDisableLangConversion;
433 $etpl = templateEscape( $itemTemplate );
435 /* show links to different language variants */
436 $variants = $wgContLang->getVariants();
438 if ( !$wgDisableLangConversion && count( $wgContLang->getVariants() ) > 1 ) {
440 foreach ( $variants as $code ) {
441 $name = $wgContLang->getVariantname( $code );
442 if ( $name == 'disable' ) {
445 $name = templateEscape( $name );
446 $s .= "{ca_variant {{$code}} {{$name}} {{$vcount}} {{$etpl}}}\n";
450 return new CBTValue( $s, array(), true );
453 function is_special() { return new CBTValue( $this->mTitle
->getNamespace() == NS_SPECIAL
, 'title' ); }
454 function can_edit() { return new CBTValue( (string)($this->mTitle
->userCanEdit()), 'dynamic' ); }
455 function can_move() { return new CBTValue( (string)($this->mTitle
->userCanMove()), 'dynamic' ); }
456 function is_talk() { return new CBTValue( (string)($this->mTitle
->isTalkPage()), 'title' ); }
457 function is_protected() { return new CBTValue( (string)$this->mTitle
->isProtected(), 'dynamic' ); }
458 function nskey() { return new CBTValue( $this->mTitle
->getNamespaceKey(), 'title' ); }
460 function request_url() {
462 return new CBTValue( $wgRequest->getRequestURL(), 'dynamic' );
465 function subject_url() {
466 $title = $this->getSubjectPage();
467 if ( $title->exists() ) {
468 $url = $title->getLocalUrl();
470 $url = $title->getLocalUrl( 'action=edit' );
472 return new CBTValue( $url, 'title' );
475 function talk_url() {
476 $title = $this->getTalkPage();
477 if ( $title->exists() ) {
478 $url = $title->getLocalUrl();
480 $url = $title->getLocalUrl( 'action=edit' );
482 return new CBTValue( $url, 'title' );
485 function edit_url() {
486 return new CBTValue( $this->getEditUrl(), array( 'title', 'nonview dynamic' ) );
489 function move_url() {
490 return new CBTValue( $this->makeSpecialParamUrl( 'Movepage' ), array(), true );
493 function localurl( $query ) {
494 return new CBTValue( $this->mTitle
->getLocalURL( $query ), 'title' );
497 function selecttab( $tab, $extraclass = '' ) {
498 if ( !isset( $this->mSelectedTab
) ) {
499 $prevent_active_tabs = false ;
500 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$preventActiveTabs ) );
505 'history' => 'history',
506 'protect' => 'protect',
507 'unprotect' => 'protect',
508 'delete' => 'delete',
510 'unwatch' => 'watch',
512 if ( $preventActiveTabs ) {
513 $this->mSelectedTab
= false;
515 $action = $this->getAction();
516 $section = $this->getSection();
518 if ( isset( $actionTabs[$action] ) ) {
519 $this->mSelectedTab
= $actionTabs[$action];
521 if ( $this->mSelectedTab
== 'edit' && $section == 'new' ) {
522 $this->mSelectedTab
= 'addsection';
524 } elseif ( $this->mTitle
->isTalkPage() ) {
525 $this->mSelectedTab
= 'talk';
527 $this->mSelectedTab
= 'subject';
532 if ( $this->mSelectedTab
== $tab ) {
533 $s = 'class="selected ' . htmlspecialchars( $extraclass ) . '"';
535 $s = 'class="' . htmlspecialchars( $extraclass ) . '"';
538 if ( $this->mSelectedTab
== $tab ) {
539 $s = 'class="selected"';
544 return new CBTValue( $s, array( 'nonview dynamic', 'title' ) );
547 function subject_newclass() {
548 $title = $this->getSubjectPage();
549 $class = $title->exists() ?
'' : 'new';
550 return new CBTValue( $class, 'dynamic' );
553 function talk_newclass() {
554 $title = $this->getTalkPage();
555 $class = $title->exists() ?
'' : 'new';
556 return new CBTValue( $class, 'dynamic' );
559 function ca_variant( $code, $name, $index, $template ) {
561 $selected = ($code == $wgContLang->getPreferredVariant());
562 $action = $this->getAction();
565 $actstr = 'action=' . $action . '&';
566 $s = strtr( $template, array(
567 '$id' => htmlspecialchars( 'varlang-' . $index ),
568 '$class' => $selected ?
'class="selected"' : '',
570 '$href' => htmlspecialchars( $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code ) )
572 return new CBTValue( $s, 'dynamic' );
575 function is_watching() {
576 return new CBTValue( (string)$this->mTitle
->userIsWatching(), array( 'dynamic' ) );
580 function personal_urls( $itemTemplate ) {
581 global $wgShowIPinHeader, $wgContLang;
583 # Split this function up into many small functions, to obtain the
584 # best specificity in the dependencies of each one. The template below
585 # has no dependencies, so its generation, and any static subfunctions,
586 # can be optimised away.
587 $etpl = templateEscape( $itemTemplate );
591 {preferences {{$etpl}}}
592 {watchlist {{$etpl}}}
593 {mycontris {{$etpl}}}
598 if ( $wgShowIPinHeader ) {
600 {anonuserpage {{$etpl}}}
602 {anonlogin {{$etpl}}}
605 $s .= "{login {{$etpl}}\n";
608 return new CBTValue( $s, array(), true /*this is a template*/ );
611 function userpage( $itemTemplate ) {
613 if ( $this->isLoggedIn() ) {
614 $userPage = $this->getUserPageTitle();
615 $s = $this->makeTemplateLink( $itemTemplate, 'userpage', $userPage, $wgUser->getName() );
619 return new CBTValue( $s, 'user' );
622 function mytalk( $itemTemplate ) {
624 if ( $this->isLoggedIn() ) {
625 $userPage = $this->getUserPageTitle();
626 $talkPage = $userPage->getTalkPage();
627 $s = $this->makeTemplateLink( $itemTemplate, 'mytalk', $talkPage, wfMsg('mytalk') );
631 return new CBTValue( $s, 'user' );
634 function preferences( $itemTemplate ) {
635 if ( $this->isLoggedIn() ) {
636 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'preferences',
637 'Preferences', wfMsg( 'preferences' ) );
641 return new CBTValue( $s, array( 'loggedin', 'lang' ) );
644 function watchlist( $itemTemplate ) {
645 if ( $this->isLoggedIn() ) {
646 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'watchlist',
647 'Watchlist', wfMsg( 'watchlist' ) );
651 return new CBTValue( $s, array( 'loggedin', 'lang' ) );
654 function mycontris( $itemTemplate ) {
655 if ( $this->isLoggedIn() ) {
657 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'mycontris',
658 "Contributions/" . $wgUser->getTitleKey(), wfMsg('mycontris') );
662 return new CBTValue( $s, 'user' );
665 function logout( $itemTemplate ) {
666 if ( $this->isLoggedIn() ) {
667 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'logout',
668 'Userlogout', wfMsg( 'userlogout' ),
669 $this->mTitle
->getNamespace() === NS_SPECIAL
&& $this->mTitle
->getText() === 'Preferences'
670 ?
'' : "returnto=" . $this->mTitle
->getPrefixedURL() );
674 return new CBTValue( $s, 'loggedin dynamic' );
677 function anonuserpage( $itemTemplate ) {
678 if ( $this->isLoggedIn() ) {
682 $userPage = $this->getUserPageTitle();
683 $s = $this->makeTemplateLink( $itemTemplate, 'userpage', $userPage, $wgUser->getName() );
685 return new CBTValue( $s, '!loggedin dynamic' );
688 function anontalk( $itemTemplate ) {
689 if ( $this->isLoggedIn() ) {
692 $userPage = $this->getUserPageTitle();
693 $talkPage = $userPage->getTalkPage();
694 $s = $this->makeTemplateLink( $itemTemplate, 'mytalk', $talkPage, wfMsg('anontalk') );
696 return new CBTValue( $s, '!loggedin dynamic' );
699 function anonlogin( $itemTemplate ) {
700 if ( $this->isLoggedIn() ) {
703 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'anonlogin', 'Userlogin',
704 wfMsg( 'userlogin' ), 'returnto=' . urlencode( $this->getThisPDBK() ) );
706 return new CBTValue( $s, '!loggedin dynamic' );
709 function login( $itemTemplate ) {
710 if ( $this->isLoggedIn() ) {
713 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'login', 'Userlogin',
714 wfMsg( 'userlogin' ), 'returnto=' . urlencode( $this->getThisPDBK() ) );
716 return new CBTValue( $s, '!loggedin dynamic' );
719 function logopath() { return $GLOBALS['wgLogo']; }
720 function mainpage() { return $this->makeI18nUrl( 'mainpage' ); }
722 function sidebar( $startSection, $endSection, $innerTpl ) {
724 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
725 $firstSection = true;
726 foreach ($lines as $line) {
727 if (strpos($line, '*') !== 0)
729 if (strpos($line, '**') !== 0) {
730 $bar = trim($line, '* ');
731 $name = wfMsg( $bar );
732 if (wfEmptyMsg($bar, $name)) {
735 if ( $firstSection ) {
736 $firstSection = false;
740 $s .= strtr( $startSection,
742 '$bar' => htmlspecialchars( $bar ),
746 if (strpos($line, '|') !== false) { // sanity check
747 $line = explode( '|' , trim($line, '* '), 2 );
748 $link = wfMsgForContent( $line[0] );
751 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
753 if (wfEmptyMsg($line[0], $link))
755 $href = $this->makeInternalOrExternalUrl( $link );
757 $s .= strtr( $innerTpl,
759 '$text' => htmlspecialchars( $text ),
760 '$href' => htmlspecialchars( $href ),
761 '$id' => htmlspecialchars( 'n-' . strtr($line[1], ' ', '-') ),
767 if ( !$firstSection ) {
771 // Depends on user language only
772 return new CBTValue( $s, 'lang' );
775 function searchaction() {
777 return $this->getSearchLink();
782 return new CBTValue( trim( $this->getSearch() ), 'special dynamic' );
785 function notspecialpage() {
786 return new CBTValue( $this->mTitle
->getNamespace() != NS_SPECIAL
, 'special' );
789 function nav_whatlinkshere() {
790 return new CBTValue( $this->makeSpecialParamUrl('Whatlinkshere' ), array(), true );
793 function article_exists() {
794 return new CBTValue( (string)($this->mTitle
->getArticleId() !== 0), 'title' );
797 function nav_recentchangeslinked() {
798 return new CBTValue( $this->makeSpecialParamUrl('Recentchangeslinked' ), array(), true );
801 function feeds( $itemTemplate = '' ) {
802 if ( !$this->mOut
->isSyndicated() ) {
804 } elseif ( $itemTemplate == '' ) {
805 // boolean only required
809 global $wgFeedClasses, $wgRequest;
810 foreach( $wgFeedClasses as $format => $class ) {
811 $feeds .= strtr( $itemTemplate,
813 '$key' => htmlspecialchars( $format ),
815 '$href' => $wgRequest->appendQuery( "feed=$format" )
819 return new CBTValue( $feeds, 'special dynamic' );
822 function is_userpage() {
823 list( $id, $ip ) = $this->getUserPageIdIp();
824 return new CBTValue( (string)($id ||
$ip), 'title' );
827 function is_ns_mediawiki() {
828 return new CBTValue( (string)$this->mTitle
->getNamespace() == NS_MEDIAWIKI
, 'title' );
831 function is_loggedin() {
833 return new CBTValue( (string)($wgUser->isLoggedIn()), 'loggedin' );
836 function nav_contributions() {
837 $url = $this->makeSpecialParamUrl( 'Contributions', '', '{title_userurl}' );
838 return new CBTValue( $url, array(), true );
841 function is_allowed( $right ) {
843 return new CBTValue( (string)$wgUser->isAllowed( $right ), 'user' );
846 function nav_blockip() {
847 $url = $this->makeSpecialParamUrl( 'Blockip', '', '{title_userurl}' );
848 return new CBTValue( $url, array(), true );
851 function nav_emailuser() {
852 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
853 if ( !$wgEnableEmail ||
!$wgEnableUserEmail ) return '';
855 $url = $this->makeSpecialParamUrl( 'Emailuser', '', '{title_userurl}' );
856 return new CBTValue( $url, array(), true );
859 function nav_upload() {
860 global $wgEnableUploads, $wgUploadNavigationUrl;
861 if ( !$wgEnableUploads ) {
863 } elseif ( $wgUploadNavigationUrl ) {
864 return $wgUploadNavigationUrl;
866 return $this->makeSpecialUrl('Upload');
870 function nav_specialpages() {
871 return $this->makeSpecialUrl('Specialpages');
874 function nav_print() {
875 global $wgRequest, $wgArticle;
876 $action = $this->getAction();
878 if( $this->mTitle
->getNamespace() !== NS_SPECIAL
879 && ($action == '' ||
$action == 'view' ||
$action == 'purge' ) )
881 $revid = $wgArticle->getLatest();
883 $url = $wgRequest->appendQuery( 'printable=yes' );
886 return new CBTValue( $url, array( 'nonview dynamic', 'title' ) );
889 function nav_permalink() {
890 $url = (string)$this->getPermalink();
891 return new CBTValue( $url, 'dynamic' );
894 function nav_trackbacklink() {
895 global $wgUseTrackbacks;
896 if ( !$wgUseTrackbacks ) return '';
898 return new CBTValue( $this->mTitle
->trackbackURL(), 'title' );
901 function is_permalink() {
902 return new CBTValue( (string)($this->getPermalink() === false), 'nonview dynamic' );
905 function toolboxend() {
906 // This is where the MonoBookTemplateToolboxEnd hook went in the old skin
910 function language_urls( $outer, $inner ) {
911 global $wgHideInterlanguageLinks, $wgOut, $wgContLang;
912 if ( $wgHideInterlanguageLinks ) return '';
914 $links = $wgOut->getLanguageLinks();
916 if ( count( $links ) ) {
917 foreach( $links as $l ) {
918 $tmp = explode( ':', $l, 2 );
919 $nt = Title
::newFromText( $l );
922 '$class' => htmlspecialchars( 'interwiki-' . $tmp[0] ),
923 '$href' => htmlspecialchars( $nt->getFullURL() ),
924 '$text' => ($wgContLang->getLanguageName( $nt->getInterwiki() ) != ''?
925 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
929 $s = str_replace( '$body', $s, $outer );
931 return new CBTValue( $s, 'dynamic' );
934 function poweredbyico() { return $this->getPoweredBy(); }
935 function copyrightico() { return $this->getCopyrightIcon(); }
938 global $wgMaxCredits;
939 if ( $wgMaxCredits ) return '';
941 if ( $this->isCurrentArticleView() ) {
942 $s = $this->lastModified();
946 return new CBTValue( $s, 'dynamic' );
949 function viewcount() {
950 global $wgDisableCounters;
951 if ( $wgDisableCounters ) return '';
953 global $wgLang, $wgArticle;
954 if ( is_object( $wgArticle ) ) {
955 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
957 $viewcount = wfMsg( "viewcount", $viewcount );
964 return new CBTValue( $viewcount, 'dynamic' );
967 function numberofwatchingusers() {
968 global $wgPageShowWatchingUsers;
969 if ( !$wgPageShowWatchingUsers ) return '';
971 $dbr =& wfGetDB( DB_SLAVE
);
972 extract( $dbr->tableNames( 'watchlist' ) );
973 $sql = "SELECT COUNT(*) AS n FROM $watchlist
974 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
975 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
976 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
977 $row = $dbr->fetchObject( $res );
980 $s = wfMsg('number_of_watching_users_pageview', $num);
984 return new CBTValue( $s, 'dynamic' );
988 global $wgMaxCredits;
989 if ( !$wgMaxCredits ) return '';
991 if ( $this->isCurrentArticleView() ) {
992 require_once("Credits.php");
993 global $wgArticle, $wgShowCreditsIfMax;
994 $credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
998 return new CBTValue( $credits, 'view dynamic' );
1001 function normalcopyright() {
1002 return $this->getCopyright( 'normal' );
1005 function historycopyright() {
1006 return $this->getCopyright( 'history' );
1009 function is_currentview() {
1011 return new CBTValue( (string)$this->isCurrentArticleView(), 'view' );
1014 function usehistorycopyright() {
1016 if ( wfMsgForContent( 'history_copyright' ) == '-' ) return '';
1018 $oldid = $this->getOldId();
1019 $diff = $this->getDiff();
1020 $use = (string)(!is_null( $oldid ) && is_null( $diff ));
1021 return new CBTValue( $use, 'nonview dynamic' );
1024 function privacy() {
1025 return new CBTValue( $this->privacyLink(), 'lang' );
1028 return new CBTValue( $this->aboutLink(), 'lang' );
1030 function disclaimer() {
1031 return new CBTValue( $this->disclaimerLink(), 'lang' );
1033 function tagline() {
1034 # A reference to this tag existed in the old MonoBook.php, but the
1035 # template data wasn't set anywhere
1038 function reporttime() {
1039 return new CBTValue( $this->mOut
->reportTime(), 'dynamic' );
1042 function msg( $name ) {
1043 return new CBTValue( wfMsg( $name ), 'lang' );
1046 function fallbackmsg( $name, $fallback ) {
1047 $text = wfMsg( $name );
1048 if ( wfEmptyMsg( $name, $text ) ) {
1051 return new CBTValue( $text, 'lang' );
1054 /******************************************************
1055 * Utility functions *
1056 ******************************************************/
1058 /** Return true if this request is a valid, secure CSS preview */
1059 function isCssPreview() {
1060 if ( !isset( $this->mCssPreview
) ) {
1061 global $wgRequest, $wgAllowUserCss, $wgUser;
1062 $this->mCssPreview
=
1064 $wgUser->isLoggedIn() &&
1065 $this->mTitle
->isCssSubpage() &&
1066 $this->userCanPreview( $this->getAction() );
1068 return $this->mCssPreview
;
1071 /** Return true if this request is a valid, secure JS preview */
1072 function isJsPreview() {
1073 if ( !isset( $this->mJsPreview
) ) {
1074 global $wgRequest, $wgAllowUserJs, $wgUser;
1077 $wgUser->isLoggedIn() &&
1078 $this->mTitle
->isJsSubpage() &&
1079 $this->userCanPreview( $this->getAction() );
1081 return $this->mJsPreview
;
1084 /** Get the title of the $wgUser's user page */
1085 function getUserPageTitle() {
1086 if ( !isset( $this->mUserPageTitle
) ) {
1088 $this->mUserPageTitle
= $wgUser->getUserPage();
1090 return $this->mUserPageTitle
;
1093 /** Get the text of the user page title */
1094 function getUserPageText() {
1095 if ( !isset( $this->mUserPageText
) ) {
1096 $userPage = $this->getUserPageTitle();
1097 $this->mUserPageText
= $userPage->getPrefixedText();
1099 return $this->mUserPageText
;
1102 /** Make an HTML element for a stylesheet link */
1103 function makeStylesheetLink( $url ) {
1104 return '<link rel="stylesheet" type="text/css" href="' . htmlspecialchars( $url ) . "\"/>";
1107 /** Make an XHTML element for inline CSS */
1108 function makeStylesheetCdata( $style ) {
1109 return "<style type=\"text/css\"> /*<![CDATA[*/ {$style} /*]]>*/ </style>";
1112 /** Get the edit URL for this page */
1113 function getEditUrl() {
1114 if ( !isset( $this->mEditUrl
) ) {
1115 $this->mEditUrl
= $this->mTitle
->getLocalUrl( $this->editUrlOptions() );
1117 return $this->mEditUrl
;
1120 /** Get the prefixed DB key for this page */
1121 function getThisPDBK() {
1122 if ( !isset( $this->mThisPDBK
) ) {
1123 $this->mThisPDBK
= $this->mTitle
->getPrefixedDbKey();
1125 return $this->mThisPDBK
;
1128 function getThisTitleUrlForm() {
1129 if ( !isset( $this->mThisTitleUrlForm
) ) {
1130 $this->mThisTitleUrlForm
= $this->mTitle
->getPrefixedURL();
1132 return $this->mThisTitleUrlForm
;
1136 * If the current page is a user page, get the user's ID and IP. Otherwise return array(0,false)
1138 function getUserPageIdIp() {
1139 if ( !isset( $this->mUserPageId
) ) {
1140 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
1141 $this->mUserPageId
= User
::idFromName($this->mTitle
->getText());
1142 $this->mUserPageIp
= User
::isIP($this->mTitle
->getText());
1144 $this->mUserPageId
= 0;
1145 $this->mUserPageIp
= false;
1148 return array( $this->mUserPageId
, $this->mUserPageIp
);
1152 * Returns a permalink URL, or false if the current page is already a
1153 * permalink, or blank if a permalink shouldn't be displayed
1155 function getPermalink() {
1156 if ( !isset( $this->mPermalink
) ) {
1157 global $wgRequest, $wgArticle;
1158 $action = $this->getAction();
1159 $oldid = $this->getOldId();
1161 if( $this->mTitle
->getNamespace() !== NS_SPECIAL
1162 && $this->mTitle
->getArticleId() != 0
1163 && ($action == '' ||
$action == 'view' ||
$action == 'purge' ) )
1166 $revid = $wgArticle->getLatest();
1167 $url = $this->mTitle
->getLocalURL( "oldid=$revid" );
1179 * Returns true if the current page is an article, not a special page,
1180 * and we are viewing a revision, not a diff
1182 function isArticleView() {
1183 global $wgOut, $wgArticle, $wgRequest;
1184 if ( !isset( $this->mIsArticleView
) ) {
1185 $oldid = $this->getOldId();
1186 $diff = $this->getDiff();
1187 $this->mIsArticleView
= $wgOut->isArticle() and
1188 (!is_null( $oldid ) or is_null( $diff )) and 0 != $wgArticle->getID();
1190 return $this->mIsArticleView
;
1193 function isCurrentArticleView() {
1194 if ( !isset( $this->mIsCurrentArticleView
) ) {
1195 global $wgOut, $wgArticle, $wgRequest;
1196 $oldid = $this->getOldId();
1197 $this->mIsCurrentArticleView
= $wgOut->isArticle() && is_null( $oldid ) && 0 != $wgArticle->getID();
1199 return $this->mIsCurrentArticleView
;
1204 * Return true if the current page is editable; if edit section on right
1205 * click should be enabled.
1207 function isEditable() {
1209 $action = $this->getAction();
1210 return ($this->mTitle
->getNamespace() != NS_SPECIAL
and !($action == 'edit' or $action == 'submit'));
1213 /** Return true if the user is logged in */
1214 function isLoggedIn() {
1216 return $wgUser->isLoggedIn();
1219 /** Get the local URL of the current page */
1220 function getPageUrl() {
1221 if ( !isset( $this->mPageUrl
) ) {
1222 $this->mPageUrl
= $this->mTitle
->getLocalURL();
1224 return $this->mPageUrl
;
1227 /** Make a link to a title using a template */
1228 function makeTemplateLink( $template, $key, $title, $text ) {
1229 $url = $title->getLocalUrl();
1230 return strtr( $template,
1233 '$classactive' => ($url == $this->getPageUrl()) ?
'class="active"' : '',
1234 '$class' => $title->getArticleID() == 0 ?
'class="new"' : '',
1235 '$href' => htmlspecialchars( $url ),
1240 /** Make a link to a URL using a template */
1241 function makeTemplateLinkUrl( $template, $key, $url, $text ) {
1242 return strtr( $template,
1245 '$classactive' => ($url == $this->getPageUrl()) ?
'class="active"' : '',
1247 '$href' => htmlspecialchars( $url ),
1252 /** Make a link to a special page using a template */
1253 function makeSpecialTemplateLink( $template, $key, $specialName, $text, $query = '' ) {
1254 $url = $this->makeSpecialUrl( $specialName, $query );
1255 // Ignore the query when comparing
1256 $active = ($this->mTitle
->getNamespace() == NS_SPECIAL
&& $this->mTitle
->getDBkey() == $specialName);
1257 return strtr( $template,
1260 '$classactive' => $active ?
'class="active"' : '',
1262 '$href' => htmlspecialchars( $url ),
1267 function loadRequestValues() {
1269 $this->mAction
= $wgRequest->getText( 'action' );
1270 $this->mOldId
= $wgRequest->getVal( 'oldid' );
1271 $this->mDiff
= $wgRequest->getVal( 'diff' );
1272 $this->mSection
= $wgRequest->getVal( 'section' );
1273 $this->mSearch
= $wgRequest->getVal( 'search' );
1274 $this->mRequestValuesLoaded
= true;
1279 /** Get the action parameter of the request */
1280 function getAction() {
1281 if ( !isset( $this->mRequestValuesLoaded
) ) {
1282 $this->loadRequestValues();
1284 return $this->mAction
;
1287 /** Get the oldid parameter */
1288 function getOldId() {
1289 if ( !isset( $this->mRequestValuesLoaded
) ) {
1290 $this->loadRequestValues();
1292 return $this->mOldId
;
1295 /** Get the diff parameter */
1296 function getDiff() {
1297 if ( !isset( $this->mRequestValuesLoaded
) ) {
1298 $this->loadRequestValues();
1300 return $this->mDiff
;
1303 function getSection() {
1304 if ( !isset( $this->mRequestValuesLoaded
) ) {
1305 $this->loadRequestValues();
1307 return $this->mSection
;
1310 function getSearch() {
1311 if ( !isset( $this->mRequestValuesLoaded
) ) {
1312 $this->loadRequestValues();
1314 return $this->mSearch
;
1317 /** Make a special page URL of the form [[Special:Somepage/{title_urlform}]] */
1318 function makeSpecialParamUrl( $name, $query = '', $param = '{title_urlform}' ) {
1319 // Abuse makeTitle's lax validity checking to slip a control character into the URL
1320 $title = Title
::makeTitle( NS_SPECIAL
, "$name/\x1a" );
1321 $url = templateEscape( $title->getLocalURL( $query ) );
1322 // Now replace it with the parameter
1323 return str_replace( '%1A', $param, $url );
1326 function getSubjectPage() {
1327 if ( !isset( $this->mSubjectPage
) ) {
1328 $this->mSubjectPage
= $this->mTitle
->getSubjectPage();
1330 return $this->mSubjectPage
;
1333 function getTalkPage() {
1334 if ( !isset( $this->mTalkPage
) ) {
1335 $this->mTalkPage
= $this->mTitle
->getTalkPage();
1337 return $this->mTalkPage
;