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/CBTProcessor.php' );
8 require_once( dirname(__FILE__
) . '/../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.
29 * It assumes that $wgMemc is valid, if not, performance will be glacial as it will
30 * compile the skin on every invocation.
32 class SkinMonoBookCBT
extends SkinTemplate
{
34 var $mStyleName = 'monobook';
35 var $mCompiling = false;
37 /******************************************************
39 ******************************************************/
41 /** Execute the template and write out the result */
42 function outputPage( &$out ) {
43 echo $this->execute( $out );
46 function execute( &$out ) {
47 global $wgTitle, $wgStyleDirectory, $wgParserCacheType;
48 $fname = 'SkinMonoBookCBT::execute';
49 wfProfileIn( $fname );
50 wfProfileIn( "$fname-setup" );
51 Skin
::initPage( $out );
54 $this->mTitle
=& $wgTitle;
56 $sourceFile = "$wgStyleDirectory/MonoBook.tpl";
58 wfProfileOut( "$fname-setup" );
60 if ( $wgParserCacheType == CACHE_NONE
) {
61 $template = file_get_contents( $sourceFile );
62 $text = $this->executeTemplate( $template );
64 $compiled = $this->getCompiledTemplate( $sourceFile );
65 $text = $this->executeTemplate( $compiled );
67 wfProfileOut( $fname );
71 function getCompiledTemplate( $sourceFile ) {
72 global $wgDBname, $wgMemc, $wgRequest, $wgUser, $parserMemc;
73 $fname = 'SkinMonoBookCBT::getCompiledTemplate';
75 // Sandbox template execution
76 if ( $this->mCompiling
) {
80 wfProfileIn( $fname );
82 // Is the request an ordinary page view?
83 if ( $wgRequest->wasPosted() ||
84 count( array_diff( array_keys( $_GET ), array( 'title', 'useskin', 'recompile' ) ) ) != 0 )
91 // Per-user compiled template
92 // Put all logged-out users on the same cache key
93 $cacheKey = "$wgDBname:monobookcbt:$type:" . $wgUser->getId();
95 $recompile = $wgRequest->getVal( 'recompile' );
97 $compiled = $parserMemc->get( $cacheKey );
99 if ( $recompile ||
!$compiled ) {
100 $template = file_get_contents( $sourceFile );
102 $ignore = array( 'lang', 'loggedin', 'user' );
103 if ( $wgUser->isLoggedIn() ) {
104 $ignore[] = '!loggedin dynamic';
106 $ignore[] = 'loggedin dynamic';
108 if ( $type == 'view' ) {
109 $ignore[] = 'nonview dynamic';
111 $tp = new CBTProcessor( $template, $this, $ignore );
112 $this->mCompiling
= true;
113 $compiled = $tp->compile();
114 $this->mCompiling
= false;
115 if ( $tp->getLastError() ) {
116 // If there was a compile error, don't save the template
117 // Instead just print the error and exit
123 // This is done here instead of in CBTProcessor because we can be
124 // more sure it is safe here.
125 $compiled = preg_replace( '/^[ \t]+/m', '', $compiled );
126 $compiled = preg_replace( '/[\r\n]+/', "\n", $compiled );
127 $parserMemc->set( $cacheKey, $compiled, 3600 );
129 wfProfileOut( $fname );
133 function executeTemplate( $template ) {
134 $fname = 'SkinMonoBookCBT::executeTemplate';
135 wfProfileIn( $fname );
136 $tp = new CBTProcessor( $template, $this );
137 $this->mCompiling
= true;
138 $text = $tp->execute();
139 $this->mCompiling
= false;
140 wfProfileOut( $fname );
144 /******************************************************
146 ******************************************************/
148 function lang() { return $GLOBALS['wgContLanguageCode']; }
152 return $wgContLang->isRTL() ?
'rtl' : 'ltr';
155 function mimetype() { return $GLOBALS['wgMimeType']; }
156 function charset() { return $GLOBALS['wgOutputEncoding']; }
157 function headlinks() {
158 return new TplValue( $this->mOut
->getHeadLinks(), 'dynamic' );
160 function headscripts() {
161 return new TplValue( $this->mOut
->getScript(), 'dynamic' );
164 function pagetitle() {
165 return new TplValue( $this->mOut
->getHTMLTitle(), array( 'title', 'lang' ) );
168 function stylepath() { return $GLOBALS['wgStylePath']; }
169 function stylename() { return $this->mStyleName
; }
171 function notprintable() {
173 return new TplValue( !$wgRequest->getBool( 'printable' ), 'nonview dynamic' );
176 function jsmimetype() { return $GLOBALS['wgJsMimeType']; }
178 function jsvarurl() {
179 global $wgUseSiteJs, $wgUser;
180 if ( !$wgUseSiteJs ) return '';
182 if ( $wgUser->isLoggedIn() ) {
183 $url = $this->makeUrl('-','action=raw&smaxage=0&gen=js');
185 $url = $this->makeUrl('-','action=raw&gen=js');
187 return new TplValue( $url, 'loggedin' );
194 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
196 // Unknown dependencies
197 return new TplValue( $out, 'dynamic' );
201 if ( $this->isCssPreview() ) {
203 $usercss = $this->makeStylesheetCdata( $wgRequest->getText('wpTextbox1') );
205 $usercss = $this->makeStylesheetLink( $this->makeUrl($this->getUserPageText() .
206 '/'.$this->mStyleName
.'.css', 'action=raw&ctype=text/css' ) );
209 // Dynamic when not an ordinary page view, also depends on the username
210 return new TplValue( $usercss, array( 'nonview dynamic', 'user' ) );
214 global $wgUseSiteCss;
215 if ( !$wgUseSiteCss ) {
219 global $wgSquidMaxage, $wgContLang, $wgStylePath;
221 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
224 if ( $wgContLang->isRTL() ) {
225 $sitecss .= $this->makeStylesheetLink( $wgStylePath . '/' . $this->mStyleName
. '/rtl.css' ) . "\n";
228 $sitecss .= $this->makeStylesheetLink( $this->makeNSUrl('Common.css', $query, NS_MEDIAWIKI
) ) . "\n";
229 $sitecss .= $this->makeStylesheetLink( $this->makeNSUrl(
230 ucfirst($this->mStyleName
) . '.css', $query, NS_MEDIAWIKI
) ) . "\n";
237 global $wgUseSiteCss;
238 if ( !$wgUseSiteCss ) return '';
240 global $wgSquidMaxage, $wgUser, $wgAllowUserCss;
241 if ( $this->isCssPreview() ) {
242 $siteargs = '&smaxage=0&maxage=0';
244 $siteargs = '&maxage=' . $wgSquidMaxage;
246 if ( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
247 $siteargs .= '&ts={user_touched}';
253 $link = $this->makeStylesheetLink( $this->makeUrl('-','action=raw&gen=css' . $siteargs) ) . "\n";
255 if ( $wgAllowUserCss ) {
260 return new TplValue( $link, $deps, $isTemplate );
263 function user_touched() {
265 return new TplValue( $wgUser->mTouched
, 'dynamic' );
269 global $wgAllowUserJs, $wgJsMimeType;
270 if ( !$wgAllowUserJs ) return '';
272 if ( $this->isJsPreview() ) {
275 $url = $this->makeUrl($this->getUserPageText().'/'.$this->mStyleName
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
277 return new TplValue( $url, array( 'nonview dynamic', 'user' ) );
280 function userjsprev() {
281 global $wgAllowUserJs, $wgRequest;
282 if ( !$wgAllowUserJs ) return '';
283 if ( $this->isJsPreview() ) {
284 $js = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
288 return new TplValue( $js, array( 'nonview dynamic' ) );
291 function trackbackhtml() {
292 global $wgUseTrackbacks;
293 if ( !$wgUseTrackbacks ) return '';
295 if ( $this->mOut
->isArticleRelated() ) {
296 $tb = $this->mTitle
->trackbackRDF();
300 return new TplValue( $tb, 'dynamic' );
303 function body_ondblclick() {
305 if( $this->isEditable() && $wgUser->getOption("editondblclick") ) {
306 $js = 'document.location = "' . $this->getEditUrl() .'";';
311 if ( User
::getDefaultOption('editondblclick') ) {
312 return new TplValue( $js, 'user', 'title' );
314 // Optimise away for logged-out users
315 return new TplValue( $js, 'loggedin dynamic' );
319 function body_onload() {
321 if ( $this->isEditable() && $wgUser->getOption( 'editsectiononrightclick' ) ) {
322 $js = 'setupRightClickEdit()';
326 return new TplValue( $js, 'loggedin dynamic' );
330 return new TplValue( 'ns-' . $this->mTitle
->getNamespace(), 'title' );
333 function sitenotice() {
334 // Perhaps this could be given special dependencies using our knowledge of what
335 // wfGetSiteNotice() depends on.
336 return new TplValue( wfGetSiteNotice(), 'dynamic' );
340 return new TplValue( $this->mOut
->getPageTitle(), array( 'title', 'lang' ) );
343 function title_urlform() {
344 return new TplValue( $this->getThisTitleUrlForm(), 'title' );
347 function title_userurl() {
348 return new TplValue( urlencode( $this->mTitle
->getDBkey() ), 'title' );
351 function subtitle() {
352 $subpagestr = $this->subPageSubtitle();
353 if ( !empty( $subpagestr ) ) {
354 $s = '<span class="subpages">'.$subpagestr.'</span>'.$this->mOut
->getSubtitle();
356 $s = $this->mOut
->getSubtitle();
358 return new TplValue( $s, array( 'title', 'nonview dynamic' ) );
361 function undelete() {
362 return new TplValue( $this->getUndeleteLink(), array( 'title', 'lang' ) );
366 global $wgUser, $wgDBname;
367 $newtalks = $wgUser->getNewMessageLinks();
369 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === $wgDBname) {
370 $usertitle = $this->getUserPageTitle();
371 $usertalktitle = $usertitle->getTalkPage();
372 if( !$usertalktitle->equals( $this->mTitle
) ) {
373 $ntl = wfMsg( 'youhavenewmessages',
374 $this->makeKnownLinkObj(
376 wfMsgHtml( 'newmessageslink' ),
379 $this->makeKnownLinkObj(
381 wfMsgHtml( 'newmessagesdifflink' ),
386 $this->mOut
->setSquidMaxage(0);
388 } else if (count($newtalks)) {
389 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
391 foreach ($newtalks as $newtalk) {
392 $msgs[] = wfElement("a",
393 array('href' => $newtalk["link"]), $newtalk["wiki"]);
395 $parts = implode($sep, $msgs);
396 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
397 $this->mOut
->setSquidMaxage(0);
401 return new TplValue( $ntl, 'dynamic' );
404 function showjumplinks() {
406 return new TplValue( $wgUser->getOption( 'showjumplinks' ) ?
'true' : '', 'user' );
409 function bodytext() {
410 return new TplValue( $this->mOut
->getHTML(), 'dynamic' );
413 function catlinks() {
414 return new TplValue( $this->getCategories(), 'dynamic' );
417 function extratabs( $itemTemplate ) {
418 global $wgContLang, $wgDisableLangConversion;
420 $etpl = templateEscape( $itemTemplate );
422 /* show links to different language variants */
423 $variants = $wgContLang->getVariants();
425 if ( !$wgDisableLangConversion && count( $wgContLang->getVariants() ) > 1 ) {
427 foreach ( $variants as $code ) {
428 $name = $wgContLang->getVariantname( $code );
429 if ( $name == 'disable' ) {
432 $name = templateEscape( $name );
433 $s .= "{ca_variant {{$code}} {{$name}} {{$vcount}} {{$etpl}}}\n";
437 return new TplValue( $s, array(), true );
440 function is_special() { return new TplValue( $this->mTitle
->getNamespace() == NS_SPECIAL
, 'title' ); }
441 function can_edit() { return new TplValue( (string)($this->mTitle
->userCanEdit()), 'dynamic' ); }
442 function can_move() { return new TplValue( (string)($this->mTitle
->userCanMove()), 'dynamic' ); }
443 function is_talk() { return new TplValue( (string)($this->mTitle
->isTalkPage()), 'title' ); }
444 function is_protected() { return new TplValue( (string)$this->mTitle
->isProtected(), 'dynamic' ); }
445 function nskey() { return new TplValue( $this->mTitle
->getNamespaceKey(), 'title' ); }
447 function request_url() {
449 return new TplValue( $wgRequest->getRequestURL(), 'dynamic' );
452 function subject_url() {
453 $title = $this->getSubjectPage();
454 if ( $title->exists() ) {
455 $url = $title->getLocalUrl();
457 $url = $title->getLocalUrl( 'action=edit' );
459 return new TplValue( $url, 'title' );
462 function talk_url() {
463 $title = $this->getTalkPage();
464 if ( $title->exists() ) {
465 $url = $title->getLocalUrl();
467 $url = $title->getLocalUrl( 'action=edit' );
469 return new TplValue( $url, 'title' );
472 function edit_url() {
473 return new TplValue( $this->getEditUrl(), array( 'title', 'nonview dynamic' ) );
476 function move_url() {
477 return new TplValue( $this->makeSpecialParamUrl( 'Movepage' ), array(), true );
480 function localurl( $query ) {
481 return new TplValue( $this->mTitle
->getLocalURL( $query ), 'title' );
484 function selecttab( $tab, $extraclass = '' ) {
485 if ( !isset( $this->mSelectedTab
) ) {
486 $prevent_active_tabs = false ;
487 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$preventActiveTabs ) );
492 'history' => 'history',
493 'protect' => 'protect',
494 'unprotect' => 'protect',
495 'delete' => 'delete',
497 'unwatch' => 'watch',
499 if ( $preventActiveTabs ) {
500 $this->mSelectedTab
= false;
502 $action = $this->getAction();
503 $section = $this->getSection();
505 if ( isset( $actionTabs[$action] ) ) {
506 $this->mSelectedTab
= $actionTabs[$action];
508 if ( $this->mSelectedTab
== 'edit' && $section == 'new' ) {
509 $this->mSelectedTab
= 'addsection';
511 } elseif ( $this->mTitle
->isTalkPage() ) {
512 $this->mSelectedTab
= 'talk';
514 $this->mSelectedTab
= 'subject';
519 if ( $this->mSelectedTab
== $tab ) {
520 $s = 'class="selected ' . htmlspecialchars( $extraclass ) . '"';
522 $s = 'class="' . htmlspecialchars( $extraclass ) . '"';
525 if ( $this->mSelectedTab
== $tab ) {
526 $s = 'class="selected"';
531 return new TplValue( $s, array( 'nonview dynamic', 'title' ) );
534 function subject_newclass() {
535 $title = $this->getSubjectPage();
536 $class = $title->exists() ?
'' : 'new';
537 return new TplValue( $class, 'dynamic' );
540 function talk_newclass() {
541 $title = $this->getTalkPage();
542 $class = $title->exists() ?
'' : 'new';
543 return new TplValue( $class, 'dynamic' );
546 function ca_variant( $code, $name, $index, $template ) {
548 $selected = ($code == $wgContLang->getPreferredVariant());
549 $action = $this->getAction();
552 $actstr = 'action=' . $action . '&';
553 $s = strtr( $template, array(
554 '$id' => htmlspecialchars( 'varlang-' . $index ),
555 '$class' => $selected ?
'class="selected"' : '',
557 '$href' => htmlspecialchars( $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code ) )
559 return new TplValue( $s, 'dynamic' );
562 function is_watching() {
563 return new TplValue( (string)$this->mTitle
->userIsWatching(), array( 'dynamic' ) );
567 function personal_urls( $itemTemplate ) {
568 global $wgShowIPinHeader, $wgContLang;
570 # Split this function up into many small functions, to obtain the
571 # best specificity in the dependencies of each one. The template below
572 # has no dependencies, so its generation, and any static subfunctions,
573 # can be optimised away.
574 $etpl = templateEscape( $itemTemplate );
578 {preferences {{$etpl}}}
579 {watchlist {{$etpl}}}
580 {mycontris {{$etpl}}}
585 if ( $wgShowIPinHeader ) {
587 {anonuserpage {{$etpl}}}
589 {anonlogin {{$etpl}}}
592 $s .= "{login {{$etpl}}\n";
595 return new TplValue( $s, array(), true /*this is a template*/ );
598 function userpage( $itemTemplate ) {
600 if ( $this->isLoggedIn() ) {
601 $userPage = $this->getUserPageTitle();
602 $s = $this->makeTemplateLink( $itemTemplate, 'userpage', $userPage, $wgUser->getName() );
606 return new TplValue( $s, 'user' );
609 function mytalk( $itemTemplate ) {
611 if ( $this->isLoggedIn() ) {
612 $userPage = $this->getUserPageTitle();
613 $talkPage = $userPage->getTalkPage();
614 $s = $this->makeTemplateLink( $itemTemplate, 'mytalk', $talkPage, wfMsg('mytalk') );
618 return new TplValue( $s, 'user' );
621 function preferences( $itemTemplate ) {
622 if ( $this->isLoggedIn() ) {
623 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'preferences',
624 'Preferences', wfMsg( 'preferences' ) );
628 return new TplValue( $s, array( 'loggedin', 'lang' ) );
631 function watchlist( $itemTemplate ) {
632 if ( $this->isLoggedIn() ) {
633 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'watchlist',
634 'Watchlist', wfMsg( 'watchlist' ) );
638 return new TplValue( $s, array( 'loggedin', 'lang' ) );
641 function mycontris( $itemTemplate ) {
642 if ( $this->isLoggedIn() ) {
644 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'mycontris',
645 "Contributions/" . $wgUser->getTitleKey(), wfMsg('mycontris') );
649 return new TplValue( $s, 'user' );
652 function logout( $itemTemplate ) {
653 if ( $this->isLoggedIn() ) {
654 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'logout',
655 'Userlogout', wfMsg( 'userlogout' ),
656 $this->mTitle
->getNamespace() === NS_SPECIAL
&& $this->mTitle
->getText() === 'Preferences'
657 ?
'' : "returnto=" . $this->mTitle
->getPrefixedURL() );
661 return new TplValue( $s, 'loggedin dynamic' );
664 function anonuserpage( $itemTemplate ) {
665 if ( $this->isLoggedIn() ) {
669 $userPage = $this->getUserPageTitle();
670 $s = $this->makeTemplateLink( $itemTemplate, 'userpage', $userPage, $wgUser->getName() );
672 return new TplValue( $s, '!loggedin dynamic' );
675 function anontalk( $itemTemplate ) {
676 if ( $this->isLoggedIn() ) {
679 $userPage = $this->getUserPageTitle();
680 $talkPage = $userPage->getTalkPage();
681 $s = $this->makeTemplateLink( $itemTemplate, 'mytalk', $talkPage, wfMsg('anontalk') );
683 return new TplValue( $s, '!loggedin dynamic' );
686 function anonlogin( $itemTemplate ) {
687 if ( $this->isLoggedIn() ) {
690 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'anonlogin', 'Userlogin',
691 wfMsg( 'userlogin' ), 'returnto=' . urlencode( $this->getThisPDBK() ) );
693 return new TplValue( $s, '!loggedin dynamic' );
696 function login( $itemTemplate ) {
697 if ( $this->isLoggedIn() ) {
700 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'login', 'Userlogin',
701 wfMsg( 'userlogin' ), 'returnto=' . urlencode( $this->getThisPDBK() ) );
703 return new TplValue( $s, '!loggedin dynamic' );
706 function logopath() { return $GLOBALS['wgLogo']; }
707 function mainpage() { return $this->makeI18nUrl( 'mainpage' ); }
709 function sidebar( $startSection, $endSection, $innerTpl ) {
711 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
712 $firstSection = true;
713 foreach ($lines as $line) {
714 if (strpos($line, '*') !== 0)
716 if (strpos($line, '**') !== 0) {
717 $bar = trim($line, '* ');
718 $name = wfMsg( $bar );
719 if (wfEmptyMsg($bar, $name)) {
722 if ( $firstSection ) {
723 $firstSection = false;
727 $s .= strtr( $startSection,
729 '$bar' => htmlspecialchars( $bar ),
733 if (strpos($line, '|') !== false) { // sanity check
734 $line = explode( '|' , trim($line, '* '), 2 );
735 $link = wfMsgForContent( $line[0] );
738 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
740 if (wfEmptyMsg($line[0], $link))
742 $href = $this->makeInternalOrExternalUrl( $link );
744 $s .= strtr( $innerTpl,
746 '$text' => htmlspecialchars( $text ),
747 '$href' => htmlspecialchars( $href ),
748 '$id' => htmlspecialchars( 'n-' . strtr($line[1], ' ', '-') ),
754 if ( !$firstSection ) {
758 // Depends on user language only
759 return new TplValue( $s, 'lang' );
762 function searchaction() {
764 return $this->getSearchLink();
769 return new TplValue( trim( $this->getSearch() ), 'special dynamic' );
772 function notspecialpage() {
773 return new TplValue( $this->mTitle
->getNamespace() != NS_SPECIAL
, 'special' );
776 function nav_whatlinkshere() {
777 return new TplValue( $this->makeSpecialParamUrl('Whatlinkshere' ), array(), true );
780 function article_exists() {
781 return new TplValue( (string)($this->mTitle
->getArticleId() !== 0), 'title' );
784 function nav_recentchangeslinked() {
785 return new TplValue( $this->makeSpecialParamUrl('Recentchangeslinked' ), array(), true );
788 function feeds( $itemTemplate = '' ) {
789 if ( !$this->mOut
->isSyndicated() ) {
791 } elseif ( $itemTemplate == '' ) {
792 // boolean only required
796 global $wgFeedClasses, $wgRequest;
797 foreach( $wgFeedClasses as $format => $class ) {
798 $feeds .= strtr( $itemTemplate,
800 '$key' => htmlspecialchars( $format ),
802 '$href' => $wgRequest->appendQuery( "feed=$format" )
806 return new TplValue( $feeds, 'special dynamic' );
809 function is_userpage() {
810 list( $id, $ip ) = $this->getUserPageIdIp();
811 return new TplValue( (string)($id ||
$ip), 'title' );
814 function is_ns_mediawiki() {
815 return new TplValue( (string)$this->mTitle
->getNamespace() == NS_MEDIAWIKI
, 'title' );
818 function is_loggedin() {
820 return new TplValue( (string)($wgUser->isLoggedIn()), 'loggedin' );
823 function nav_contributions() {
824 $url = $this->makeSpecialParamUrl( 'Contributions', '', '{title_userurl}' );
825 return new TplValue( $url, array(), true );
828 function is_allowed( $right ) {
830 return new TplValue( (string)$wgUser->isAllowed( $right ), 'user' );
833 function nav_blockip() {
834 $url = $this->makeSpecialParamUrl( 'Blockip', '', '{title_userurl}' );
835 return new TplValue( $url, array(), true );
838 function nav_emailuser() {
839 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
840 if ( !$wgEnableEmail ||
!$wgEnableUserEmail ) return '';
842 $url = $this->makeSpecialParamUrl( 'Emailuser', '', '{title_userurl}' );
843 return new TplValue( $url, array(), true );
846 function nav_upload() {
847 global $wgEnableUploads, $wgUploadNavigationUrl;
848 if ( !$wgEnableUploads ) {
850 } elseif ( $wgUploadNavigationUrl ) {
851 return $wgUploadNavigationUrl;
853 return $this->makeSpecialUrl('Upload');
857 function nav_specialpages() {
858 return $this->makeSpecialUrl('Specialpages');
861 function nav_print() {
862 global $wgRequest, $wgArticle;
863 $action = $this->getAction();
865 if( $this->mTitle
->getNamespace() !== NS_SPECIAL
866 && ($action == '' ||
$action == 'view' ||
$action == 'purge' ) )
868 $revid = $wgArticle->getLatest();
870 $url = $wgRequest->appendQuery( 'printable=yes' );
873 return new TplValue( $url, array( 'nonview dynamic', 'title' ) );
876 function nav_permalink() {
877 $url = (string)$this->getPermalink();
878 return new TplValue( $url, 'dynamic' );
881 function nav_trackbacklink() {
882 global $wgUseTrackbacks;
883 if ( !$wgUseTrackbacks ) return '';
885 return new TplValue( $this->mTitle
->trackbackURL(), 'title' );
888 function is_permalink() {
889 return new TplValue( (string)($this->getPermalink() === false), 'nonview dynamic' );
892 function toolboxend() {
893 // This is where the MonoBookTemplateToolboxEnd hook went in the old skin
897 function language_urls( $outer, $inner ) {
898 global $wgHideInterlanguageLinks, $wgOut, $wgContLang;
899 if ( $wgHideInterlanguageLinks ) return '';
901 $links = $wgOut->getLanguageLinks();
903 if ( count( $links ) ) {
904 foreach( $links as $l ) {
905 $tmp = explode( ':', $l, 2 );
906 $nt = Title
::newFromText( $l );
909 '$class' => htmlspecialchars( 'interwiki-' . $tmp[0] ),
910 '$href' => htmlspecialchars( $nt->getFullURL() ),
911 '$text' => ($wgContLang->getLanguageName( $nt->getInterwiki() ) != ''?
912 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
916 $s = str_replace( '$body', $s, $outer );
918 return new TplValue( $s, 'dynamic' );
921 function poweredbyico() { return $this->getPoweredBy(); }
922 function copyrightico() { return $this->getCopyrightIcon(); }
925 global $wgMaxCredits;
926 if ( $wgMaxCredits ) return '';
928 if ( $this->isCurrentArticleView() ) {
929 $s = $this->lastModified();
933 return new TplValue( $s, 'dynamic' );
936 function viewcount() {
937 global $wgDisableCounters;
938 if ( $wgDisableCounters ) return '';
940 global $wgLang, $wgArticle;
941 if ( is_object( $wgArticle ) ) {
942 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
944 $viewcount = wfMsg( "viewcount", $viewcount );
951 return new TplValue( $viewcount, 'dynamic' );
954 function numberofwatchingusers() {
955 global $wgPageShowWatchingUsers;
956 if ( !$wgPageShowWatchingUsers ) return '';
958 $dbr =& wfGetDB( DB_SLAVE
);
959 extract( $dbr->tableNames( 'watchlist' ) );
960 $sql = "SELECT COUNT(*) AS n FROM $watchlist
961 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
962 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
963 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
964 $row = $dbr->fetchObject( $res );
967 $s = wfMsg('number_of_watching_users_pageview', $num);
971 return new TplValue( $s, 'dynamic' );
975 global $wgMaxCredits;
976 if ( !$wgMaxCredits ) return '';
978 if ( $this->isCurrentArticleView() ) {
979 require_once("Credits.php");
980 global $wgArticle, $wgShowCreditsIfMax;
981 $credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
985 return new TplValue( $credits, 'view dynamic' );
988 function normalcopyright() {
989 return $this->getCopyright( 'normal' );
992 function historycopyright() {
993 return $this->getCopyright( 'history' );
996 function is_currentview() {
998 return new TplValue( (string)$this->isCurrentArticleView(), 'view' );
1001 function usehistorycopyright() {
1003 if ( wfMsgForContent( 'history_copyright' ) == '-' ) return '';
1005 $oldid = $this->getOldId();
1006 $diff = $this->getDiff();
1007 $use = (string)(!is_null( $oldid ) && is_null( $diff ));
1008 return new TplValue( $use, 'nonview dynamic' );
1011 function privacy() {
1012 return new TplValue( $this->privacyLink(), 'lang' );
1015 return new TplValue( $this->aboutLink(), 'lang' );
1017 function disclaimer() {
1018 return new TplValue( $this->disclaimerLink(), 'lang' );
1020 function tagline() {
1021 # A reference to this tag existed in the old MonoBook.php, but the
1022 # template data wasn't set anywhere
1025 function reporttime() {
1026 return new TplValue( $this->mOut
->reportTime(), 'dynamic' );
1029 function msg( $name ) {
1030 return new TplValue( wfMsg( $name ), 'lang' );
1033 function fallbackmsg( $name, $fallback ) {
1034 $text = wfMsg( $name );
1035 if ( wfEmptyMsg( $name, $text ) ) {
1038 return new TplValue( $text, 'lang' );
1041 /******************************************************
1042 * Utility functions *
1043 ******************************************************/
1045 /** Return true if this request is a valid, secure CSS preview */
1046 function isCssPreview() {
1047 if ( !isset( $this->mCssPreview
) ) {
1048 global $wgRequest, $wgAllowUserCss, $wgUser;
1049 $this->mCssPreview
=
1051 $wgUser->isLoggedIn() &&
1052 $this->mTitle
->isCssSubpage() &&
1053 $this->userCanPreview( $this->getAction() );
1055 return $this->mCssPreview
;
1058 /** Return true if this request is a valid, secure JS preview */
1059 function isJsPreview() {
1060 if ( !isset( $this->mJsPreview
) ) {
1061 global $wgRequest, $wgAllowUserJs, $wgUser;
1064 $wgUser->isLoggedIn() &&
1065 $this->mTitle
->isJsSubpage() &&
1066 $this->userCanPreview( $this->getAction() );
1068 return $this->mJsPreview
;
1071 /** Get the title of the $wgUser's user page */
1072 function getUserPageTitle() {
1073 if ( !isset( $this->mUserPageTitle
) ) {
1075 $this->mUserPageTitle
= $wgUser->getUserPage();
1077 return $this->mUserPageTitle
;
1080 /** Get the text of the user page title */
1081 function getUserPageText() {
1082 if ( !isset( $this->mUserPageText
) ) {
1083 $userPage = $this->getUserPageTitle();
1084 $this->mUserPageText
= $userPage->getPrefixedText();
1086 return $this->mUserPageText
;
1089 /** Make an HTML element for a stylesheet link */
1090 function makeStylesheetLink( $url ) {
1091 return '<link rel="stylesheet" type="text/css" href="' . htmlspecialchars( $url ) . "\"/>";
1094 /** Make an XHTML element for inline CSS */
1095 function makeStylesheetCdata( $style ) {
1096 return "<style type=\"text/css\"> /*<![CDATA[*/ {$style} /*]]>*/ </style>";
1099 /** Get the edit URL for this page */
1100 function getEditUrl() {
1101 if ( !isset( $this->mEditUrl
) ) {
1102 $this->mEditUrl
= $this->mTitle
->getLocalUrl( $this->editUrlOptions() );
1104 return $this->mEditUrl
;
1107 /** Get the prefixed DB key for this page */
1108 function getThisPDBK() {
1109 if ( !isset( $this->mThisPDBK
) ) {
1110 $this->mThisPDBK
= $this->mTitle
->getPrefixedDbKey();
1112 return $this->mThisPDBK
;
1115 function getThisTitleUrlForm() {
1116 if ( !isset( $this->mThisTitleUrlForm
) ) {
1117 $this->mThisTitleUrlForm
= $this->mTitle
->getPrefixedURL();
1119 return $this->mThisTitleUrlForm
;
1123 * If the current page is a user page, get the user's ID and IP. Otherwise return array(0,false)
1125 function getUserPageIdIp() {
1126 if ( !isset( $this->mUserPageId
) ) {
1127 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
1128 $this->mUserPageId
= User
::idFromName($this->mTitle
->getText());
1129 $this->mUserPageIp
= User
::isIP($this->mTitle
->getText());
1131 $this->mUserPageId
= 0;
1132 $this->mUserPageIp
= false;
1135 return array( $this->mUserPageId
, $this->mUserPageIp
);
1139 * Returns a permalink URL, or false if the current page is already a
1140 * permalink, or blank if a permalink shouldn't be displayed
1142 function getPermalink() {
1143 if ( !isset( $this->mPermalink
) ) {
1144 global $wgRequest, $wgArticle;
1145 $action = $this->getAction();
1146 $oldid = $this->getOldId();
1148 if( $this->mTitle
->getNamespace() !== NS_SPECIAL
1149 && $this->mTitle
->getArticleId() != 0
1150 && ($action == '' ||
$action == 'view' ||
$action == 'purge' ) )
1153 $revid = $wgArticle->getLatest();
1154 $url = $this->mTitle
->getLocalURL( "oldid=$revid" );
1166 * Returns true if the current page is an article, not a special page,
1167 * and we are viewing a revision, not a diff
1169 function isArticleView() {
1170 global $wgOut, $wgArticle, $wgRequest;
1171 if ( !isset( $this->mIsArticleView
) ) {
1172 $oldid = $this->getOldId();
1173 $diff = $this->getDiff();
1174 $this->mIsArticleView
= $wgOut->isArticle() and
1175 (!is_null( $oldid ) or is_null( $diff )) and 0 != $wgArticle->getID();
1177 return $this->mIsArticleView
;
1180 function isCurrentArticleView() {
1181 if ( !isset( $this->mIsCurrentArticleView
) ) {
1182 global $wgOut, $wgArticle, $wgRequest;
1183 $oldid = $this->getOldId();
1184 $this->mIsCurrentArticleView
= $wgOut->isArticle() && is_null( $oldid ) && 0 != $wgArticle->getID();
1186 return $this->mIsCurrentArticleView
;
1191 * Return true if the current page is editable; if edit section on right
1192 * click should be enabled.
1194 function isEditable() {
1196 $action = $this->getAction();
1197 return ($this->mTitle
->getNamespace() != NS_SPECIAL
and !($action == 'edit' or $action == 'submit'));
1200 /** Return true if the user is logged in */
1201 function isLoggedIn() {
1203 return $wgUser->isLoggedIn();
1206 /** Get the local URL of the current page */
1207 function getPageUrl() {
1208 if ( !isset( $this->mPageUrl
) ) {
1209 $this->mPageUrl
= $this->mTitle
->getLocalURL();
1211 return $this->mPageUrl
;
1214 /** Make a link to a title using a template */
1215 function makeTemplateLink( $template, $key, $title, $text ) {
1216 $url = $title->getLocalUrl();
1217 return strtr( $template,
1220 '$classactive' => ($url == $this->getPageUrl()) ?
'class="active"' : '',
1221 '$class' => $title->getArticleID() == 0 ?
'class="new"' : '',
1222 '$href' => htmlspecialchars( $url ),
1227 /** Make a link to a URL using a template */
1228 function makeTemplateLinkUrl( $template, $key, $url, $text ) {
1229 return strtr( $template,
1232 '$classactive' => ($url == $this->getPageUrl()) ?
'class="active"' : '',
1234 '$href' => htmlspecialchars( $url ),
1239 /** Make a link to a special page using a template */
1240 function makeSpecialTemplateLink( $template, $key, $specialName, $text, $query = '' ) {
1241 $url = $this->makeSpecialUrl( $specialName, $query );
1242 // Ignore the query when comparing
1243 $active = ($this->mTitle
->getNamespace() == NS_SPECIAL
&& $this->mTitle
->getDBkey() == $specialName);
1244 return strtr( $template,
1247 '$classactive' => $active ?
'class="active"' : '',
1249 '$href' => htmlspecialchars( $url ),
1254 function loadRequestValues() {
1256 $this->mAction
= $wgRequest->getText( 'action' );
1257 $this->mOldId
= $wgRequest->getVal( 'oldid' );
1258 $this->mDiff
= $wgRequest->getVal( 'diff' );
1259 $this->mSection
= $wgRequest->getVal( 'section' );
1260 $this->mSearch
= $wgRequest->getVal( 'search' );
1261 $this->mRequestValuesLoaded
= true;
1266 /** Get the action parameter of the request */
1267 function getAction() {
1268 if ( !isset( $this->mRequestValuesLoaded
) ) {
1269 $this->loadRequestValues();
1271 return $this->mAction
;
1274 /** Get the oldid parameter */
1275 function getOldId() {
1276 if ( !isset( $this->mRequestValuesLoaded
) ) {
1277 $this->loadRequestValues();
1279 return $this->mOldId
;
1282 /** Get the diff parameter */
1283 function getDiff() {
1284 if ( !isset( $this->mRequestValuesLoaded
) ) {
1285 $this->loadRequestValues();
1287 return $this->mDiff
;
1290 function getSection() {
1291 if ( !isset( $this->mRequestValuesLoaded
) ) {
1292 $this->loadRequestValues();
1294 return $this->mSection
;
1297 function getSearch() {
1298 if ( !isset( $this->mRequestValuesLoaded
) ) {
1299 $this->loadRequestValues();
1301 return $this->mSearch
;
1304 /** Make a special page URL of the form [[Special:Somepage/{title_urlform}]] */
1305 function makeSpecialParamUrl( $name, $query = '', $param = '{title_urlform}' ) {
1306 // Abuse makeTitle's lax validity checking to slip a control character into the URL
1307 $title = Title
::makeTitle( NS_SPECIAL
, "$name/\x1a" );
1308 $url = templateEscape( $title->getLocalURL( $query ) );
1309 // Now replace it with the parameter
1310 return str_replace( '%1A', $param, $url );
1313 function getSubjectPage() {
1314 if ( !isset( $this->mSubjectPage
) ) {
1315 $this->mSubjectPage
= $this->mTitle
->getSubjectPage();
1317 return $this->mSubjectPage
;
1320 function getTalkPage() {
1321 if ( !isset( $this->mTalkPage
) ) {
1322 $this->mTalkPage
= $this->mTitle
->getTalkPage();
1324 return $this->mTalkPage
;