00001 <?php
00002
00003 if ( !defined( 'MEDIAWIKI' ) ) {
00004 die( "This file is part of MediaWiki, it is not a valid entry point\n" );
00005 }
00006
00007 require_once( 'includes/cbt/CBTProcessor.php' );
00008 require_once( 'includes/cbt/CBTCompiler.php' );
00009 require_once( 'includes/SkinTemplate.php' );
00010
00032 class SkinMonoBookCBT extends SkinTemplate {
00033 var $mOut, $mTitle;
00034 var $mStyleName = 'monobook';
00035 var $mCompiling = false;
00036 var $mFunctionCache = array();
00037
00038
00039
00040
00041
00043 function outputPage( &$out ) {
00044 echo $this->execute( $out );
00045 }
00046
00047 function execute( &$out ) {
00048 global $wgTitle, $wgStyleDirectory, $wgParserCacheType;
00049 $fname = 'SkinMonoBookCBT::execute';
00050 wfProfileIn( $fname );
00051 wfProfileIn( "$fname-setup" );
00052 Skin::initPage( $out );
00053
00054 $this->mOut =& $out;
00055 $this->mTitle =& $wgTitle;
00056
00057 $sourceFile = "$wgStyleDirectory/MonoBook.tpl";
00058
00059 wfProfileOut( "$fname-setup" );
00060
00061 if ( $wgParserCacheType == CACHE_NONE ) {
00062 $template = file_get_contents( $sourceFile );
00063 $text = $this->executeTemplate( $template );
00064 } else {
00065 $compiled = $this->getCompiledTemplate( $sourceFile );
00066
00067 wfProfileIn( "$fname-eval" );
00068 $text = eval( $compiled );
00069 wfProfileOut( "$fname-eval" );
00070 }
00071 wfProfileOut( $fname );
00072 return $text;
00073 }
00074
00075 function getCompiledTemplate( $sourceFile ) {
00076 global $wgDBname, $wgMemc, $wgRequest, $wgUser, $parserMemc;
00077 $fname = 'SkinMonoBookCBT::getCompiledTemplate';
00078
00079 $expiry = 3600;
00080
00081
00082 if ( $this->mCompiling ) {
00083 return;
00084 }
00085
00086 wfProfileIn( $fname );
00087
00088
00089 if ( $wgRequest->wasPosted() ||
00090 count( array_diff( array_keys( $_GET ), array( 'title', 'useskin', 'recompile' ) ) ) != 0 )
00091 {
00092 $type = 'nonview';
00093 } else {
00094 $type = 'view';
00095 }
00096
00097
00098
00099 $cacheKey = "$wgDBname:monobookcbt:$type:" . $wgUser->getId();
00100
00101 $recompile = $wgRequest->getVal( 'recompile' );
00102 if ( $recompile == 'user' ) {
00103 $recompileUser = true;
00104 $recompileGeneric = false;
00105 } elseif ( $recompile ) {
00106 $recompileUser = true;
00107 $recompileGeneric = true;
00108 } else {
00109 $recompileUser = false;
00110 $recompileGeneric = false;
00111 }
00112
00113 if ( !$recompileUser ) {
00114 $php = $parserMemc->get( $cacheKey );
00115 }
00116 if ( $recompileUser || !$php ) {
00117 if ( $wgUser->isLoggedIn() ) {
00118
00119
00120 $genericKey = "$wgDBname:monobookcbt:$type:loggedin";
00121 if ( !$recompileGeneric ) {
00122 $template = $parserMemc->get( $genericKey );
00123 }
00124 if ( $recompileGeneric || !$template ) {
00125 $template = file_get_contents( $sourceFile );
00126 $ignore = array( 'loggedin', '!loggedin dynamic' );
00127 if ( $type == 'view' ) {
00128 $ignore[] = 'nonview dynamic';
00129 }
00130 $template = $this->compileTemplate( $template, $ignore );
00131 $parserMemc->set( $genericKey, $template, $expiry );
00132 }
00133 } else {
00134 $template = file_get_contents( $sourceFile );
00135 }
00136
00137 $ignore = array( 'lang', 'loggedin', 'user' );
00138 if ( $wgUser->isLoggedIn() ) {
00139 $ignore[] = '!loggedin dynamic';
00140 } else {
00141 $ignore[] = 'loggedin dynamic';
00142 }
00143 if ( $type == 'view' ) {
00144 $ignore[] = 'nonview dynamic';
00145 }
00146 $compiled = $this->compileTemplate( $template, $ignore );
00147
00148
00149
00150
00151 $compiled = preg_replace( '/^[ \t]+/m', '', $compiled );
00152 $compiled = preg_replace( '/[\r\n]+/', "\n", $compiled );
00153
00154
00155 $compiler = new CBTCompiler( $compiled );
00156 $ret = $compiler->compile();
00157 if ( $ret !== true ) {
00158 echo $ret;
00159 wfErrorExit();
00160 }
00161 $php = $compiler->generatePHP( '$this' );
00162
00163 $parserMemc->set( $cacheKey, $php, $expiry );
00164 }
00165 wfProfileOut( $fname );
00166 return $php;
00167 }
00168
00169 function compileTemplate( $template, $ignore ) {
00170 $tp = new CBTProcessor( $template, $this, $ignore );
00171 $tp->mFunctionCache = $this->mFunctionCache;
00172
00173 $this->mCompiling = true;
00174 $compiled = $tp->compile();
00175 $this->mCompiling = false;
00176
00177 if ( $tp->getLastError() ) {
00178
00179
00180 echo $compiled;
00181 wfErrorExit();
00182 }
00183 $this->mFunctionCache = $tp->mFunctionCache;
00184 return $compiled;
00185 }
00186
00187 function executeTemplate( $template ) {
00188 $fname = 'SkinMonoBookCBT::executeTemplate';
00189 wfProfileIn( $fname );
00190 $tp = new CBTProcessor( $template, $this );
00191 $tp->mFunctionCache = $this->mFunctionCache;
00192
00193 $this->mCompiling = true;
00194 $text = $tp->execute();
00195 $this->mCompiling = false;
00196
00197 $this->mFunctionCache = $tp->mFunctionCache;
00198 wfProfileOut( $fname );
00199 return $text;
00200 }
00201
00202
00203
00204
00205
00206 function lang() { return $GLOBALS['wgContLanguageCode']; }
00207
00208 function dir() {
00209 global $wgContLang;
00210 return $wgContLang->isRTL() ? 'rtl' : 'ltr';
00211 }
00212
00213 function mimetype() { return $GLOBALS['wgMimeType']; }
00214 function charset() { return $GLOBALS['wgOutputEncoding']; }
00215 function headlinks() {
00216 return cbt_value( $this->mOut->getHeadLinks(), 'dynamic' );
00217 }
00218 function headscripts() {
00219 return cbt_value( $this->mOut->getScript(), 'dynamic' );
00220 }
00221
00222 function pagetitle() {
00223 return cbt_value( $this->mOut->getHTMLTitle(), array( 'title', 'lang' ) );
00224 }
00225
00226 function stylepath() { return $GLOBALS['wgStylePath']; }
00227 function stylename() { return $this->mStyleName; }
00228
00229 function notprintable() {
00230 global $wgRequest;
00231 return cbt_value( !$wgRequest->getBool( 'printable' ), 'nonview dynamic' );
00232 }
00233
00234 function jsmimetype() { return $GLOBALS['wgJsMimeType']; }
00235
00236 function jsvarurl() {
00237 global $wgUseSiteJs, $wgUser;
00238 if ( !$wgUseSiteJs ) return '';
00239
00240 if ( $wgUser->isLoggedIn() ) {
00241 $url = self::makeUrl( '-','action=raw&smaxage=0&gen=js' );
00242 } else {
00243 $url = self::makeUrl( '-','action=raw&gen=js' );
00244 }
00245 return cbt_value( $url, 'loggedin' );
00246 }
00247
00248 function pagecss() {
00249 global $wgHooks;
00250
00251 $out = false;
00252 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
00253
00254
00255 return cbt_value( $out, 'dynamic' );
00256 }
00257
00258 function usercss() {
00259 if ( $this->isCssPreview() ) {
00260 global $wgRequest;
00261 $usercss = $this->makeStylesheetCdata( $wgRequest->getText('wpTextbox1') );
00262 } else {
00263 $usercss = $this->makeStylesheetLink( self::makeUrl($this->getUserPageText() .
00264 '/'.$this->mStyleName.'.css', 'action=raw&ctype=text/css' ) );
00265 }
00266
00267
00268 return cbt_value( $usercss, array( 'nonview dynamic', 'user' ) );
00269 }
00270
00271 function sitecss() {
00272 global $wgUseSiteCss;
00273 if ( !$wgUseSiteCss ) {
00274 return '';
00275 }
00276
00277 global $wgSquidMaxage, $wgContLang, $wgStylePath;
00278
00279 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
00280
00281 $sitecss = '';
00282 if ( $wgContLang->isRTL() ) {
00283 $sitecss .= $this->makeStylesheetLink( $wgStylePath . '/' . $this->mStyleName . '/rtl.css' ) . "\n";
00284 }
00285
00286 $sitecss .= $this->makeStylesheetLink( self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) ) . "\n";
00287 $sitecss .= $this->makeStylesheetLink( self::makeNSUrl( ucfirst( $this->mStyleName ) . '.css', $query, NS_MEDIAWIKI ) ) . "\n";
00288
00289
00290 return $sitecss;
00291 }
00292
00293 function gencss() {
00294 global $wgUseSiteCss;
00295 if ( !$wgUseSiteCss ) return '';
00296
00297 global $wgSquidMaxage, $wgUser, $wgAllowUserCss;
00298 if ( $this->isCssPreview() ) {
00299 $siteargs = '&smaxage=0&maxage=0';
00300 } else {
00301 $siteargs = '&maxage=' . $wgSquidMaxage;
00302 }
00303 if ( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
00304 $siteargs .= '&ts={user_touched}';
00305 $isTemplate = true;
00306 } else {
00307 $isTemplate = false;
00308 }
00309
00310 $link = $this->makeStylesheetLink( self::makeUrl('-','action=raw&gen=css' . $siteargs) ) . "\n";
00311
00312 if ( $wgAllowUserCss ) {
00313 $deps = 'loggedin';
00314 } else {
00315 $deps = array();
00316 }
00317 return cbt_value( $link, $deps, $isTemplate );
00318 }
00319
00320 function user_touched() {
00321 global $wgUser;
00322 return cbt_value( $wgUser->mTouched, 'dynamic' );
00323 }
00324
00325 function userjs() {
00326 global $wgAllowUserJs, $wgJsMimeType;
00327 if ( !$wgAllowUserJs ) return '';
00328
00329 if ( $this->isJsPreview() ) {
00330 $url = '';
00331 } else {
00332 $url = self::makeUrl($this->getUserPageText().'/'.$this->mStyleName.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
00333 }
00334 return cbt_value( $url, array( 'nonview dynamic', 'user' ) );
00335 }
00336
00337 function userjsprev() {
00338 global $wgAllowUserJs, $wgRequest;
00339 if ( !$wgAllowUserJs ) return '';
00340 if ( $this->isJsPreview() ) {
00341 $js = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
00342 } else {
00343 $js = '';
00344 }
00345 return cbt_value( $js, array( 'nonview dynamic' ) );
00346 }
00347
00348 function trackbackhtml() {
00349 global $wgUseTrackbacks;
00350 if ( !$wgUseTrackbacks ) return '';
00351
00352 if ( $this->mOut->isArticleRelated() ) {
00353 $tb = $this->mTitle->trackbackRDF();
00354 } else {
00355 $tb = '';
00356 }
00357 return cbt_value( $tb, 'dynamic' );
00358 }
00359
00360 function body_ondblclick() {
00361 global $wgUser;
00362 if( $this->isEditable() && $wgUser->getOption("editondblclick") ) {
00363 $js = 'document.location = "' . $this->getEditUrl() .'";';
00364 } else {
00365 $js = '';
00366 }
00367
00368 if ( User::getDefaultOption('editondblclick') ) {
00369 return cbt_value( $js, 'user', 'title' );
00370 } else {
00371
00372 return cbt_value( $js, 'loggedin dynamic' );
00373 }
00374 }
00375
00376 function body_onload() {
00377 global $wgUser;
00378 if ( $this->isEditable() && $wgUser->getOption( 'editsectiononrightclick' ) ) {
00379 $js = 'setupRightClickEdit()';
00380 } else {
00381 $js = '';
00382 }
00383 return cbt_value( $js, 'loggedin dynamic' );
00384 }
00385
00386 function nsclass() {
00387 return cbt_value( 'ns-' . $this->mTitle->getNamespace(), 'title' );
00388 }
00389
00390 function sitenotice() {
00391
00392
00393 return cbt_value( wfGetSiteNotice(), 'dynamic' );
00394 }
00395
00396 function title() {
00397 return cbt_value( $this->mOut->getPageTitle(), array( 'title', 'lang' ) );
00398 }
00399
00400 function title_urlform() {
00401 return cbt_value( $this->getThisTitleUrlForm(), 'title' );
00402 }
00403
00404 function title_userurl() {
00405 return cbt_value( urlencode( $this->mTitle->getDBkey() ), 'title' );
00406 }
00407
00408 function subtitle() {
00409 $subpagestr = $this->subPageSubtitle();
00410 if ( !empty( $subpagestr ) ) {
00411 $s = '<span class="subpages">'.$subpagestr.'</span>'.$this->mOut->getSubtitle();
00412 } else {
00413 $s = $this->mOut->getSubtitle();
00414 }
00415 return cbt_value( $s, array( 'title', 'nonview dynamic' ) );
00416 }
00417
00418 function undelete() {
00419 return cbt_value( $this->getUndeleteLink(), array( 'title', 'lang' ) );
00420 }
00421
00422 function newtalk() {
00423 global $wgUser, $wgDBname;
00424 $newtalks = $wgUser->getNewMessageLinks();
00425
00426 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === $wgDBname) {
00427 $usertitle = $this->getUserPageTitle();
00428 $usertalktitle = $usertitle->getTalkPage();
00429 if( !$usertalktitle->equals( $this->mTitle ) ) {
00430 $ntl = wfMsg( 'youhavenewmessages',
00431 $this->makeKnownLinkObj(
00432 $usertalktitle,
00433 wfMsgHtml( 'newmessageslink' ),
00434 'redirect=no'
00435 ),
00436 $this->makeKnownLinkObj(
00437 $usertalktitle,
00438 wfMsgHtml( 'newmessagesdifflink' ),
00439 'diff=cur'
00440 )
00441 );
00442 # Disable Cache
00443 $this->mOut->setSquidMaxage(0);
00444 }
00445 } else if (count($newtalks)) {
00446 $sep = str_replace("_", " ", wfMsgHtml("newtalkseparator"));
00447 $msgs = array();
00448 foreach ($newtalks as $newtalk) {
00449 $msgs[] = wfElement("a",
00450 array('href' => $newtalk["link"]), $newtalk["wiki"]);
00451 }
00452 $parts = implode($sep, $msgs);
00453 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
00454 $this->mOut->setSquidMaxage(0);
00455 } else {
00456 $ntl = '';
00457 }
00458 return cbt_value( $ntl, 'dynamic' );
00459 }
00460
00461 function showjumplinks() {
00462 global $wgUser;
00463 return cbt_value( $wgUser->getOption( 'showjumplinks' ) ? 'true' : '', 'user' );
00464 }
00465
00466 function bodytext() {
00467 return cbt_value( $this->mOut->getHTML(), 'dynamic' );
00468 }
00469
00470 function catlinks() {
00471 if ( !isset( $this->mCatlinks ) ) {
00472 $this->mCatlinks = $this->getCategories();
00473 }
00474 return cbt_value( $this->mCatlinks, 'dynamic' );
00475 }
00476
00477 function extratabs( $itemTemplate ) {
00478 global $wgContLang, $wgDisableLangConversion;
00479
00480 $etpl = cbt_escape( $itemTemplate );
00481
00482
00483 $variants = $wgContLang->getVariants();
00484 $s = '';
00485 if ( !$wgDisableLangConversion && count( $wgContLang->getVariants() ) > 1 ) {
00486 $vcount=0;
00487 foreach ( $variants as $code ) {
00488 $name = $wgContLang->getVariantname( $code );
00489 if ( $name == 'disable' ) {
00490 continue;
00491 }
00492 $code = cbt_escape( $code );
00493 $name = cbt_escape( $name );
00494 $s .= "{ca_variant {{$code}} {{$name}} {{$vcount}} {{$etpl}}}\n";
00495 $vcount ++;
00496 }
00497 }
00498 return cbt_value( $s, array(), true );
00499 }
00500
00501 function is_special() { return cbt_value( $this->mTitle->getNamespace() == NS_SPECIAL, 'title' ); }
00502 function can_edit() { return cbt_value( (string)($this->mTitle->userCan( 'edit' )), 'dynamic' ); }
00503 function can_move() { return cbt_value( (string)($this->mTitle->userCan( 'move' )), 'dynamic' ); }
00504 function is_talk() { return cbt_value( (string)($this->mTitle->isTalkPage()), 'title' ); }
00505 function is_protected() { return cbt_value( (string)$this->mTitle->isProtected(), 'dynamic' ); }
00506 function nskey() { return cbt_value( $this->mTitle->getNamespaceKey(), 'title' ); }
00507
00508 function request_url() {
00509 global $wgRequest;
00510 return cbt_value( $wgRequest->getRequestURL(), 'dynamic' );
00511 }
00512
00513 function subject_url() {
00514 $title = $this->getSubjectPage();
00515 if ( $title->exists() ) {
00516 $url = $title->getLocalUrl();
00517 } else {
00518 $url = $title->getLocalUrl( 'action=edit' );
00519 }
00520 return cbt_value( $url, 'title' );
00521 }
00522
00523 function talk_url() {
00524 $title = $this->getTalkPage();
00525 if ( $title->exists() ) {
00526 $url = $title->getLocalUrl();
00527 } else {
00528 $url = $title->getLocalUrl( 'action=edit' );
00529 }
00530 return cbt_value( $url, 'title' );
00531 }
00532
00533 function edit_url() {
00534 return cbt_value( $this->getEditUrl(), array( 'title', 'nonview dynamic' ) );
00535 }
00536
00537 function move_url() {
00538 return cbt_value( $this->makeSpecialParamUrl( 'Movepage' ), array(), true );
00539 }
00540
00541 function localurl( $query ) {
00542 return cbt_value( $this->mTitle->getLocalURL( $query ), 'title' );
00543 }
00544
00545 function selecttab( $tab, $extraclass = '' ) {
00546 if ( !isset( $this->mSelectedTab ) ) {
00547 $prevent_active_tabs = false ;
00548 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$preventActiveTabs ) );
00549
00550 $actionTabs = array(
00551 'edit' => 'edit',
00552 'submit' => 'edit',
00553 'history' => 'history',
00554 'protect' => 'protect',
00555 'unprotect' => 'protect',
00556 'delete' => 'delete',
00557 'watch' => 'watch',
00558 'unwatch' => 'watch',
00559 );
00560 if ( $preventActiveTabs ) {
00561 $this->mSelectedTab = false;
00562 } else {
00563 $action = $this->getAction();
00564 $section = $this->getSection();
00565
00566 if ( isset( $actionTabs[$action] ) ) {
00567 $this->mSelectedTab = $actionTabs[$action];
00568
00569 if ( $this->mSelectedTab == 'edit' && $section == 'new' ) {
00570 $this->mSelectedTab = 'addsection';
00571 }
00572 } elseif ( $this->mTitle->isTalkPage() ) {
00573 $this->mSelectedTab = 'talk';
00574 } else {
00575 $this->mSelectedTab = 'subject';
00576 }
00577 }
00578 }
00579 if ( $extraclass ) {
00580 if ( $this->mSelectedTab == $tab ) {
00581 $s = 'class="selected ' . htmlspecialchars( $extraclass ) . '"';
00582 } else {
00583 $s = 'class="' . htmlspecialchars( $extraclass ) . '"';
00584 }
00585 } else {
00586 if ( $this->mSelectedTab == $tab ) {
00587 $s = 'class="selected"';
00588 } else {
00589 $s = '';
00590 }
00591 }
00592 return cbt_value( $s, array( 'nonview dynamic', 'title' ) );
00593 }
00594
00595 function subject_newclass() {
00596 $title = $this->getSubjectPage();
00597 $class = $title->exists() ? '' : 'new';
00598 return cbt_value( $class, 'dynamic' );
00599 }
00600
00601 function talk_newclass() {
00602 $title = $this->getTalkPage();
00603 $class = $title->exists() ? '' : 'new';
00604 return cbt_value( $class, 'dynamic' );
00605 }
00606
00607 function ca_variant( $code, $name, $index, $template ) {
00608 global $wgContLang;
00609 $selected = ($code == $wgContLang->getPreferredVariant());
00610 $action = $this->getAction();
00611 $actstr = '';
00612 if( $action )
00613 $actstr = 'action=' . $action . '&';
00614 $s = strtr( $template, array(
00615 '$id' => htmlspecialchars( 'varlang-' . $index ),
00616 '$class' => $selected ? 'class="selected"' : '',
00617 '$text' => $name,
00618 '$href' => htmlspecialchars( $this->mTitle->getLocalUrl( $actstr . 'variant=' . $code ) )
00619 ));
00620 return cbt_value( $s, 'dynamic' );
00621 }
00622
00623 function is_watching() {
00624 return cbt_value( (string)$this->mTitle->userIsWatching(), array( 'dynamic' ) );
00625 }
00626
00627
00628 function personal_urls( $itemTemplate ) {
00629 global $wgShowIPinHeader, $wgContLang;
00630
00631 # Split this function up into many small functions, to obtain the
00632 # best specificity in the dependencies of each one. The template below
00633 # has no dependencies, so its generation, and any static subfunctions,
00634 # can be optimised away.
00635 $etpl = cbt_escape( $itemTemplate );
00636 $s = "
00637 {userpage {{$etpl}}}
00638 {mytalk {{$etpl}}}
00639 {preferences {{$etpl}}}
00640 {watchlist {{$etpl}}}
00641 {mycontris {{$etpl}}}
00642 {logout {{$etpl}}}
00643 ";
00644
00645 if ( $wgShowIPinHeader ) {
00646 $s .= "
00647 {anonuserpage {{$etpl}}}
00648 {anontalk {{$etpl}}}
00649 {anonlogin {{$etpl}}}
00650 ";
00651 } else {
00652 $s .= "{login {{$etpl}}}\n";
00653 }
00654
00655 return cbt_value( $s, array(), true );
00656 }
00657
00658 function userpage( $itemTemplate ) {
00659 global $wgUser;
00660 if ( $this->isLoggedIn() ) {
00661 $userPage = $this->getUserPageTitle();
00662 $s = $this->makeTemplateLink( $itemTemplate, 'userpage', $userPage, $wgUser->getName() );
00663 } else {
00664 $s = '';
00665 }
00666 return cbt_value( $s, 'user' );
00667 }
00668
00669 function mytalk( $itemTemplate ) {
00670 global $wgUser;
00671 if ( $this->isLoggedIn() ) {
00672 $userPage = $this->getUserPageTitle();
00673 $talkPage = $userPage->getTalkPage();
00674 $s = $this->makeTemplateLink( $itemTemplate, 'mytalk', $talkPage, wfMsg('mytalk') );
00675 } else {
00676 $s = '';
00677 }
00678 return cbt_value( $s, 'user' );
00679 }
00680
00681 function preferences( $itemTemplate ) {
00682 if ( $this->isLoggedIn() ) {
00683 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'preferences',
00684 'Preferences', wfMsg( 'preferences' ) );
00685 } else {
00686 $s = '';
00687 }
00688 return cbt_value( $s, array( 'loggedin', 'lang' ) );
00689 }
00690
00691 function watchlist( $itemTemplate ) {
00692 if ( $this->isLoggedIn() ) {
00693 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'watchlist',
00694 'Watchlist', wfMsg( 'watchlist' ) );
00695 } else {
00696 $s = '';
00697 }
00698 return cbt_value( $s, array( 'loggedin', 'lang' ) );
00699 }
00700
00701 function mycontris( $itemTemplate ) {
00702 if ( $this->isLoggedIn() ) {
00703 global $wgUser;
00704 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'mycontris',
00705 "Contributions/" . $wgUser->getTitleKey(), wfMsg('mycontris') );
00706 } else {
00707 $s = '';
00708 }
00709 return cbt_value( $s, 'user' );
00710 }
00711
00712 function logout( $itemTemplate ) {
00713 if ( $this->isLoggedIn() ) {
00714 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'logout',
00715 'Userlogout', wfMsg( 'userlogout' ),
00716 $this->mTitle->getNamespace() === NS_SPECIAL && $this->mTitle->getText() === 'Preferences'
00717 ? '' : "returnto=" . $this->mTitle->getPrefixedURL() );
00718 } else {
00719 $s = '';
00720 }
00721 return cbt_value( $s, 'loggedin dynamic' );
00722 }
00723
00724 function anonuserpage( $itemTemplate ) {
00725 if ( $this->isLoggedIn() ) {
00726 $s = '';
00727 } else {
00728 global $wgUser;
00729 $userPage = $this->getUserPageTitle();
00730 $s = $this->makeTemplateLink( $itemTemplate, 'userpage', $userPage, $wgUser->getName() );
00731 }
00732 return cbt_value( $s, '!loggedin dynamic' );
00733 }
00734
00735 function anontalk( $itemTemplate ) {
00736 if ( $this->isLoggedIn() ) {
00737 $s = '';
00738 } else {
00739 $userPage = $this->getUserPageTitle();
00740 $talkPage = $userPage->getTalkPage();
00741 $s = $this->makeTemplateLink( $itemTemplate, 'mytalk', $talkPage, wfMsg('anontalk') );
00742 }
00743 return cbt_value( $s, '!loggedin dynamic' );
00744 }
00745
00746 function anonlogin( $itemTemplate ) {
00747 if ( $this->isLoggedIn() ) {
00748 $s = '';
00749 } else {
00750 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'anonlogin', 'Userlogin',
00751 wfMsg( 'userlogin' ), 'returnto=' . urlencode( $this->getThisPDBK() ) );
00752 }
00753 return cbt_value( $s, '!loggedin dynamic' );
00754 }
00755
00756 function login( $itemTemplate ) {
00757 if ( $this->isLoggedIn() ) {
00758 $s = '';
00759 } else {
00760 $s = $this->makeSpecialTemplateLink( $itemTemplate, 'login', 'Userlogin',
00761 wfMsg( 'userlogin' ), 'returnto=' . urlencode( $this->getThisPDBK() ) );
00762 }
00763 return cbt_value( $s, '!loggedin dynamic' );
00764 }
00765
00766 function logopath() { return $GLOBALS['wgLogo']; }
00767 function mainpage() { return self::makeMainPageUrl(); }
00768
00769 function sidebar( $startSection, $endSection, $innerTpl ) {
00770 $s = '';
00771 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
00772 $firstSection = true;
00773 foreach ($lines as $line) {
00774 if (strpos($line, '*') !== 0)
00775 continue;
00776 if (strpos($line, '**') !== 0) {
00777 $bar = trim($line, '* ');
00778 $name = wfMsg( $bar );
00779 if (wfEmptyMsg($bar, $name)) {
00780 $name = $bar;
00781 }
00782 if ( $firstSection ) {
00783 $firstSection = false;
00784 } else {
00785 $s .= $endSection;
00786 }
00787 $s .= strtr( $startSection,
00788 array(
00789 '$bar' => htmlspecialchars( $bar ),
00790 '$barname' => $name
00791 ) );
00792 } else {
00793 if (strpos($line, '|') !== false) {
00794 $line = explode( '|' , trim($line, '* '), 2 );
00795 $link = wfMsgForContent( $line[0] );
00796 if ($link == '-')
00797 continue;
00798 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
00799 $text = $line[1];
00800 if (wfEmptyMsg($line[0], $link))
00801 $link = $line[0];
00802 $href = self::makeInternalOrExternalUrl( $link );
00803
00804 $s .= strtr( $innerTpl,
00805 array(
00806 '$text' => htmlspecialchars( $text ),
00807 '$href' => htmlspecialchars( $href ),
00808 '$id' => htmlspecialchars( 'n-' . strtr($line[1], ' ', '-') ),
00809 '$classactive' => ''
00810 ) );
00811 } else { continue; }
00812 }
00813 }
00814 if ( !$firstSection ) {
00815 $s .= $endSection;
00816 }
00817
00818
00819 return cbt_value( $s, 'lang' );
00820 }
00821
00822 function searchaction() {
00823
00824 return $this->getSearchLink();
00825 }
00826
00827 function search() {
00828 global $wgRequest;
00829 return cbt_value( trim( $this->getSearch() ), 'special dynamic' );
00830 }
00831
00832 function notspecialpage() {
00833 return cbt_value( $this->mTitle->getNamespace() != NS_SPECIAL, 'special' );
00834 }
00835
00836 function nav_whatlinkshere() {
00837 return cbt_value( $this->makeSpecialParamUrl('Whatlinkshere' ), array(), true );
00838 }
00839
00840 function article_exists() {
00841 return cbt_value( (string)($this->mTitle->getArticleId() !== 0), 'title' );
00842 }
00843
00844 function nav_recentchangeslinked() {
00845 return cbt_value( $this->makeSpecialParamUrl('Recentchangeslinked' ), array(), true );
00846 }
00847
00848 function feeds( $itemTemplate = '' ) {
00849 if ( !$this->mOut->isSyndicated() ) {
00850 $feeds = '';
00851 } elseif ( $itemTemplate == '' ) {
00852
00853 $feeds = 'true';
00854 } else {
00855 $feeds = '';
00856 global $wgFeedClasses, $wgRequest;
00857 foreach( $wgFeedClasses as $format => $class ) {
00858 $feeds .= strtr( $itemTemplate,
00859 array(
00860 '$key' => htmlspecialchars( $format ),
00861 '$text' => $format,
00862 '$href' => $wgRequest->appendQuery( "feed=$format" )
00863 ) );
00864 }
00865 }
00866 return cbt_value( $feeds, 'special dynamic' );
00867 }
00868
00869 function is_userpage() {
00870 list( $id, $ip ) = $this->getUserPageIdIp();
00871 return cbt_value( (string)($id || $ip), 'title' );
00872 }
00873
00874 function is_ns_mediawiki() {
00875 return cbt_value( (string)$this->mTitle->getNamespace() == NS_MEDIAWIKI, 'title' );
00876 }
00877
00878 function is_loggedin() {
00879 global $wgUser;
00880 return cbt_value( (string)($wgUser->isLoggedIn()), 'loggedin' );
00881 }
00882
00883 function nav_contributions() {
00884 $url = $this->makeSpecialParamUrl( 'Contributions', '', '{title_userurl}' );
00885 return cbt_value( $url, array(), true );
00886 }
00887
00888 function is_allowed( $right ) {
00889 global $wgUser;
00890 return cbt_value( (string)$wgUser->isAllowed( $right ), 'user' );
00891 }
00892
00893 function nav_blockip() {
00894 $url = $this->makeSpecialParamUrl( 'Blockip', '', '{title_userurl}' );
00895 return cbt_value( $url, array(), true );
00896 }
00897
00898 function nav_emailuser() {
00899 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
00900 if ( !$wgEnableEmail || !$wgEnableUserEmail ) return '';
00901
00902 $url = $this->makeSpecialParamUrl( 'Emailuser', '', '{title_userurl}' );
00903 return cbt_value( $url, array(), true );
00904 }
00905
00906 function nav_upload() {
00907 global $wgEnableUploads, $wgUploadNavigationUrl;
00908 if ( !$wgEnableUploads ) {
00909 return '';
00910 } elseif ( $wgUploadNavigationUrl ) {
00911 return $wgUploadNavigationUrl;
00912 } else {
00913 return self::makeSpecialUrl('Upload');
00914 }
00915 }
00916
00917 function nav_specialpages() {
00918 return self::makeSpecialUrl('Specialpages');
00919 }
00920
00921 function nav_print() {
00922 global $wgRequest, $wgArticle;
00923 $action = $this->getAction();
00924 $url = '';
00925 if( $this->mTitle->getNamespace() !== NS_SPECIAL
00926 && ($action == '' || $action == 'view' || $action == 'purge' ) )
00927 {
00928 $revid = $wgArticle->getLatest();
00929 if ( $revid != 0 ) {
00930 $url = $wgRequest->appendQuery( 'printable=yes' );
00931 }
00932 }
00933 return cbt_value( $url, array( 'nonview dynamic', 'title' ) );
00934 }
00935
00936 function nav_permalink() {
00937 $url = (string)$this->getPermalink();
00938 return cbt_value( $url, 'dynamic' );
00939 }
00940
00941 function nav_trackbacklink() {
00942 global $wgUseTrackbacks;
00943 if ( !$wgUseTrackbacks ) return '';
00944
00945 return cbt_value( $this->mTitle->trackbackURL(), 'title' );
00946 }
00947
00948 function is_permalink() {
00949 return cbt_value( (string)($this->getPermalink() === false), 'nonview dynamic' );
00950 }
00951
00952 function toolboxend() {
00953
00954 return '';
00955 }
00956
00957 function language_urls( $outer, $inner ) {
00958 global $wgHideInterlanguageLinks, $wgOut, $wgContLang;
00959 if ( $wgHideInterlanguageLinks ) return '';
00960
00961 $links = $wgOut->getLanguageLinks();
00962 $s = '';
00963 if ( count( $links ) ) {
00964 foreach( $links as $l ) {
00965 $tmp = explode( ':', $l, 2 );
00966 $nt = Title::newFromText( $l );
00967 $s .= strtr( $inner,
00968 array(
00969 '$class' => htmlspecialchars( 'interwiki-' . $tmp[0] ),
00970 '$href' => htmlspecialchars( $nt->getFullURL() ),
00971 '$text' => ($wgContLang->getLanguageName( $nt->getInterwiki() ) != ''?
00972 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
00973 )
00974 );
00975 }
00976 $s = str_replace( '$body', $s, $outer );
00977 }
00978 return cbt_value( $s, 'dynamic' );
00979 }
00980
00981 function poweredbyico() { return $this->getPoweredBy(); }
00982 function copyrightico() { return $this->getCopyrightIcon(); }
00983
00984 function lastmod() {
00985 global $wgMaxCredits;
00986 if ( $wgMaxCredits ) return '';
00987
00988 if ( !isset( $this->mLastmod ) ) {
00989 if ( $this->isCurrentArticleView() ) {
00990 $this->mLastmod = $this->lastModified();
00991 } else {
00992 $this->mLastmod = '';
00993 }
00994 }
00995 return cbt_value( $this->mLastmod, 'dynamic' );
00996 }
00997
00998 function viewcount() {
00999 global $wgDisableCounters;
01000 if ( $wgDisableCounters ) return '';
01001
01002 global $wgLang, $wgArticle;
01003 if ( is_object( $wgArticle ) ) {
01004 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
01005 if ( $viewcount ) {
01006 $viewcount = wfMsg( "viewcount", $viewcount );
01007 } else {
01008 $viewcount = '';
01009 }
01010 } else {
01011 $viewcount = '';
01012 }
01013 return cbt_value( $viewcount, 'dynamic' );
01014 }
01015
01016 function numberofwatchingusers() {
01017 global $wgPageShowWatchingUsers;
01018 if ( !$wgPageShowWatchingUsers ) return '';
01019
01020 $dbr = wfGetDB( DB_SLAVE );
01021 extract( $dbr->tableNames( 'watchlist' ) );
01022 $sql = "SELECT COUNT(*) AS n FROM $watchlist
01023 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBkey()) .
01024 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
01025 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
01026 $row = $dbr->fetchObject( $res );
01027 $num = $row->n;
01028 if ($num > 0) {
01029 $s = wfMsg('number_of_watching_users_pageview', $num);
01030 } else {
01031 $s = '';
01032 }
01033 return cbt_value( $s, 'dynamic' );
01034 }
01035
01036 function credits() {
01037 global $wgMaxCredits;
01038 if ( !$wgMaxCredits ) return '';
01039
01040 if ( $this->isCurrentArticleView() ) {
01041 require_once("Credits.php");
01042 global $wgArticle, $wgShowCreditsIfMax;
01043 $credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
01044 } else {
01045 $credits = '';
01046 }
01047 return cbt_value( $credits, 'view dynamic' );
01048 }
01049
01050 function normalcopyright() {
01051 return $this->getCopyright( 'normal' );
01052 }
01053
01054 function historycopyright() {
01055 return $this->getCopyright( 'history' );
01056 }
01057
01058 function is_currentview() {
01059 global $wgRequest;
01060 return cbt_value( (string)$this->isCurrentArticleView(), 'view' );
01061 }
01062
01063 function usehistorycopyright() {
01064 global $wgRequest;
01065 if ( wfMsgForContent( 'history_copyright' ) == '-' ) return '';
01066
01067 $oldid = $this->getOldId();
01068 $diff = $this->getDiff();
01069 $use = (string)(!is_null( $oldid ) && is_null( $diff ));
01070 return cbt_value( $use, 'nonview dynamic' );
01071 }
01072
01073 function privacy() {
01074 return cbt_value( $this->privacyLink(), 'lang' );
01075 }
01076 function about() {
01077 return cbt_value( $this->aboutLink(), 'lang' );
01078 }
01079 function disclaimer() {
01080 return cbt_value( $this->disclaimerLink(), 'lang' );
01081 }
01082 function tagline() {
01083 # A reference to this tag existed in the old MonoBook.php, but the
01084 # template data wasn't set anywhere
01085 return '';
01086 }
01087 function reporttime() {
01088 return cbt_value( $this->mOut->reportTime(), 'dynamic' );
01089 }
01090
01091 function msg( $name ) {
01092 return cbt_value( wfMsg( $name ), 'lang' );
01093 }
01094
01095 function fallbackmsg( $name, $fallback ) {
01096 $text = wfMsg( $name );
01097 if ( wfEmptyMsg( $name, $text ) ) {
01098 $text = $fallback;
01099 }
01100 return cbt_value( $text, 'lang' );
01101 }
01102
01103
01104
01105
01106
01108 function isCssPreview() {
01109 if ( !isset( $this->mCssPreview ) ) {
01110 global $wgRequest, $wgAllowUserCss, $wgUser;
01111 $this->mCssPreview =
01112 $wgAllowUserCss &&
01113 $wgUser->isLoggedIn() &&
01114 $this->mTitle->isCssSubpage() &&
01115 $this->userCanPreview( $this->getAction() );
01116 }
01117 return $this->mCssPreview;
01118 }
01119
01121 function isJsPreview() {
01122 if ( !isset( $this->mJsPreview ) ) {
01123 global $wgRequest, $wgAllowUserJs, $wgUser;
01124 $this->mJsPreview =
01125 $wgAllowUserJs &&
01126 $wgUser->isLoggedIn() &&
01127 $this->mTitle->isJsSubpage() &&
01128 $this->userCanPreview( $this->getAction() );
01129 }
01130 return $this->mJsPreview;
01131 }
01132
01134 function getUserPageTitle() {
01135 if ( !isset( $this->mUserPageTitle ) ) {
01136 global $wgUser;
01137 $this->mUserPageTitle = $wgUser->getUserPage();
01138 }
01139 return $this->mUserPageTitle;
01140 }
01141
01143 function getUserPageText() {
01144 if ( !isset( $this->mUserPageText ) ) {
01145 $userPage = $this->getUserPageTitle();
01146 $this->mUserPageText = $userPage->getPrefixedText();
01147 }
01148 return $this->mUserPageText;
01149 }
01150
01152 function makeStylesheetLink( $url ) {
01153 return '<link rel="stylesheet" type="text/css" href="' . htmlspecialchars( $url ) . "\"/>";
01154 }
01155
01157 function makeStylesheetCdata( $style ) {
01158 return "<style type=\"text/css\"> /*<![CDATA[*/ {$style} /*]]>*/ </style>";
01159 }
01160
01162 function getEditUrl() {
01163 if ( !isset( $this->mEditUrl ) ) {
01164 $this->mEditUrl = $this->mTitle->getLocalUrl( $this->editUrlOptions() );
01165 }
01166 return $this->mEditUrl;
01167 }
01168
01170 function getThisPDBK() {
01171 if ( !isset( $this->mThisPDBK ) ) {
01172 $this->mThisPDBK = $this->mTitle->getPrefixedDbKey();
01173 }
01174 return $this->mThisPDBK;
01175 }
01176
01177 function getThisTitleUrlForm() {
01178 if ( !isset( $this->mThisTitleUrlForm ) ) {
01179 $this->mThisTitleUrlForm = $this->mTitle->getPrefixedURL();
01180 }
01181 return $this->mThisTitleUrlForm;
01182 }
01183
01187 function getUserPageIdIp() {
01188 if ( !isset( $this->mUserPageId ) ) {
01189 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
01190 $this->mUserPageId = User::idFromName($this->mTitle->getText());
01191 $this->mUserPageIp = User::isIP($this->mTitle->getText());
01192 } else {
01193 $this->mUserPageId = 0;
01194 $this->mUserPageIp = false;
01195 }
01196 }
01197 return array( $this->mUserPageId, $this->mUserPageIp );
01198 }
01199
01204 function getPermalink() {
01205 if ( !isset( $this->mPermalink ) ) {
01206 global $wgRequest, $wgArticle;
01207 $action = $this->getAction();
01208 $oldid = $this->getOldId();
01209 $url = '';
01210 if( $this->mTitle->getNamespace() !== NS_SPECIAL
01211 && $this->mTitle->getArticleId() != 0
01212 && ($action == '' || $action == 'view' || $action == 'purge' ) )
01213 {
01214 if ( !$oldid ) {
01215 $revid = $wgArticle->getLatest();
01216 $url = $this->mTitle->getLocalURL( "oldid=$revid" );
01217 } else {
01218 $url = false;
01219 }
01220 } else {
01221 $url = '';
01222 }
01223 }
01224 return $url;
01225 }
01226
01231 function isArticleView() {
01232 global $wgOut, $wgArticle, $wgRequest;
01233 if ( !isset( $this->mIsArticleView ) ) {
01234 $oldid = $this->getOldId();
01235 $diff = $this->getDiff();
01236 $this->mIsArticleView = $wgOut->isArticle() and
01237 (!is_null( $oldid ) or is_null( $diff )) and 0 != $wgArticle->getID();
01238 }
01239 return $this->mIsArticleView;
01240 }
01241
01242 function isCurrentArticleView() {
01243 if ( !isset( $this->mIsCurrentArticleView ) ) {
01244 global $wgOut, $wgArticle, $wgRequest;
01245 $oldid = $this->getOldId();
01246 $this->mIsCurrentArticleView = $wgOut->isArticle() && is_null( $oldid ) && 0 != $wgArticle->getID();
01247 }
01248 return $this->mIsCurrentArticleView;
01249 }
01250
01251
01256 function isEditable() {
01257 global $wgRequest;
01258 $action = $this->getAction();
01259 return ($this->mTitle->getNamespace() != NS_SPECIAL and !($action == 'edit' or $action == 'submit'));
01260 }
01261
01263 function isLoggedIn() {
01264 global $wgUser;
01265 return $wgUser->isLoggedIn();
01266 }
01267
01269 function getPageUrl() {
01270 if ( !isset( $this->mPageUrl ) ) {
01271 $this->mPageUrl = $this->mTitle->getLocalURL();
01272 }
01273 return $this->mPageUrl;
01274 }
01275
01277 function makeTemplateLink( $template, $key, $title, $text ) {
01278 $url = $title->getLocalUrl();
01279 return strtr( $template,
01280 array(
01281 '$key' => $key,
01282 '$classactive' => ($url == $this->getPageUrl()) ? 'class="active"' : '',
01283 '$class' => $title->getArticleID() == 0 ? 'class="new"' : '',
01284 '$href' => htmlspecialchars( $url ),
01285 '$text' => $text
01286 ) );
01287 }
01288
01290 function makeTemplateLinkUrl( $template, $key, $url, $text ) {
01291 return strtr( $template,
01292 array(
01293 '$key' => $key,
01294 '$classactive' => ($url == $this->getPageUrl()) ? 'class="active"' : '',
01295 '$class' => '',
01296 '$href' => htmlspecialchars( $url ),
01297 '$text' => $text
01298 ) );
01299 }
01300
01302 function makeSpecialTemplateLink( $template, $key, $specialName, $text, $query = '' ) {
01303 $url = self::makeSpecialUrl( $specialName, $query );
01304
01305 $active = ($this->mTitle->getNamespace() == NS_SPECIAL && $this->mTitle->getDBkey() == $specialName);
01306 return strtr( $template,
01307 array(
01308 '$key' => $key,
01309 '$classactive' => $active ? 'class="active"' : '',
01310 '$class' => '',
01311 '$href' => htmlspecialchars( $url ),
01312 '$text' => $text
01313 ) );
01314 }
01315
01316 function loadRequestValues() {
01317 global $wgRequest;
01318 $this->mAction = $wgRequest->getText( 'action' );
01319 $this->mOldId = $wgRequest->getVal( 'oldid' );
01320 $this->mDiff = $wgRequest->getVal( 'diff' );
01321 $this->mSection = $wgRequest->getVal( 'section' );
01322 $this->mSearch = $wgRequest->getVal( 'search' );
01323 $this->mRequestValuesLoaded = true;
01324 }
01325
01326
01327
01329 function getAction() {
01330 if ( !isset( $this->mRequestValuesLoaded ) ) {
01331 $this->loadRequestValues();
01332 }
01333 return $this->mAction;
01334 }
01335
01337 function getOldId() {
01338 if ( !isset( $this->mRequestValuesLoaded ) ) {
01339 $this->loadRequestValues();
01340 }
01341 return $this->mOldId;
01342 }
01343
01345 function getDiff() {
01346 if ( !isset( $this->mRequestValuesLoaded ) ) {
01347 $this->loadRequestValues();
01348 }
01349 return $this->mDiff;
01350 }
01351
01352 function getSection() {
01353 if ( !isset( $this->mRequestValuesLoaded ) ) {
01354 $this->loadRequestValues();
01355 }
01356 return $this->mSection;
01357 }
01358
01359 function getSearch() {
01360 if ( !isset( $this->mRequestValuesLoaded ) ) {
01361 $this->loadRequestValues();
01362 }
01363 return $this->mSearch;
01364 }
01365
01367 function makeSpecialParamUrl( $name, $query = '', $param = '{title_urlform}' ) {
01368
01369 $title = Title::makeTitle( NS_SPECIAL, "$name/\x1a" );
01370 $url = cbt_escape( $title->getLocalURL( $query ) );
01371
01372 return str_replace( '%1A', $param, $url );
01373 }
01374
01375 function getSubjectPage() {
01376 if ( !isset( $this->mSubjectPage ) ) {
01377 $this->mSubjectPage = $this->mTitle->getSubjectPage();
01378 }
01379 return $this->mSubjectPage;
01380 }
01381
01382 function getTalkPage() {
01383 if ( !isset( $this->mTalkPage ) ) {
01384 $this->mTalkPage = $this->mTitle->getTalkPage();
01385 }
01386 return $this->mTalkPage;
01387 }
01388 }
01389