ca2c314a9ce6cafcfe2b26f1406b97dfc5f5ce4b
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 * The main thing that's missing is cache invalidation, on change of:
19 * * source code and configuration files
21 * The other thing is that lots of dependencies that are declared in the callbacks
22 * are not intelligently handled. There's some room for improvement there.
24 * The class is derived from SkinTemplate, but that's only temporary. Eventually
25 * it'll be derived from Skin, and I've avoided using SkinTemplate functions as
26 * much as possible. In fact, the only SkinTemplate dependencies I know of at the
27 * moment are the functions to generate the gen=css and gen=js files.
30 class SkinMonoBookCBT
extends SkinTemplate
{
32 var $mStyleName = 'monobook';
33 var $mCompiling = false;
35 /******************************************************
37 ******************************************************/
39 /** Execute the template and write out the result */
40 function outputPage( &$out ) {
41 echo $this->execute( $out );
44 function execute( &$out ) {
45 global $wgTitle, $wgStyleDirectory, $wgParserCacheType;
46 $fname = 'SkinMonoBookCBT::execute';
47 wfProfileIn( $fname );
48 wfProfileIn( "$fname-setup" );
49 Skin
::initPage( $out );
52 $this->mTitle
=& $wgTitle;
54 $sourceFile = "$wgStyleDirectory/MonoBook.tpl";
56 wfProfileOut( "$fname-setup" );
58 if ( $wgParserCacheType == CACHE_NONE
) {
59 $template = file_get_contents( $sourceFile );
60 $text = $this->executeTemplate( $template );
62 $compiled = $this->getCompiledTemplate( $sourceFile );
64 wfProfileIn( "$fname-eval" );
65 $text = eval( $compiled );
66 wfProfileOut( "$fname-eval" );
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 $ret = $compiler->compile();
132 if ( $ret !== true ) {
136 $php = $compiler->generatePHP( '$this' );
138 $parserMemc->set( $cacheKey, $php, 3600 );
140 wfProfileOut( $fname );
144 function executeTemplate( $template ) {
145 $fname = 'SkinMonoBookCBT::executeTemplate';
146 wfProfileIn( $fname );
147 $tp = new CBTProcessor( $template, $this );
148 $this->mCompiling
= true;
149 $text = $tp->execute();
150 $this->mCompiling
= false;
151 wfProfileOut( $fname );
155 /******************************************************
157 ******************************************************/
159 function lang() { return $GLOBALS['wgContLanguageCode']; }
163 return $wgContLang->isRTL() ?
'rtl' : 'ltr';
166 function mimetype() { return $GLOBALS['wgMimeType']; }
167 function charset() { return $GLOBALS['wgOutputEncoding']; }
168 function headlinks() {
169 return cbt_value( $this->mOut
->getHeadLinks(), 'dynamic' );
171 function headscripts() {
172 return cbt_value( $this->mOut
->getScript(), 'dynamic' );
175 function pagetitle() {
176 return cbt_value( $this->mOut
->getHTMLTitle(), array( 'title', 'lang' ) );
179 function stylepath() { return $GLOBALS['wgStylePath']; }
180 function stylename() { return $this->mStyleName
; }
182 function notprintable() {
184 return cbt_value( !$wgRequest->getBool( 'printable' ), 'nonview dynamic' );
187 function jsmimetype() { return $GLOBALS['wgJsMimeType']; }
189 function jsvarurl() {
190 global $wgUseSiteJs, $wgUser;
191 if ( !$wgUseSiteJs ) return '';
193 if ( $wgUser->isLoggedIn() ) {
194 $url = $this->makeUrl('-','action=raw&smaxage=0&gen=js');
196 $url = $this->makeUrl('-','action=raw&gen=js');
198 return cbt_value( $url, 'loggedin' );
205 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
207 // Unknown dependencies
208 return cbt_value( $out, 'dynamic' );
212 if ( $this->isCssPreview() ) {
214 $usercss = $this->makeStylesheetCdata( $wgRequest->getText('wpTextbox1') );
216 $usercss = $this->makeStylesheetLink( $this->makeUrl($this->getUserPageText() .
217 '/'.$this->mStyleName
.'.css', 'action=raw&ctype=text/css' ) );
220 // Dynamic when not an ordinary page view, also depends on the username
221 return cbt_value( $usercss, array( 'nonview dynamic', 'user' ) );
225 global $wgUseSiteCss;
226 if ( !$wgUseSiteCss ) {
230 global $wgSquidMaxage, $wgContLang, $wgStylePath;
232 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
235 if ( $wgContLang->isRTL() ) {
236 $sitecss .= $this->makeStylesheetLink( $wgStylePath . '/' . $this->mStyleName
. '/rtl.css' ) . "\n";
239 $sitecss .= $this->makeStylesheetLink( $this->makeNSUrl('Common.css', $query, NS_MEDIAWIKI
) ) . "\n";
240 $sitecss .= $this->makeStylesheetLink( $this->makeNSUrl(
241 ucfirst($this->mStyleName
) . '.css', $query, NS_MEDIAWIKI
) ) . "\n";
248 global $wgUseSiteCss;
249 if ( !$wgUseSiteCss ) return '';
251 global $wgSquidMaxage, $wgUser, $wgAllowUserCss;
252 if ( $this->isCssPreview() ) {
253 $siteargs = '&smaxage=0&maxage=0';
255 $siteargs = '&maxage=' . $wgSquidMaxage;
257 if ( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
258 $siteargs .= '&ts={user_touched}';
264 $link = $this->makeStylesheetLink( $this->makeUrl('-','action=raw&gen=css' . $siteargs) ) . "\n";
266 if ( $wgAllowUserCss ) {
271 return cbt_value( $link, $deps, $isTemplate );
274 function user_touched() {
276 return cbt_value( $wgUser->mTouched
, 'dynamic' );
280 global $wgAllowUserJs, $wgJsMimeType;
281 if ( !$wgAllowUserJs ) return '';
283 if ( $this->isJsPreview() ) {
286 $url = $this->makeUrl($this->getUserPageText().'/'.$this->mStyleName
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
288 return cbt_value( $url, array( 'nonview dynamic', 'user' ) );
291 function userjsprev() {
292 global $wgAllowUserJs, $wgRequest;
293 if ( !$wgAllowUserJs ) return '';
294 if ( $this->isJsPreview() ) {
295 $js = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
299 return cbt_value( $js, array( 'nonview dynamic' ) );
302 function trackbackhtml() {
303 global $wgUseTrackbacks;
304 if ( !$wgUseTrackbacks ) return '';
306 if ( $this->mOut
->isArticleRelated() ) {
307 $tb = $this->mTitle
->trackbackRDF();
311 return cbt_value( $tb, 'dynamic' );
314 function body_ondblclick() {
316 if( $this->isEditable() && $wgUser->getOption("editondblclick") ) {
317 $js = 'document.location = "' . $this->getEditUrl() .'";';
322 if ( User
::getDefaultOption('editondblclick') ) {
323 return cbt_value( $js, 'user', 'title' );
325 // Optimise away for logged-out users
326 return cbt_value( $js, 'loggedin dynamic' );
330 function body_onload() {
332 if ( $this->isEditable() && $wgUser->getOption( 'editsectiononrightclick' ) ) {
333 $js = 'setupRightClickEdit()';
337 return cbt_value( $js, 'loggedin dynamic' );
341 return cbt_value( 'ns-' . $this->mTitle
->getNamespace(), 'title' );
344 function sitenotice() {
345 // Perhaps this could be given special dependencies using our knowledge of what
346 // wfGetSiteNotice() depends on.
347 return cbt_value( wfGetSiteNotice(), 'dynamic' );
351 return cbt_value( $this->mOut
->getPageTitle(), array( 'title', 'lang' ) );
354 function title_urlform() {
355 return cbt_value( $this->getThisTitleUrlForm(), 'title' );
358 function title_userurl() {
359 return cbt_value( urlencode( $this->mTitle
->getDBkey() ), 'title' );
362 function subtitle() {
363 $subpagestr = $this->subPageSubtitle();
364 if ( !empty( $subpagestr ) ) {
365 $s = '<span class="subpages">'.$subpagestr.'</span>'.$this->mOut
->getSubtitle();
367 $s = $this->mOut
->getSubtitle();
369 return cbt_value( $s, array( 'title', 'nonview dynamic' ) );
372 function undelete() {
373 return cbt_value( $this->getUndeleteLink(), array( 'title', 'lang' ) );
377 global $wgUser, $wgDBname;
378 $newtalks = $wgUser->getNewMessageLinks();
380 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === $wgDBname) {
381 $usertitle = $this->getUserPageTitle();
382 $usertalktitle = $usertitle->getTalkPage();
383 if( !$usertalktitle->equals( $this->mTitle
) ) {
384 $ntl = wfMsg( 'youhavenewmessages',
385 $this->makeKnownLinkObj(
387 wfMsgHtml( 'newmessageslink' ),
390 $this->makeKnownLinkObj(
392 wfMsgHtml( 'newmessagesdifflink' ),
397 $this->mOut
->setSquidMaxage(0);
399 } else if (count($newtalks)) {
400 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
402 foreach ($newtalks as $newtalk) {
403 $msgs[] = wfElement("a",
404 array('href' => $newtalk["link"]), $newtalk["wiki"]);
406 $parts = implode($sep, $msgs);
407 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
408 $this->mOut
->setSquidMaxage(0);
412 return cbt_value( $ntl, 'dynamic' );
415 function showjumplinks() {
417 return cbt_value( $wgUser->getOption( 'showjumplinks' ) ?
'true' : '', 'user' );
420 function bodytext() {
421 return cbt_value( $this->mOut
->getHTML(), 'dynamic' );
424 function catlinks() {
425 return cbt_value( $this->getCategories(), 'dynamic' );
428 function extratabs( $itemTemplate ) {
429 global $wgContLang, $wgDisableLangConversion;
431 $etpl = cbt_escape( $itemTemplate );
433 /* show links to different language variants */
434 $variants = $wgContLang->getVariants();
436 if ( !$wgDisableLangConversion && count( $wgContLang->getVariants() ) > 1 ) {
438 foreach ( $variants as $code ) {
439 $name = $wgContLang->getVariantname( $code );
440 if ( $name == 'disable' ) {
443 $code = cbt_escape( $code );
444 $name = cbt_escape( $name );
445 $s .= "{ca_variant {{$code}} {{$name}} {{$vcount}} {{$etpl}}}\n";
449 return cbt_value( $s, array(), true );
452 function is_special() { return cbt_value( $this->mTitle
->getNamespace() == NS_SPECIAL
, 'title' ); }
453 function can_edit() { return cbt_value( (string)($this->mTitle
->userCanEdit()), 'dynamic' ); }
454 function can_move() { return cbt_value( (string)($this->mTitle
->userCanMove()), 'dynamic' ); }
455 function is_talk() { return cbt_value( (string)($this->mTitle
->isTalkPage()), 'title' ); }
456 function is_protected() { return cbt_value( (string)$this->mTitle
->isProtected(), 'dynamic' ); }
457 function nskey() { return cbt_value( $this->mTitle
->getNamespaceKey(), 'title' ); }
459 function request_url() {
461 return cbt_value( $wgRequest->getRequestURL(), 'dynamic' );
464 function subject_url() {
465 $title = $this->getSubjectPage();
466 if ( $title->exists() ) {
467 $url = $title->getLocalUrl();
469 $url = $title->getLocalUrl( 'action=edit' );
471 return cbt_value( $url, 'title' );
474 function talk_url() {
475 $title = $this->getTalkPage();
476 if ( $title->exists() ) {
477 $url = $title->getLocalUrl();
479 $url = $title->getLocalUrl( 'action=edit' );
481 return cbt_value( $url, 'title' );
484 function edit_url() {
485 return cbt_value( $this->getEditUrl(), array( 'title', 'nonview dynamic' ) );
488 function move_url() {
489 return cbt_value( $this->makeSpecialParamUrl( 'Movepage' ), array(), true );
492 function localurl( $query ) {
493 return cbt_value( $this->mTitle
->getLocalURL( $query ), 'title' );
496 function selecttab( $tab, $extraclass = '' ) {
497 if ( !isset( $this->mSelectedTab
) ) {
498 $prevent_active_tabs = false ;
499 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$preventActiveTabs ) );
504 'history' => 'history',
505 'protect' => 'protect',
506 'unprotect' => 'protect',
507 'delete' => 'delete',
509 'unwatch' => 'watch',
511 if ( $preventActiveTabs ) {
512 $this->mSelectedTab
= false;
514 $action = $this->getAction();
515 $section = $this->getSection();
517 if ( isset( $actionTabs[$action] ) ) {
518 $this->mSelectedTab
= $actionTabs[$action];
520 if ( $this->mSelectedTab
== 'edit' && $section == 'new' ) {
521 $this->mSelectedTab
= 'addsection';
523 } elseif ( $this->mTitle
->isTalkPage() ) {
524 $this->mSelectedTab
= 'talk';
526 $this->mSelectedTab
= 'subject';
531 if ( $this->mSelectedTab
== $tab ) {
532 $s = 'class="selected ' . htmlspecialchars( $extraclass ) . '"';
534 $s = 'class="' . htmlspecialchars( $extraclass ) . '"';
537 if ( $this->mSelectedTab
== $tab ) {
538 $s = 'class="selected"';
543 return cbt_value( $s, array( 'nonview dynamic', 'title' ) );
546 function subject_newclass() {
547 $title = $this->getSubjectPage();
548 $class = $title->exists() ?
'' : 'new';
549 return cbt_value( $class, 'dynamic' );
552 function talk_newclass() {
553 $title = $this->getTalkPage();
554 $class = $title->exists() ?
'' : 'new';
555 return cbt_value( $class, 'dynamic' );
558 function ca_variant( $code, $name, $index, $template ) {
560 $selected = ($code == $wgContLang->getPreferredVariant());
561 $action = $this->getAction();
564 $actstr = 'action=' . $action . '&';
565 $s = strtr( $template, array(
566 '$id' => htmlspecialchars( 'varlang-' . $index ),
567 '$class' => $selected ?
'class="selected"' : '',
569 '$href' => htmlspecialchars( $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code ) )
571 return cbt_value( $s, 'dynamic' );
574 function is_watching() {
575 return cbt_value( (string)$this->mTitle
->userIsWatching(), array( 'dynamic' ) );
579 function personal_urls( $itemTemplate ) {
580 global $wgShowIPinHeader, $wgContLang;
582 # Split this function up into many small functions, to obtain the
583 # best specificity in the dependencies of each one. The template below
584 # has no dependencies, so its generation, and any static subfunctions,
585 # can be optimised away.
586 $etpl = cbt_escape( $itemTemplate );
590 {preferences {{$etpl}}}
591 {watchlist {{$etpl}}}
592 {mycontris {{$etpl}}}
596 if ( $wgShowIPinHeader ) {
598 {anonuserpage {{$etpl}}}
600 {anonlogin {{$etpl}}}
603 $s .= "{login {{$etpl}}}\n";
606 return cbt_value( $s, array(), true /*this is a template*/ );
609 function userpage( $itemTemplate ) {
611 if ( $this->isLoggedIn() ) {
612 $userPage = $this->getUserPageTitle();
613 $s = $this->makeTemplateLink( $itemTemplate, 'userpage', $userPage, $wgUser->getName() );
617 return cbt_value( $s, 'user' );
620 function mytalk( $itemTemplate ) {
622 if ( $this->isLoggedIn() ) {
623 $userPage = $this->getUserPageTitle();
624 $talkPage = $userPage->getTalkPage();
625 $s = $this->makeTemplateLink( $itemTemplate, 'mytalk', $talkPage, wfMsg('mytalk') );
629 return cbt_value( $s, 'user' );
632 function preferences( $itemTemplate ) {
633 if ( $this->isLoggedIn() ) {
634 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'preferences',
635 'Preferences', wfMsg( 'preferences' ) );
639 return cbt_value( $s, array( 'loggedin', 'lang' ) );
642 function watchlist( $itemTemplate ) {
643 if ( $this->isLoggedIn() ) {
644 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'watchlist',
645 'Watchlist', wfMsg( 'watchlist' ) );
649 return cbt_value( $s, array( 'loggedin', 'lang' ) );
652 function mycontris( $itemTemplate ) {
653 if ( $this->isLoggedIn() ) {
655 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'mycontris',
656 "Contributions/" . $wgUser->getTitleKey(), wfMsg('mycontris') );
660 return cbt_value( $s, 'user' );
663 function logout( $itemTemplate ) {
664 if ( $this->isLoggedIn() ) {
665 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'logout',
666 'Userlogout', wfMsg( 'userlogout' ),
667 $this->mTitle
->getNamespace() === NS_SPECIAL
&& $this->mTitle
->getText() === 'Preferences'
668 ?
'' : "returnto=" . $this->mTitle
->getPrefixedURL() );
672 return cbt_value( $s, 'loggedin dynamic' );
675 function anonuserpage( $itemTemplate ) {
676 if ( $this->isLoggedIn() ) {
680 $userPage = $this->getUserPageTitle();
681 $s = $this->makeTemplateLink( $itemTemplate, 'userpage', $userPage, $wgUser->getName() );
683 return cbt_value( $s, '!loggedin dynamic' );
686 function anontalk( $itemTemplate ) {
687 if ( $this->isLoggedIn() ) {
690 $userPage = $this->getUserPageTitle();
691 $talkPage = $userPage->getTalkPage();
692 $s = $this->makeTemplateLink( $itemTemplate, 'mytalk', $talkPage, wfMsg('anontalk') );
694 return cbt_value( $s, '!loggedin dynamic' );
697 function anonlogin( $itemTemplate ) {
698 if ( $this->isLoggedIn() ) {
701 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'anonlogin', 'Userlogin',
702 wfMsg( 'userlogin' ), 'returnto=' . urlencode( $this->getThisPDBK() ) );
704 return cbt_value( $s, '!loggedin dynamic' );
707 function login( $itemTemplate ) {
708 if ( $this->isLoggedIn() ) {
711 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'login', 'Userlogin',
712 wfMsg( 'userlogin' ), 'returnto=' . urlencode( $this->getThisPDBK() ) );
714 return cbt_value( $s, '!loggedin dynamic' );
717 function logopath() { return $GLOBALS['wgLogo']; }
718 function mainpage() { return $this->makeI18nUrl( 'mainpage' ); }
720 function sidebar( $startSection, $endSection, $innerTpl ) {
722 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
723 $firstSection = true;
724 foreach ($lines as $line) {
725 if (strpos($line, '*') !== 0)
727 if (strpos($line, '**') !== 0) {
728 $bar = trim($line, '* ');
729 $name = wfMsg( $bar );
730 if (wfEmptyMsg($bar, $name)) {
733 if ( $firstSection ) {
734 $firstSection = false;
738 $s .= strtr( $startSection,
740 '$bar' => htmlspecialchars( $bar ),
744 if (strpos($line, '|') !== false) { // sanity check
745 $line = explode( '|' , trim($line, '* '), 2 );
746 $link = wfMsgForContent( $line[0] );
749 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
751 if (wfEmptyMsg($line[0], $link))
753 $href = $this->makeInternalOrExternalUrl( $link );
755 $s .= strtr( $innerTpl,
757 '$text' => htmlspecialchars( $text ),
758 '$href' => htmlspecialchars( $href ),
759 '$id' => htmlspecialchars( 'n-' . strtr($line[1], ' ', '-') ),
765 if ( !$firstSection ) {
769 // Depends on user language only
770 return cbt_value( $s, 'lang' );
773 function searchaction() {
775 return $this->getSearchLink();
780 return cbt_value( trim( $this->getSearch() ), 'special dynamic' );
783 function notspecialpage() {
784 return cbt_value( $this->mTitle
->getNamespace() != NS_SPECIAL
, 'special' );
787 function nav_whatlinkshere() {
788 return cbt_value( $this->makeSpecialParamUrl('Whatlinkshere' ), array(), true );
791 function article_exists() {
792 return cbt_value( (string)($this->mTitle
->getArticleId() !== 0), 'title' );
795 function nav_recentchangeslinked() {
796 return cbt_value( $this->makeSpecialParamUrl('Recentchangeslinked' ), array(), true );
799 function feeds( $itemTemplate = '' ) {
800 if ( !$this->mOut
->isSyndicated() ) {
802 } elseif ( $itemTemplate == '' ) {
803 // boolean only required
807 global $wgFeedClasses, $wgRequest;
808 foreach( $wgFeedClasses as $format => $class ) {
809 $feeds .= strtr( $itemTemplate,
811 '$key' => htmlspecialchars( $format ),
813 '$href' => $wgRequest->appendQuery( "feed=$format" )
817 return cbt_value( $feeds, 'special dynamic' );
820 function is_userpage() {
821 list( $id, $ip ) = $this->getUserPageIdIp();
822 return cbt_value( (string)($id ||
$ip), 'title' );
825 function is_ns_mediawiki() {
826 return cbt_value( (string)$this->mTitle
->getNamespace() == NS_MEDIAWIKI
, 'title' );
829 function is_loggedin() {
831 return cbt_value( (string)($wgUser->isLoggedIn()), 'loggedin' );
834 function nav_contributions() {
835 $url = $this->makeSpecialParamUrl( 'Contributions', '', '{title_userurl}' );
836 return cbt_value( $url, array(), true );
839 function is_allowed( $right ) {
841 return cbt_value( (string)$wgUser->isAllowed( $right ), 'user' );
844 function nav_blockip() {
845 $url = $this->makeSpecialParamUrl( 'Blockip', '', '{title_userurl}' );
846 return cbt_value( $url, array(), true );
849 function nav_emailuser() {
850 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
851 if ( !$wgEnableEmail ||
!$wgEnableUserEmail ) return '';
853 $url = $this->makeSpecialParamUrl( 'Emailuser', '', '{title_userurl}' );
854 return cbt_value( $url, array(), true );
857 function nav_upload() {
858 global $wgEnableUploads, $wgUploadNavigationUrl;
859 if ( !$wgEnableUploads ) {
861 } elseif ( $wgUploadNavigationUrl ) {
862 return $wgUploadNavigationUrl;
864 return $this->makeSpecialUrl('Upload');
868 function nav_specialpages() {
869 return $this->makeSpecialUrl('Specialpages');
872 function nav_print() {
873 global $wgRequest, $wgArticle;
874 $action = $this->getAction();
876 if( $this->mTitle
->getNamespace() !== NS_SPECIAL
877 && ($action == '' ||
$action == 'view' ||
$action == 'purge' ) )
879 $revid = $wgArticle->getLatest();
881 $url = $wgRequest->appendQuery( 'printable=yes' );
884 return cbt_value( $url, array( 'nonview dynamic', 'title' ) );
887 function nav_permalink() {
888 $url = (string)$this->getPermalink();
889 return cbt_value( $url, 'dynamic' );
892 function nav_trackbacklink() {
893 global $wgUseTrackbacks;
894 if ( !$wgUseTrackbacks ) return '';
896 return cbt_value( $this->mTitle
->trackbackURL(), 'title' );
899 function is_permalink() {
900 return cbt_value( (string)($this->getPermalink() === false), 'nonview dynamic' );
903 function toolboxend() {
904 // This is where the MonoBookTemplateToolboxEnd hook went in the old skin
908 function language_urls( $outer, $inner ) {
909 global $wgHideInterlanguageLinks, $wgOut, $wgContLang;
910 if ( $wgHideInterlanguageLinks ) return '';
912 $links = $wgOut->getLanguageLinks();
914 if ( count( $links ) ) {
915 foreach( $links as $l ) {
916 $tmp = explode( ':', $l, 2 );
917 $nt = Title
::newFromText( $l );
920 '$class' => htmlspecialchars( 'interwiki-' . $tmp[0] ),
921 '$href' => htmlspecialchars( $nt->getFullURL() ),
922 '$text' => ($wgContLang->getLanguageName( $nt->getInterwiki() ) != ''?
923 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
927 $s = str_replace( '$body', $s, $outer );
929 return cbt_value( $s, 'dynamic' );
932 function poweredbyico() { return $this->getPoweredBy(); }
933 function copyrightico() { return $this->getCopyrightIcon(); }
936 global $wgMaxCredits;
937 if ( $wgMaxCredits ) return '';
939 if ( $this->isCurrentArticleView() ) {
940 $s = $this->lastModified();
944 return cbt_value( $s, 'dynamic' );
947 function viewcount() {
948 global $wgDisableCounters;
949 if ( $wgDisableCounters ) return '';
951 global $wgLang, $wgArticle;
952 if ( is_object( $wgArticle ) ) {
953 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
955 $viewcount = wfMsg( "viewcount", $viewcount );
962 return cbt_value( $viewcount, 'dynamic' );
965 function numberofwatchingusers() {
966 global $wgPageShowWatchingUsers;
967 if ( !$wgPageShowWatchingUsers ) return '';
969 $dbr =& wfGetDB( DB_SLAVE
);
970 extract( $dbr->tableNames( 'watchlist' ) );
971 $sql = "SELECT COUNT(*) AS n FROM $watchlist
972 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
973 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
974 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
975 $row = $dbr->fetchObject( $res );
978 $s = wfMsg('number_of_watching_users_pageview', $num);
982 return cbt_value( $s, 'dynamic' );
986 global $wgMaxCredits;
987 if ( !$wgMaxCredits ) return '';
989 if ( $this->isCurrentArticleView() ) {
990 require_once("Credits.php");
991 global $wgArticle, $wgShowCreditsIfMax;
992 $credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
996 return cbt_value( $credits, 'view dynamic' );
999 function normalcopyright() {
1000 return $this->getCopyright( 'normal' );
1003 function historycopyright() {
1004 return $this->getCopyright( 'history' );
1007 function is_currentview() {
1009 return cbt_value( (string)$this->isCurrentArticleView(), 'view' );
1012 function usehistorycopyright() {
1014 if ( wfMsgForContent( 'history_copyright' ) == '-' ) return '';
1016 $oldid = $this->getOldId();
1017 $diff = $this->getDiff();
1018 $use = (string)(!is_null( $oldid ) && is_null( $diff ));
1019 return cbt_value( $use, 'nonview dynamic' );
1022 function privacy() {
1023 return cbt_value( $this->privacyLink(), 'lang' );
1026 return cbt_value( $this->aboutLink(), 'lang' );
1028 function disclaimer() {
1029 return cbt_value( $this->disclaimerLink(), 'lang' );
1031 function tagline() {
1032 # A reference to this tag existed in the old MonoBook.php, but the
1033 # template data wasn't set anywhere
1036 function reporttime() {
1037 return cbt_value( $this->mOut
->reportTime(), 'dynamic' );
1040 function msg( $name ) {
1041 return cbt_value( wfMsg( $name ), 'lang' );
1044 function fallbackmsg( $name, $fallback ) {
1045 $text = wfMsg( $name );
1046 if ( wfEmptyMsg( $name, $text ) ) {
1049 return cbt_value( $text, 'lang' );
1052 /******************************************************
1053 * Utility functions *
1054 ******************************************************/
1056 /** Return true if this request is a valid, secure CSS preview */
1057 function isCssPreview() {
1058 if ( !isset( $this->mCssPreview
) ) {
1059 global $wgRequest, $wgAllowUserCss, $wgUser;
1060 $this->mCssPreview
=
1062 $wgUser->isLoggedIn() &&
1063 $this->mTitle
->isCssSubpage() &&
1064 $this->userCanPreview( $this->getAction() );
1066 return $this->mCssPreview
;
1069 /** Return true if this request is a valid, secure JS preview */
1070 function isJsPreview() {
1071 if ( !isset( $this->mJsPreview
) ) {
1072 global $wgRequest, $wgAllowUserJs, $wgUser;
1075 $wgUser->isLoggedIn() &&
1076 $this->mTitle
->isJsSubpage() &&
1077 $this->userCanPreview( $this->getAction() );
1079 return $this->mJsPreview
;
1082 /** Get the title of the $wgUser's user page */
1083 function getUserPageTitle() {
1084 if ( !isset( $this->mUserPageTitle
) ) {
1086 $this->mUserPageTitle
= $wgUser->getUserPage();
1088 return $this->mUserPageTitle
;
1091 /** Get the text of the user page title */
1092 function getUserPageText() {
1093 if ( !isset( $this->mUserPageText
) ) {
1094 $userPage = $this->getUserPageTitle();
1095 $this->mUserPageText
= $userPage->getPrefixedText();
1097 return $this->mUserPageText
;
1100 /** Make an HTML element for a stylesheet link */
1101 function makeStylesheetLink( $url ) {
1102 return '<link rel="stylesheet" type="text/css" href="' . htmlspecialchars( $url ) . "\"/>";
1105 /** Make an XHTML element for inline CSS */
1106 function makeStylesheetCdata( $style ) {
1107 return "<style type=\"text/css\"> /*<![CDATA[*/ {$style} /*]]>*/ </style>";
1110 /** Get the edit URL for this page */
1111 function getEditUrl() {
1112 if ( !isset( $this->mEditUrl
) ) {
1113 $this->mEditUrl
= $this->mTitle
->getLocalUrl( $this->editUrlOptions() );
1115 return $this->mEditUrl
;
1118 /** Get the prefixed DB key for this page */
1119 function getThisPDBK() {
1120 if ( !isset( $this->mThisPDBK
) ) {
1121 $this->mThisPDBK
= $this->mTitle
->getPrefixedDbKey();
1123 return $this->mThisPDBK
;
1126 function getThisTitleUrlForm() {
1127 if ( !isset( $this->mThisTitleUrlForm
) ) {
1128 $this->mThisTitleUrlForm
= $this->mTitle
->getPrefixedURL();
1130 return $this->mThisTitleUrlForm
;
1134 * If the current page is a user page, get the user's ID and IP. Otherwise return array(0,false)
1136 function getUserPageIdIp() {
1137 if ( !isset( $this->mUserPageId
) ) {
1138 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
1139 $this->mUserPageId
= User
::idFromName($this->mTitle
->getText());
1140 $this->mUserPageIp
= User
::isIP($this->mTitle
->getText());
1142 $this->mUserPageId
= 0;
1143 $this->mUserPageIp
= false;
1146 return array( $this->mUserPageId
, $this->mUserPageIp
);
1150 * Returns a permalink URL, or false if the current page is already a
1151 * permalink, or blank if a permalink shouldn't be displayed
1153 function getPermalink() {
1154 if ( !isset( $this->mPermalink
) ) {
1155 global $wgRequest, $wgArticle;
1156 $action = $this->getAction();
1157 $oldid = $this->getOldId();
1159 if( $this->mTitle
->getNamespace() !== NS_SPECIAL
1160 && $this->mTitle
->getArticleId() != 0
1161 && ($action == '' ||
$action == 'view' ||
$action == 'purge' ) )
1164 $revid = $wgArticle->getLatest();
1165 $url = $this->mTitle
->getLocalURL( "oldid=$revid" );
1177 * Returns true if the current page is an article, not a special page,
1178 * and we are viewing a revision, not a diff
1180 function isArticleView() {
1181 global $wgOut, $wgArticle, $wgRequest;
1182 if ( !isset( $this->mIsArticleView
) ) {
1183 $oldid = $this->getOldId();
1184 $diff = $this->getDiff();
1185 $this->mIsArticleView
= $wgOut->isArticle() and
1186 (!is_null( $oldid ) or is_null( $diff )) and 0 != $wgArticle->getID();
1188 return $this->mIsArticleView
;
1191 function isCurrentArticleView() {
1192 if ( !isset( $this->mIsCurrentArticleView
) ) {
1193 global $wgOut, $wgArticle, $wgRequest;
1194 $oldid = $this->getOldId();
1195 $this->mIsCurrentArticleView
= $wgOut->isArticle() && is_null( $oldid ) && 0 != $wgArticle->getID();
1197 return $this->mIsCurrentArticleView
;
1202 * Return true if the current page is editable; if edit section on right
1203 * click should be enabled.
1205 function isEditable() {
1207 $action = $this->getAction();
1208 return ($this->mTitle
->getNamespace() != NS_SPECIAL
and !($action == 'edit' or $action == 'submit'));
1211 /** Return true if the user is logged in */
1212 function isLoggedIn() {
1214 return $wgUser->isLoggedIn();
1217 /** Get the local URL of the current page */
1218 function getPageUrl() {
1219 if ( !isset( $this->mPageUrl
) ) {
1220 $this->mPageUrl
= $this->mTitle
->getLocalURL();
1222 return $this->mPageUrl
;
1225 /** Make a link to a title using a template */
1226 function makeTemplateLink( $template, $key, $title, $text ) {
1227 $url = $title->getLocalUrl();
1228 return strtr( $template,
1231 '$classactive' => ($url == $this->getPageUrl()) ?
'class="active"' : '',
1232 '$class' => $title->getArticleID() == 0 ?
'class="new"' : '',
1233 '$href' => htmlspecialchars( $url ),
1238 /** Make a link to a URL using a template */
1239 function makeTemplateLinkUrl( $template, $key, $url, $text ) {
1240 return strtr( $template,
1243 '$classactive' => ($url == $this->getPageUrl()) ?
'class="active"' : '',
1245 '$href' => htmlspecialchars( $url ),
1250 /** Make a link to a special page using a template */
1251 function makeSpecialTemplateLink( $template, $key, $specialName, $text, $query = '' ) {
1252 $url = $this->makeSpecialUrl( $specialName, $query );
1253 // Ignore the query when comparing
1254 $active = ($this->mTitle
->getNamespace() == NS_SPECIAL
&& $this->mTitle
->getDBkey() == $specialName);
1255 return strtr( $template,
1258 '$classactive' => $active ?
'class="active"' : '',
1260 '$href' => htmlspecialchars( $url ),
1265 function loadRequestValues() {
1267 $this->mAction
= $wgRequest->getText( 'action' );
1268 $this->mOldId
= $wgRequest->getVal( 'oldid' );
1269 $this->mDiff
= $wgRequest->getVal( 'diff' );
1270 $this->mSection
= $wgRequest->getVal( 'section' );
1271 $this->mSearch
= $wgRequest->getVal( 'search' );
1272 $this->mRequestValuesLoaded
= true;
1277 /** Get the action parameter of the request */
1278 function getAction() {
1279 if ( !isset( $this->mRequestValuesLoaded
) ) {
1280 $this->loadRequestValues();
1282 return $this->mAction
;
1285 /** Get the oldid parameter */
1286 function getOldId() {
1287 if ( !isset( $this->mRequestValuesLoaded
) ) {
1288 $this->loadRequestValues();
1290 return $this->mOldId
;
1293 /** Get the diff parameter */
1294 function getDiff() {
1295 if ( !isset( $this->mRequestValuesLoaded
) ) {
1296 $this->loadRequestValues();
1298 return $this->mDiff
;
1301 function getSection() {
1302 if ( !isset( $this->mRequestValuesLoaded
) ) {
1303 $this->loadRequestValues();
1305 return $this->mSection
;
1308 function getSearch() {
1309 if ( !isset( $this->mRequestValuesLoaded
) ) {
1310 $this->loadRequestValues();
1312 return $this->mSearch
;
1315 /** Make a special page URL of the form [[Special:Somepage/{title_urlform}]] */
1316 function makeSpecialParamUrl( $name, $query = '', $param = '{title_urlform}' ) {
1317 // Abuse makeTitle's lax validity checking to slip a control character into the URL
1318 $title = Title
::makeTitle( NS_SPECIAL
, "$name/\x1a" );
1319 $url = cbt_escape( $title->getLocalURL( $query ) );
1320 // Now replace it with the parameter
1321 return str_replace( '%1A', $param, $url );
1324 function getSubjectPage() {
1325 if ( !isset( $this->mSubjectPage
) ) {
1326 $this->mSubjectPage
= $this->mTitle
->getSubjectPage();
1328 return $this->mSubjectPage
;
1331 function getTalkPage() {
1332 if ( !isset( $this->mTalkPage
) ) {
1333 $this->mTalkPage
= $this->mTitle
->getTalkPage();
1335 return $this->mTalkPage
;