* Removed unused usenewcategorypage from messages
[mediawiki.git] / skins / disabled / MonoBookCBT.php
blob0474ad7cf07043ee4f76f9ac73a6072a12bd7b9e
1 <?php
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' );
11 /**
12 * MonoBook clone using the new dependency-tracking template processor.
13 * EXPERIMENTAL - use only for testing and profiling at this stage.
15 * See includes/cbt/README for an explanation.
17 * The main thing that's missing is cache invalidation, on change of:
18 * * messages
19 * * user preferences
20 * * source template
21 * * source code and configuration files
23 * The other thing is that lots of dependencies that are declared in the callbacks
24 * are not intelligently handled. There's some room for improvement there.
26 * The class is derived from SkinTemplate, but that's only temporary. Eventually
27 * it'll be derived from Skin, and I've avoided using SkinTemplate functions as
28 * much as possible. In fact, the only SkinTemplate dependencies I know of at the
29 * moment are the functions to generate the gen=css and gen=js files.
32 class SkinMonoBookCBT extends SkinTemplate {
33 var $mOut, $mTitle;
34 var $mStyleName = 'monobook';
35 var $mCompiling = false;
36 var $mFunctionCache = array();
38 /******************************************************
39 * General functions *
40 ******************************************************/
42 /** Execute the template and write out the result */
43 function outputPage( &$out ) {
44 echo $this->execute( $out );
47 function execute( &$out ) {
48 global $wgTitle, $wgStyleDirectory, $wgParserCacheType;
49 $fname = 'SkinMonoBookCBT::execute';
50 wfProfileIn( $fname );
51 wfProfileIn( "$fname-setup" );
52 Skin::initPage( $out );
54 $this->mOut =& $out;
55 $this->mTitle =& $wgTitle;
57 $sourceFile = "$wgStyleDirectory/MonoBook.tpl";
59 wfProfileOut( "$fname-setup" );
61 if ( $wgParserCacheType == CACHE_NONE ) {
62 $template = file_get_contents( $sourceFile );
63 $text = $this->executeTemplate( $template );
64 } else {
65 $compiled = $this->getCompiledTemplate( $sourceFile );
67 wfProfileIn( "$fname-eval" );
68 $text = eval( $compiled );
69 wfProfileOut( "$fname-eval" );
71 wfProfileOut( $fname );
72 return $text;
75 function getCompiledTemplate( $sourceFile ) {
76 global $wgDBname, $wgMemc, $wgRequest, $wgUser, $parserMemc;
77 $fname = 'SkinMonoBookCBT::getCompiledTemplate';
79 $expiry = 3600;
81 // Sandbox template execution
82 if ( $this->mCompiling ) {
83 return;
86 wfProfileIn( $fname );
88 // Is the request an ordinary page view?
89 if ( $wgRequest->wasPosted() ||
90 count( array_diff( array_keys( $_GET ), array( 'title', 'useskin', 'recompile' ) ) ) != 0 )
92 $type = 'nonview';
93 } else {
94 $type = 'view';
97 // Per-user compiled template
98 // Put all logged-out users on the same cache key
99 $cacheKey = "$wgDBname:monobookcbt:$type:" . $wgUser->getId();
101 $recompile = $wgRequest->getVal( 'recompile' );
102 if ( $recompile == 'user' ) {
103 $recompileUser = true;
104 $recompileGeneric = false;
105 } elseif ( $recompile ) {
106 $recompileUser = true;
107 $recompileGeneric = true;
108 } else {
109 $recompileUser = false;
110 $recompileGeneric = false;
113 if ( !$recompileUser ) {
114 $php = $parserMemc->get( $cacheKey );
116 if ( $recompileUser || !$php ) {
117 if ( $wgUser->isLoggedIn() ) {
118 // Perform staged compilation
119 // First compile a generic template for all logged-in users
120 $genericKey = "$wgDBname:monobookcbt:$type:loggedin";
121 if ( !$recompileGeneric ) {
122 $template = $parserMemc->get( $genericKey );
124 if ( $recompileGeneric || !$template ) {
125 $template = file_get_contents( $sourceFile );
126 $ignore = array( 'loggedin', '!loggedin dynamic' );
127 if ( $type == 'view' ) {
128 $ignore[] = 'nonview dynamic';
130 $template = $this->compileTemplate( $template, $ignore );
131 $parserMemc->set( $genericKey, $template, $expiry );
133 } else {
134 $template = file_get_contents( $sourceFile );
137 $ignore = array( 'lang', 'loggedin', 'user' );
138 if ( $wgUser->isLoggedIn() ) {
139 $ignore[] = '!loggedin dynamic';
140 } else {
141 $ignore[] = 'loggedin dynamic';
143 if ( $type == 'view' ) {
144 $ignore[] = 'nonview dynamic';
146 $compiled = $this->compileTemplate( $template, $ignore );
148 // Reduce whitespace
149 // This is done here instead of in CBTProcessor because we can be
150 // more sure it is safe here.
151 $compiled = preg_replace( '/^[ \t]+/m', '', $compiled );
152 $compiled = preg_replace( '/[\r\n]+/', "\n", $compiled );
154 // Compile to PHP
155 $compiler = new CBTCompiler( $compiled );
156 $ret = $compiler->compile();
157 if ( $ret !== true ) {
158 echo $ret;
159 wfErrorExit();
161 $php = $compiler->generatePHP( '$this' );
163 $parserMemc->set( $cacheKey, $php, $expiry );
165 wfProfileOut( $fname );
166 return $php;
169 function compileTemplate( $template, $ignore ) {
170 $tp = new CBTProcessor( $template, $this, $ignore );
171 $tp->mFunctionCache = $this->mFunctionCache;
173 $this->mCompiling = true;
174 $compiled = $tp->compile();
175 $this->mCompiling = false;
177 if ( $tp->getLastError() ) {
178 // If there was a compile error, don't save the template
179 // Instead just print the error and exit
180 echo $compiled;
181 wfErrorExit();
183 $this->mFunctionCache = $tp->mFunctionCache;
184 return $compiled;
187 function executeTemplate( $template ) {
188 $fname = 'SkinMonoBookCBT::executeTemplate';
189 wfProfileIn( $fname );
190 $tp = new CBTProcessor( $template, $this );
191 $tp->mFunctionCache = $this->mFunctionCache;
193 $this->mCompiling = true;
194 $text = $tp->execute();
195 $this->mCompiling = false;
197 $this->mFunctionCache = $tp->mFunctionCache;
198 wfProfileOut( $fname );
199 return $text;
202 /******************************************************
203 * Callbacks *
204 ******************************************************/
206 function lang() { return $GLOBALS['wgContLanguageCode']; }
208 function dir() {
209 global $wgContLang;
210 return $wgContLang->isRTL() ? 'rtl' : 'ltr';
213 function mimetype() { return $GLOBALS['wgMimeType']; }
214 function charset() { return $GLOBALS['wgOutputEncoding']; }
215 function headlinks() {
216 return cbt_value( $this->mOut->getHeadLinks(), 'dynamic' );
218 function headscripts() {
219 return cbt_value( $this->mOut->getScript(), 'dynamic' );
222 function pagetitle() {
223 return cbt_value( $this->mOut->getHTMLTitle(), array( 'title', 'lang' ) );
226 function stylepath() { return $GLOBALS['wgStylePath']; }
227 function stylename() { return $this->mStyleName; }
229 function notprintable() {
230 global $wgRequest;
231 return cbt_value( !$wgRequest->getBool( 'printable' ), 'nonview dynamic' );
234 function jsmimetype() { return $GLOBALS['wgJsMimeType']; }
236 function jsvarurl() {
237 global $wgUseSiteJs, $wgUser;
238 if ( !$wgUseSiteJs ) return '';
240 if ( $wgUser->isLoggedIn() ) {
241 $url = $this->makeUrl('-','action=raw&smaxage=0&gen=js');
242 } else {
243 $url = $this->makeUrl('-','action=raw&gen=js');
245 return cbt_value( $url, 'loggedin' );
248 function pagecss() {
249 global $wgHooks;
251 $out = false;
252 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
254 // Unknown dependencies
255 return cbt_value( $out, 'dynamic' );
258 function usercss() {
259 if ( $this->isCssPreview() ) {
260 global $wgRequest;
261 $usercss = $this->makeStylesheetCdata( $wgRequest->getText('wpTextbox1') );
262 } else {
263 $usercss = $this->makeStylesheetLink( $this->makeUrl($this->getUserPageText() .
264 '/'.$this->mStyleName.'.css', 'action=raw&ctype=text/css' ) );
267 // Dynamic when not an ordinary page view, also depends on the username
268 return cbt_value( $usercss, array( 'nonview dynamic', 'user' ) );
271 function sitecss() {
272 global $wgUseSiteCss;
273 if ( !$wgUseSiteCss ) {
274 return '';
277 global $wgSquidMaxage, $wgContLang, $wgStylePath;
279 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
281 $sitecss = '';
282 if ( $wgContLang->isRTL() ) {
283 $sitecss .= $this->makeStylesheetLink( $wgStylePath . '/' . $this->mStyleName . '/rtl.css' ) . "\n";
286 $sitecss .= $this->makeStylesheetLink( $this->makeNSUrl('Common.css', $query, NS_MEDIAWIKI) ) . "\n";
287 $sitecss .= $this->makeStylesheetLink( $this->makeNSUrl(
288 ucfirst($this->mStyleName) . '.css', $query, NS_MEDIAWIKI) ) . "\n";
290 // No deps
291 return $sitecss;
294 function gencss() {
295 global $wgUseSiteCss;
296 if ( !$wgUseSiteCss ) return '';
298 global $wgSquidMaxage, $wgUser, $wgAllowUserCss;
299 if ( $this->isCssPreview() ) {
300 $siteargs = '&smaxage=0&maxage=0';
301 } else {
302 $siteargs = '&maxage=' . $wgSquidMaxage;
304 if ( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
305 $siteargs .= '&ts={user_touched}';
306 $isTemplate = true;
307 } else {
308 $isTemplate = false;
311 $link = $this->makeStylesheetLink( $this->makeUrl('-','action=raw&gen=css' . $siteargs) ) . "\n";
313 if ( $wgAllowUserCss ) {
314 $deps = 'loggedin';
315 } else {
316 $deps = array();
318 return cbt_value( $link, $deps, $isTemplate );
321 function user_touched() {
322 global $wgUser;
323 return cbt_value( $wgUser->mTouched, 'dynamic' );
326 function userjs() {
327 global $wgAllowUserJs, $wgJsMimeType;
328 if ( !$wgAllowUserJs ) return '';
330 if ( $this->isJsPreview() ) {
331 $url = '';
332 } else {
333 $url = $this->makeUrl($this->getUserPageText().'/'.$this->mStyleName.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
335 return cbt_value( $url, array( 'nonview dynamic', 'user' ) );
338 function userjsprev() {
339 global $wgAllowUserJs, $wgRequest;
340 if ( !$wgAllowUserJs ) return '';
341 if ( $this->isJsPreview() ) {
342 $js = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
343 } else {
344 $js = '';
346 return cbt_value( $js, array( 'nonview dynamic' ) );
349 function trackbackhtml() {
350 global $wgUseTrackbacks;
351 if ( !$wgUseTrackbacks ) return '';
353 if ( $this->mOut->isArticleRelated() ) {
354 $tb = $this->mTitle->trackbackRDF();
355 } else {
356 $tb = '';
358 return cbt_value( $tb, 'dynamic' );
361 function body_ondblclick() {
362 global $wgUser;
363 if( $this->isEditable() && $wgUser->getOption("editondblclick") ) {
364 $js = 'document.location = "' . $this->getEditUrl() .'";';
365 } else {
366 $js = '';
369 if ( User::getDefaultOption('editondblclick') ) {
370 return cbt_value( $js, 'user', 'title' );
371 } else {
372 // Optimise away for logged-out users
373 return cbt_value( $js, 'loggedin dynamic' );
377 function body_onload() {
378 global $wgUser;
379 if ( $this->isEditable() && $wgUser->getOption( 'editsectiononrightclick' ) ) {
380 $js = 'setupRightClickEdit()';
381 } else {
382 $js = '';
384 return cbt_value( $js, 'loggedin dynamic' );
387 function nsclass() {
388 return cbt_value( 'ns-' . $this->mTitle->getNamespace(), 'title' );
391 function sitenotice() {
392 // Perhaps this could be given special dependencies using our knowledge of what
393 // wfGetSiteNotice() depends on.
394 return cbt_value( wfGetSiteNotice(), 'dynamic' );
397 function title() {
398 return cbt_value( $this->mOut->getPageTitle(), array( 'title', 'lang' ) );
401 function title_urlform() {
402 return cbt_value( $this->getThisTitleUrlForm(), 'title' );
405 function title_userurl() {
406 return cbt_value( urlencode( $this->mTitle->getDBkey() ), 'title' );
409 function subtitle() {
410 $subpagestr = $this->subPageSubtitle();
411 if ( !empty( $subpagestr ) ) {
412 $s = '<span class="subpages">'.$subpagestr.'</span>'.$this->mOut->getSubtitle();
413 } else {
414 $s = $this->mOut->getSubtitle();
416 return cbt_value( $s, array( 'title', 'nonview dynamic' ) );
419 function undelete() {
420 return cbt_value( $this->getUndeleteLink(), array( 'title', 'lang' ) );
423 function newtalk() {
424 global $wgUser, $wgDBname;
425 $newtalks = $wgUser->getNewMessageLinks();
427 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === $wgDBname) {
428 $usertitle = $this->getUserPageTitle();
429 $usertalktitle = $usertitle->getTalkPage();
430 if( !$usertalktitle->equals( $this->mTitle ) ) {
431 $ntl = wfMsg( 'youhavenewmessages',
432 $this->makeKnownLinkObj(
433 $usertalktitle,
434 wfMsgHtml( 'newmessageslink' ),
435 'redirect=no'
437 $this->makeKnownLinkObj(
438 $usertalktitle,
439 wfMsgHtml( 'newmessagesdifflink' ),
440 'diff=cur'
443 # Disable Cache
444 $this->mOut->setSquidMaxage(0);
446 } else if (count($newtalks)) {
447 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
448 $msgs = array();
449 foreach ($newtalks as $newtalk) {
450 $msgs[] = wfElement("a",
451 array('href' => $newtalk["link"]), $newtalk["wiki"]);
453 $parts = implode($sep, $msgs);
454 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
455 $this->mOut->setSquidMaxage(0);
456 } else {
457 $ntl = '';
459 return cbt_value( $ntl, 'dynamic' );
462 function showjumplinks() {
463 global $wgUser;
464 return cbt_value( $wgUser->getOption( 'showjumplinks' ) ? 'true' : '', 'user' );
467 function bodytext() {
468 return cbt_value( $this->mOut->getHTML(), 'dynamic' );
471 function catlinks() {
472 if ( !isset( $this->mCatlinks ) ) {
473 $this->mCatlinks = $this->getCategories();
475 return cbt_value( $this->mCatlinks, 'dynamic' );
478 function extratabs( $itemTemplate ) {
479 global $wgContLang, $wgDisableLangConversion;
481 $etpl = cbt_escape( $itemTemplate );
483 /* show links to different language variants */
484 $variants = $wgContLang->getVariants();
485 $s = '';
486 if ( !$wgDisableLangConversion && count( $wgContLang->getVariants() ) > 1 ) {
487 $vcount=0;
488 foreach ( $variants as $code ) {
489 $name = $wgContLang->getVariantname( $code );
490 if ( $name == 'disable' ) {
491 continue;
493 $code = cbt_escape( $code );
494 $name = cbt_escape( $name );
495 $s .= "{ca_variant {{$code}} {{$name}} {{$vcount}} {{$etpl}}}\n";
496 $vcount ++;
499 return cbt_value( $s, array(), true );
502 function is_special() { return cbt_value( $this->mTitle->getNamespace() == NS_SPECIAL, 'title' ); }
503 function can_edit() { return cbt_value( (string)($this->mTitle->userCanEdit()), 'dynamic' ); }
504 function can_move() { return cbt_value( (string)($this->mTitle->userCanMove()), 'dynamic' ); }
505 function is_talk() { return cbt_value( (string)($this->mTitle->isTalkPage()), 'title' ); }
506 function is_protected() { return cbt_value( (string)$this->mTitle->isProtected(), 'dynamic' ); }
507 function nskey() { return cbt_value( $this->mTitle->getNamespaceKey(), 'title' ); }
509 function request_url() {
510 global $wgRequest;
511 return cbt_value( $wgRequest->getRequestURL(), 'dynamic' );
514 function subject_url() {
515 $title = $this->getSubjectPage();
516 if ( $title->exists() ) {
517 $url = $title->getLocalUrl();
518 } else {
519 $url = $title->getLocalUrl( 'action=edit' );
521 return cbt_value( $url, 'title' );
524 function talk_url() {
525 $title = $this->getTalkPage();
526 if ( $title->exists() ) {
527 $url = $title->getLocalUrl();
528 } else {
529 $url = $title->getLocalUrl( 'action=edit' );
531 return cbt_value( $url, 'title' );
534 function edit_url() {
535 return cbt_value( $this->getEditUrl(), array( 'title', 'nonview dynamic' ) );
538 function move_url() {
539 return cbt_value( $this->makeSpecialParamUrl( 'Movepage' ), array(), true );
542 function localurl( $query ) {
543 return cbt_value( $this->mTitle->getLocalURL( $query ), 'title' );
546 function selecttab( $tab, $extraclass = '' ) {
547 if ( !isset( $this->mSelectedTab ) ) {
548 $prevent_active_tabs = false ;
549 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$preventActiveTabs ) );
551 $actionTabs = array(
552 'edit' => 'edit',
553 'submit' => 'edit',
554 'history' => 'history',
555 'protect' => 'protect',
556 'unprotect' => 'protect',
557 'delete' => 'delete',
558 'watch' => 'watch',
559 'unwatch' => 'watch',
561 if ( $preventActiveTabs ) {
562 $this->mSelectedTab = false;
563 } else {
564 $action = $this->getAction();
565 $section = $this->getSection();
567 if ( isset( $actionTabs[$action] ) ) {
568 $this->mSelectedTab = $actionTabs[$action];
570 if ( $this->mSelectedTab == 'edit' && $section == 'new' ) {
571 $this->mSelectedTab = 'addsection';
573 } elseif ( $this->mTitle->isTalkPage() ) {
574 $this->mSelectedTab = 'talk';
575 } else {
576 $this->mSelectedTab = 'subject';
580 if ( $extraclass ) {
581 if ( $this->mSelectedTab == $tab ) {
582 $s = 'class="selected ' . htmlspecialchars( $extraclass ) . '"';
583 } else {
584 $s = 'class="' . htmlspecialchars( $extraclass ) . '"';
586 } else {
587 if ( $this->mSelectedTab == $tab ) {
588 $s = 'class="selected"';
589 } else {
590 $s = '';
593 return cbt_value( $s, array( 'nonview dynamic', 'title' ) );
596 function subject_newclass() {
597 $title = $this->getSubjectPage();
598 $class = $title->exists() ? '' : 'new';
599 return cbt_value( $class, 'dynamic' );
602 function talk_newclass() {
603 $title = $this->getTalkPage();
604 $class = $title->exists() ? '' : 'new';
605 return cbt_value( $class, 'dynamic' );
608 function ca_variant( $code, $name, $index, $template ) {
609 global $wgContLang;
610 $selected = ($code == $wgContLang->getPreferredVariant());
611 $action = $this->getAction();
612 $actstr = '';
613 if( $action )
614 $actstr = 'action=' . $action . '&';
615 $s = strtr( $template, array(
616 '$id' => htmlspecialchars( 'varlang-' . $index ),
617 '$class' => $selected ? 'class="selected"' : '',
618 '$text' => $name,
619 '$href' => htmlspecialchars( $this->mTitle->getLocalUrl( $actstr . 'variant=' . $code ) )
621 return cbt_value( $s, 'dynamic' );
624 function is_watching() {
625 return cbt_value( (string)$this->mTitle->userIsWatching(), array( 'dynamic' ) );
629 function personal_urls( $itemTemplate ) {
630 global $wgShowIPinHeader, $wgContLang;
632 # Split this function up into many small functions, to obtain the
633 # best specificity in the dependencies of each one. The template below
634 # has no dependencies, so its generation, and any static subfunctions,
635 # can be optimised away.
636 $etpl = cbt_escape( $itemTemplate );
637 $s = "
638 {userpage {{$etpl}}}
639 {mytalk {{$etpl}}}
640 {preferences {{$etpl}}}
641 {watchlist {{$etpl}}}
642 {mycontris {{$etpl}}}
643 {logout {{$etpl}}}
646 if ( $wgShowIPinHeader ) {
647 $s .= "
648 {anonuserpage {{$etpl}}}
649 {anontalk {{$etpl}}}
650 {anonlogin {{$etpl}}}
652 } else {
653 $s .= "{login {{$etpl}}}\n";
655 // No dependencies
656 return cbt_value( $s, array(), true /*this is a template*/ );
659 function userpage( $itemTemplate ) {
660 global $wgUser;
661 if ( $this->isLoggedIn() ) {
662 $userPage = $this->getUserPageTitle();
663 $s = $this->makeTemplateLink( $itemTemplate, 'userpage', $userPage, $wgUser->getName() );
664 } else {
665 $s = '';
667 return cbt_value( $s, 'user' );
670 function mytalk( $itemTemplate ) {
671 global $wgUser;
672 if ( $this->isLoggedIn() ) {
673 $userPage = $this->getUserPageTitle();
674 $talkPage = $userPage->getTalkPage();
675 $s = $this->makeTemplateLink( $itemTemplate, 'mytalk', $talkPage, wfMsg('mytalk') );
676 } else {
677 $s = '';
679 return cbt_value( $s, 'user' );
682 function preferences( $itemTemplate ) {
683 if ( $this->isLoggedIn() ) {
684 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'preferences',
685 'Preferences', wfMsg( 'preferences' ) );
686 } else {
687 $s = '';
689 return cbt_value( $s, array( 'loggedin', 'lang' ) );
692 function watchlist( $itemTemplate ) {
693 if ( $this->isLoggedIn() ) {
694 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'watchlist',
695 'Watchlist', wfMsg( 'watchlist' ) );
696 } else {
697 $s = '';
699 return cbt_value( $s, array( 'loggedin', 'lang' ) );
702 function mycontris( $itemTemplate ) {
703 if ( $this->isLoggedIn() ) {
704 global $wgUser;
705 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'mycontris',
706 "Contributions/" . $wgUser->getTitleKey(), wfMsg('mycontris') );
707 } else {
708 $s = '';
710 return cbt_value( $s, 'user' );
713 function logout( $itemTemplate ) {
714 if ( $this->isLoggedIn() ) {
715 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'logout',
716 'Userlogout', wfMsg( 'userlogout' ),
717 $this->mTitle->getNamespace() === NS_SPECIAL && $this->mTitle->getText() === 'Preferences'
718 ? '' : "returnto=" . $this->mTitle->getPrefixedURL() );
719 } else {
720 $s = '';
722 return cbt_value( $s, 'loggedin dynamic' );
725 function anonuserpage( $itemTemplate ) {
726 if ( $this->isLoggedIn() ) {
727 $s = '';
728 } else {
729 global $wgUser;
730 $userPage = $this->getUserPageTitle();
731 $s = $this->makeTemplateLink( $itemTemplate, 'userpage', $userPage, $wgUser->getName() );
733 return cbt_value( $s, '!loggedin dynamic' );
736 function anontalk( $itemTemplate ) {
737 if ( $this->isLoggedIn() ) {
738 $s = '';
739 } else {
740 $userPage = $this->getUserPageTitle();
741 $talkPage = $userPage->getTalkPage();
742 $s = $this->makeTemplateLink( $itemTemplate, 'mytalk', $talkPage, wfMsg('anontalk') );
744 return cbt_value( $s, '!loggedin dynamic' );
747 function anonlogin( $itemTemplate ) {
748 if ( $this->isLoggedIn() ) {
749 $s = '';
750 } else {
751 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'anonlogin', 'Userlogin',
752 wfMsg( 'userlogin' ), 'returnto=' . urlencode( $this->getThisPDBK() ) );
754 return cbt_value( $s, '!loggedin dynamic' );
757 function login( $itemTemplate ) {
758 if ( $this->isLoggedIn() ) {
759 $s = '';
760 } else {
761 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'login', 'Userlogin',
762 wfMsg( 'userlogin' ), 'returnto=' . urlencode( $this->getThisPDBK() ) );
764 return cbt_value( $s, '!loggedin dynamic' );
767 function logopath() { return $GLOBALS['wgLogo']; }
768 function mainpage() { return $this->makeI18nUrl( 'mainpage' ); }
770 function sidebar( $startSection, $endSection, $innerTpl ) {
771 $s = '';
772 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
773 $firstSection = true;
774 foreach ($lines as $line) {
775 if (strpos($line, '*') !== 0)
776 continue;
777 if (strpos($line, '**') !== 0) {
778 $bar = trim($line, '* ');
779 $name = wfMsg( $bar );
780 if (wfEmptyMsg($bar, $name)) {
781 $name = $bar;
783 if ( $firstSection ) {
784 $firstSection = false;
785 } else {
786 $s .= $endSection;
788 $s .= strtr( $startSection,
789 array(
790 '$bar' => htmlspecialchars( $bar ),
791 '$barname' => $name
792 ) );
793 } else {
794 if (strpos($line, '|') !== false) { // sanity check
795 $line = explode( '|' , trim($line, '* '), 2 );
796 $link = wfMsgForContent( $line[0] );
797 if ($link == '-')
798 continue;
799 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
800 $text = $line[1];
801 if (wfEmptyMsg($line[0], $link))
802 $link = $line[0];
803 $href = $this->makeInternalOrExternalUrl( $link );
805 $s .= strtr( $innerTpl,
806 array(
807 '$text' => htmlspecialchars( $text ),
808 '$href' => htmlspecialchars( $href ),
809 '$id' => htmlspecialchars( 'n-' . strtr($line[1], ' ', '-') ),
810 '$classactive' => ''
811 ) );
812 } else { continue; }
815 if ( !$firstSection ) {
816 $s .= $endSection;
819 // Depends on user language only
820 return cbt_value( $s, 'lang' );
823 function searchaction() {
824 // Static link
825 return $this->getSearchLink();
828 function search() {
829 global $wgRequest;
830 return cbt_value( trim( $this->getSearch() ), 'special dynamic' );
833 function notspecialpage() {
834 return cbt_value( $this->mTitle->getNamespace() != NS_SPECIAL, 'special' );
837 function nav_whatlinkshere() {
838 return cbt_value( $this->makeSpecialParamUrl('Whatlinkshere' ), array(), true );
841 function article_exists() {
842 return cbt_value( (string)($this->mTitle->getArticleId() !== 0), 'title' );
845 function nav_recentchangeslinked() {
846 return cbt_value( $this->makeSpecialParamUrl('Recentchangeslinked' ), array(), true );
849 function feeds( $itemTemplate = '' ) {
850 if ( !$this->mOut->isSyndicated() ) {
851 $feeds = '';
852 } elseif ( $itemTemplate == '' ) {
853 // boolean only required
854 $feeds = 'true';
855 } else {
856 $feeds = '';
857 global $wgFeedClasses, $wgRequest;
858 foreach( $wgFeedClasses as $format => $class ) {
859 $feeds .= strtr( $itemTemplate,
860 array(
861 '$key' => htmlspecialchars( $format ),
862 '$text' => $format,
863 '$href' => $wgRequest->appendQuery( "feed=$format" )
864 ) );
867 return cbt_value( $feeds, 'special dynamic' );
870 function is_userpage() {
871 list( $id, $ip ) = $this->getUserPageIdIp();
872 return cbt_value( (string)($id || $ip), 'title' );
875 function is_ns_mediawiki() {
876 return cbt_value( (string)$this->mTitle->getNamespace() == NS_MEDIAWIKI, 'title' );
879 function is_loggedin() {
880 global $wgUser;
881 return cbt_value( (string)($wgUser->isLoggedIn()), 'loggedin' );
884 function nav_contributions() {
885 $url = $this->makeSpecialParamUrl( 'Contributions', '', '{title_userurl}' );
886 return cbt_value( $url, array(), true );
889 function is_allowed( $right ) {
890 global $wgUser;
891 return cbt_value( (string)$wgUser->isAllowed( $right ), 'user' );
894 function nav_blockip() {
895 $url = $this->makeSpecialParamUrl( 'Blockip', '', '{title_userurl}' );
896 return cbt_value( $url, array(), true );
899 function nav_emailuser() {
900 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
901 if ( !$wgEnableEmail || !$wgEnableUserEmail ) return '';
903 $url = $this->makeSpecialParamUrl( 'Emailuser', '', '{title_userurl}' );
904 return cbt_value( $url, array(), true );
907 function nav_upload() {
908 global $wgEnableUploads, $wgUploadNavigationUrl;
909 if ( !$wgEnableUploads ) {
910 return '';
911 } elseif ( $wgUploadNavigationUrl ) {
912 return $wgUploadNavigationUrl;
913 } else {
914 return $this->makeSpecialUrl('Upload');
918 function nav_specialpages() {
919 return $this->makeSpecialUrl('Specialpages');
922 function nav_print() {
923 global $wgRequest, $wgArticle;
924 $action = $this->getAction();
925 $url = '';
926 if( $this->mTitle->getNamespace() !== NS_SPECIAL
927 && ($action == '' || $action == 'view' || $action == 'purge' ) )
929 $revid = $wgArticle->getLatest();
930 if ( $revid != 0 ) {
931 $url = $wgRequest->appendQuery( 'printable=yes' );
934 return cbt_value( $url, array( 'nonview dynamic', 'title' ) );
937 function nav_permalink() {
938 $url = (string)$this->getPermalink();
939 return cbt_value( $url, 'dynamic' );
942 function nav_trackbacklink() {
943 global $wgUseTrackbacks;
944 if ( !$wgUseTrackbacks ) return '';
946 return cbt_value( $this->mTitle->trackbackURL(), 'title' );
949 function is_permalink() {
950 return cbt_value( (string)($this->getPermalink() === false), 'nonview dynamic' );
953 function toolboxend() {
954 // This is where the MonoBookTemplateToolboxEnd hook went in the old skin
955 return '';
958 function language_urls( $outer, $inner ) {
959 global $wgHideInterlanguageLinks, $wgOut, $wgContLang;
960 if ( $wgHideInterlanguageLinks ) return '';
962 $links = $wgOut->getLanguageLinks();
963 $s = '';
964 if ( count( $links ) ) {
965 foreach( $links as $l ) {
966 $tmp = explode( ':', $l, 2 );
967 $nt = Title::newFromText( $l );
968 $s .= strtr( $inner,
969 array(
970 '$class' => htmlspecialchars( 'interwiki-' . $tmp[0] ),
971 '$href' => htmlspecialchars( $nt->getFullURL() ),
972 '$text' => ($wgContLang->getLanguageName( $nt->getInterwiki() ) != ''?
973 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
977 $s = str_replace( '$body', $s, $outer );
979 return cbt_value( $s, 'dynamic' );
982 function poweredbyico() { return $this->getPoweredBy(); }
983 function copyrightico() { return $this->getCopyrightIcon(); }
985 function lastmod() {
986 global $wgMaxCredits;
987 if ( $wgMaxCredits ) return '';
989 if ( !isset( $this->mLastmod ) ) {
990 if ( $this->isCurrentArticleView() ) {
991 $this->mLastmod = $this->lastModified();
992 } else {
993 $this->mLastmod = '';
996 return cbt_value( $this->mLastmod, 'dynamic' );
999 function viewcount() {
1000 global $wgDisableCounters;
1001 if ( $wgDisableCounters ) return '';
1003 global $wgLang, $wgArticle;
1004 if ( is_object( $wgArticle ) ) {
1005 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
1006 if ( $viewcount ) {
1007 $viewcount = wfMsg( "viewcount", $viewcount );
1008 } else {
1009 $viewcount = '';
1011 } else {
1012 $viewcount = '';
1014 return cbt_value( $viewcount, 'dynamic' );
1017 function numberofwatchingusers() {
1018 global $wgPageShowWatchingUsers;
1019 if ( !$wgPageShowWatchingUsers ) return '';
1021 $dbr =& wfGetDB( DB_SLAVE );
1022 extract( $dbr->tableNames( 'watchlist' ) );
1023 $sql = "SELECT COUNT(*) AS n FROM $watchlist
1024 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBKey()) .
1025 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
1026 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
1027 $row = $dbr->fetchObject( $res );
1028 $num = $row->n;
1029 if ($num > 0) {
1030 $s = wfMsg('number_of_watching_users_pageview', $num);
1031 } else {
1032 $s = '';
1034 return cbt_value( $s, 'dynamic' );
1037 function credits() {
1038 global $wgMaxCredits;
1039 if ( !$wgMaxCredits ) return '';
1041 if ( $this->isCurrentArticleView() ) {
1042 require_once("Credits.php");
1043 global $wgArticle, $wgShowCreditsIfMax;
1044 $credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
1045 } else {
1046 $credits = '';
1048 return cbt_value( $credits, 'view dynamic' );
1051 function normalcopyright() {
1052 return $this->getCopyright( 'normal' );
1055 function historycopyright() {
1056 return $this->getCopyright( 'history' );
1059 function is_currentview() {
1060 global $wgRequest;
1061 return cbt_value( (string)$this->isCurrentArticleView(), 'view' );
1064 function usehistorycopyright() {
1065 global $wgRequest;
1066 if ( wfMsgForContent( 'history_copyright' ) == '-' ) return '';
1068 $oldid = $this->getOldId();
1069 $diff = $this->getDiff();
1070 $use = (string)(!is_null( $oldid ) && is_null( $diff ));
1071 return cbt_value( $use, 'nonview dynamic' );
1074 function privacy() {
1075 return cbt_value( $this->privacyLink(), 'lang' );
1077 function about() {
1078 return cbt_value( $this->aboutLink(), 'lang' );
1080 function disclaimer() {
1081 return cbt_value( $this->disclaimerLink(), 'lang' );
1083 function tagline() {
1084 # A reference to this tag existed in the old MonoBook.php, but the
1085 # template data wasn't set anywhere
1086 return '';
1088 function reporttime() {
1089 return cbt_value( $this->mOut->reportTime(), 'dynamic' );
1092 function msg( $name ) {
1093 return cbt_value( wfMsg( $name ), 'lang' );
1096 function fallbackmsg( $name, $fallback ) {
1097 $text = wfMsg( $name );
1098 if ( wfEmptyMsg( $name, $text ) ) {
1099 $text = $fallback;
1101 return cbt_value( $text, 'lang' );
1104 /******************************************************
1105 * Utility functions *
1106 ******************************************************/
1108 /** Return true if this request is a valid, secure CSS preview */
1109 function isCssPreview() {
1110 if ( !isset( $this->mCssPreview ) ) {
1111 global $wgRequest, $wgAllowUserCss, $wgUser;
1112 $this->mCssPreview =
1113 $wgAllowUserCss &&
1114 $wgUser->isLoggedIn() &&
1115 $this->mTitle->isCssSubpage() &&
1116 $this->userCanPreview( $this->getAction() );
1118 return $this->mCssPreview;
1121 /** Return true if this request is a valid, secure JS preview */
1122 function isJsPreview() {
1123 if ( !isset( $this->mJsPreview ) ) {
1124 global $wgRequest, $wgAllowUserJs, $wgUser;
1125 $this->mJsPreview =
1126 $wgAllowUserJs &&
1127 $wgUser->isLoggedIn() &&
1128 $this->mTitle->isJsSubpage() &&
1129 $this->userCanPreview( $this->getAction() );
1131 return $this->mJsPreview;
1134 /** Get the title of the $wgUser's user page */
1135 function getUserPageTitle() {
1136 if ( !isset( $this->mUserPageTitle ) ) {
1137 global $wgUser;
1138 $this->mUserPageTitle = $wgUser->getUserPage();
1140 return $this->mUserPageTitle;
1143 /** Get the text of the user page title */
1144 function getUserPageText() {
1145 if ( !isset( $this->mUserPageText ) ) {
1146 $userPage = $this->getUserPageTitle();
1147 $this->mUserPageText = $userPage->getPrefixedText();
1149 return $this->mUserPageText;
1152 /** Make an HTML element for a stylesheet link */
1153 function makeStylesheetLink( $url ) {
1154 return '<link rel="stylesheet" type="text/css" href="' . htmlspecialchars( $url ) . "\"/>";
1157 /** Make an XHTML element for inline CSS */
1158 function makeStylesheetCdata( $style ) {
1159 return "<style type=\"text/css\"> /*<![CDATA[*/ {$style} /*]]>*/ </style>";
1162 /** Get the edit URL for this page */
1163 function getEditUrl() {
1164 if ( !isset( $this->mEditUrl ) ) {
1165 $this->mEditUrl = $this->mTitle->getLocalUrl( $this->editUrlOptions() );
1167 return $this->mEditUrl;
1170 /** Get the prefixed DB key for this page */
1171 function getThisPDBK() {
1172 if ( !isset( $this->mThisPDBK ) ) {
1173 $this->mThisPDBK = $this->mTitle->getPrefixedDbKey();
1175 return $this->mThisPDBK;
1178 function getThisTitleUrlForm() {
1179 if ( !isset( $this->mThisTitleUrlForm ) ) {
1180 $this->mThisTitleUrlForm = $this->mTitle->getPrefixedURL();
1182 return $this->mThisTitleUrlForm;
1185 /**
1186 * If the current page is a user page, get the user's ID and IP. Otherwise return array(0,false)
1188 function getUserPageIdIp() {
1189 if ( !isset( $this->mUserPageId ) ) {
1190 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
1191 $this->mUserPageId = User::idFromName($this->mTitle->getText());
1192 $this->mUserPageIp = User::isIP($this->mTitle->getText());
1193 } else {
1194 $this->mUserPageId = 0;
1195 $this->mUserPageIp = false;
1198 return array( $this->mUserPageId, $this->mUserPageIp );
1202 * Returns a permalink URL, or false if the current page is already a
1203 * permalink, or blank if a permalink shouldn't be displayed
1205 function getPermalink() {
1206 if ( !isset( $this->mPermalink ) ) {
1207 global $wgRequest, $wgArticle;
1208 $action = $this->getAction();
1209 $oldid = $this->getOldId();
1210 $url = '';
1211 if( $this->mTitle->getNamespace() !== NS_SPECIAL
1212 && $this->mTitle->getArticleId() != 0
1213 && ($action == '' || $action == 'view' || $action == 'purge' ) )
1215 if ( !$oldid ) {
1216 $revid = $wgArticle->getLatest();
1217 $url = $this->mTitle->getLocalURL( "oldid=$revid" );
1218 } else {
1219 $url = false;
1221 } else {
1222 $url = '';
1225 return $url;
1229 * Returns true if the current page is an article, not a special page,
1230 * and we are viewing a revision, not a diff
1232 function isArticleView() {
1233 global $wgOut, $wgArticle, $wgRequest;
1234 if ( !isset( $this->mIsArticleView ) ) {
1235 $oldid = $this->getOldId();
1236 $diff = $this->getDiff();
1237 $this->mIsArticleView = $wgOut->isArticle() and
1238 (!is_null( $oldid ) or is_null( $diff )) and 0 != $wgArticle->getID();
1240 return $this->mIsArticleView;
1243 function isCurrentArticleView() {
1244 if ( !isset( $this->mIsCurrentArticleView ) ) {
1245 global $wgOut, $wgArticle, $wgRequest;
1246 $oldid = $this->getOldId();
1247 $this->mIsCurrentArticleView = $wgOut->isArticle() && is_null( $oldid ) && 0 != $wgArticle->getID();
1249 return $this->mIsCurrentArticleView;
1254 * Return true if the current page is editable; if edit section on right
1255 * click should be enabled.
1257 function isEditable() {
1258 global $wgRequest;
1259 $action = $this->getAction();
1260 return ($this->mTitle->getNamespace() != NS_SPECIAL and !($action == 'edit' or $action == 'submit'));
1263 /** Return true if the user is logged in */
1264 function isLoggedIn() {
1265 global $wgUser;
1266 return $wgUser->isLoggedIn();
1269 /** Get the local URL of the current page */
1270 function getPageUrl() {
1271 if ( !isset( $this->mPageUrl ) ) {
1272 $this->mPageUrl = $this->mTitle->getLocalURL();
1274 return $this->mPageUrl;
1277 /** Make a link to a title using a template */
1278 function makeTemplateLink( $template, $key, $title, $text ) {
1279 $url = $title->getLocalUrl();
1280 return strtr( $template,
1281 array(
1282 '$key' => $key,
1283 '$classactive' => ($url == $this->getPageUrl()) ? 'class="active"' : '',
1284 '$class' => $title->getArticleID() == 0 ? 'class="new"' : '',
1285 '$href' => htmlspecialchars( $url ),
1286 '$text' => $text
1287 ) );
1290 /** Make a link to a URL using a template */
1291 function makeTemplateLinkUrl( $template, $key, $url, $text ) {
1292 return strtr( $template,
1293 array(
1294 '$key' => $key,
1295 '$classactive' => ($url == $this->getPageUrl()) ? 'class="active"' : '',
1296 '$class' => '',
1297 '$href' => htmlspecialchars( $url ),
1298 '$text' => $text
1299 ) );
1302 /** Make a link to a special page using a template */
1303 function makeSpecialTemplateLink( $template, $key, $specialName, $text, $query = '' ) {
1304 $url = $this->makeSpecialUrl( $specialName, $query );
1305 // Ignore the query when comparing
1306 $active = ($this->mTitle->getNamespace() == NS_SPECIAL && $this->mTitle->getDBkey() == $specialName);
1307 return strtr( $template,
1308 array(
1309 '$key' => $key,
1310 '$classactive' => $active ? 'class="active"' : '',
1311 '$class' => '',
1312 '$href' => htmlspecialchars( $url ),
1313 '$text' => $text
1314 ) );
1317 function loadRequestValues() {
1318 global $wgRequest;
1319 $this->mAction = $wgRequest->getText( 'action' );
1320 $this->mOldId = $wgRequest->getVal( 'oldid' );
1321 $this->mDiff = $wgRequest->getVal( 'diff' );
1322 $this->mSection = $wgRequest->getVal( 'section' );
1323 $this->mSearch = $wgRequest->getVal( 'search' );
1324 $this->mRequestValuesLoaded = true;
1329 /** Get the action parameter of the request */
1330 function getAction() {
1331 if ( !isset( $this->mRequestValuesLoaded ) ) {
1332 $this->loadRequestValues();
1334 return $this->mAction;
1337 /** Get the oldid parameter */
1338 function getOldId() {
1339 if ( !isset( $this->mRequestValuesLoaded ) ) {
1340 $this->loadRequestValues();
1342 return $this->mOldId;
1345 /** Get the diff parameter */
1346 function getDiff() {
1347 if ( !isset( $this->mRequestValuesLoaded ) ) {
1348 $this->loadRequestValues();
1350 return $this->mDiff;
1353 function getSection() {
1354 if ( !isset( $this->mRequestValuesLoaded ) ) {
1355 $this->loadRequestValues();
1357 return $this->mSection;
1360 function getSearch() {
1361 if ( !isset( $this->mRequestValuesLoaded ) ) {
1362 $this->loadRequestValues();
1364 return $this->mSearch;
1367 /** Make a special page URL of the form [[Special:Somepage/{title_urlform}]] */
1368 function makeSpecialParamUrl( $name, $query = '', $param = '{title_urlform}' ) {
1369 // Abuse makeTitle's lax validity checking to slip a control character into the URL
1370 $title = Title::makeTitle( NS_SPECIAL, "$name/\x1a" );
1371 $url = cbt_escape( $title->getLocalURL( $query ) );
1372 // Now replace it with the parameter
1373 return str_replace( '%1A', $param, $url );
1376 function getSubjectPage() {
1377 if ( !isset( $this->mSubjectPage ) ) {
1378 $this->mSubjectPage = $this->mTitle->getSubjectPage();
1380 return $this->mSubjectPage;
1383 function getTalkPage() {
1384 if ( !isset( $this->mTalkPage ) ) {
1385 $this->mTalkPage = $this->mTitle->getTalkPage();
1387 return $this->mTalkPage;