MediaWiki
REL1_23
|
00001 <?php 00030 class MediaWiki_I18N { 00031 var $_context = array(); 00032 00033 function set( $varName, $value ) { 00034 $this->_context[$varName] = $value; 00035 } 00036 00037 function translate( $value ) { 00038 wfProfileIn( __METHOD__ ); 00039 00040 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23 00041 $value = preg_replace( '/^string:/', '', $value ); 00042 00043 $value = wfMessage( $value )->text(); 00044 // interpolate variables 00045 $m = array(); 00046 while ( preg_match( '/\$([0-9]*?)/sm', $value, $m ) ) { 00047 list( $src, $var ) = $m; 00048 wfSuppressWarnings(); 00049 $varValue = $this->_context[$var]; 00050 wfRestoreWarnings(); 00051 $value = str_replace( $src, $varValue, $value ); 00052 } 00053 wfProfileOut( __METHOD__ ); 00054 return $value; 00055 } 00056 } 00057 00070 class SkinTemplate extends Skin { 00079 var $skinname = 'monobook'; 00080 00085 var $stylename = 'monobook'; 00086 00091 var $template = 'QuickTemplate'; 00092 00097 var $useHeadElement = false; 00098 00106 function setupSkinUserCss( OutputPage $out ) { 00107 $out->addModuleStyles( array( 00108 'mediawiki.legacy.shared', 00109 'mediawiki.legacy.commonPrint', 00110 'mediawiki.ui.button' 00111 ) ); 00112 } 00113 00125 function setupTemplate( $classname, $repository = false, $cache_dir = false ) { 00126 return new $classname(); 00127 } 00128 00135 public function getLanguages() { 00136 global $wgHideInterlanguageLinks; 00137 if ( $wgHideInterlanguageLinks ) { 00138 return array(); 00139 } 00140 00141 $userLang = $this->getLanguage(); 00142 $languageLinks = array(); 00143 00144 foreach ( $this->getOutput()->getLanguageLinks() as $languageLinkText ) { 00145 $languageLinkParts = explode( ':', $languageLinkText, 2 ); 00146 $class = 'interlanguage-link interwiki-' . $languageLinkParts[0]; 00147 unset( $languageLinkParts ); 00148 00149 $languageLinkTitle = Title::newFromText( $languageLinkText ); 00150 if ( $languageLinkTitle ) { 00151 $ilInterwikiCode = $languageLinkTitle->getInterwiki(); 00152 $ilLangName = Language::fetchLanguageName( $ilInterwikiCode ); 00153 00154 if ( strval( $ilLangName ) === '' ) { 00155 $ilLangName = $languageLinkText; 00156 } else { 00157 $ilLangName = $this->formatLanguageName( $ilLangName ); 00158 } 00159 00160 // CLDR extension or similar is required to localize the language name; 00161 // otherwise we'll end up with the autonym again. 00162 $ilLangLocalName = Language::fetchLanguageName( 00163 $ilInterwikiCode, 00164 $userLang->getCode() 00165 ); 00166 00167 $languageLinkTitleText = $languageLinkTitle->getText(); 00168 if ( $languageLinkTitleText === '' ) { 00169 $ilTitle = wfMessage( 00170 'interlanguage-link-title-langonly', 00171 $ilLangLocalName 00172 )->text(); 00173 } else { 00174 $ilTitle = wfMessage( 00175 'interlanguage-link-title', 00176 $languageLinkTitleText, 00177 $ilLangLocalName 00178 )->text(); 00179 } 00180 00181 $ilInterwikiCodeBCP47 = wfBCP47( $ilInterwikiCode ); 00182 $languageLink = array( 00183 'href' => $languageLinkTitle->getFullURL(), 00184 'text' => $ilLangName, 00185 'title' => $ilTitle, 00186 'class' => $class, 00187 'lang' => $ilInterwikiCodeBCP47, 00188 'hreflang' => $ilInterwikiCodeBCP47, 00189 ); 00190 wfRunHooks( 'SkinTemplateGetLanguageLink', array( &$languageLink, $languageLinkTitle, $this->getTitle() ) ); 00191 $languageLinks[] = $languageLink; 00192 } 00193 } 00194 00195 return $languageLinks; 00196 } 00197 00198 protected function setupTemplateForOutput() { 00199 wfProfileIn( __METHOD__ ); 00200 00201 $request = $this->getRequest(); 00202 $user = $this->getUser(); 00203 $title = $this->getTitle(); 00204 00205 wfProfileIn( __METHOD__ . '-init' ); 00206 $tpl = $this->setupTemplate( $this->template, 'skins' ); 00207 wfProfileOut( __METHOD__ . '-init' ); 00208 00209 wfProfileIn( __METHOD__ . '-stuff' ); 00210 $this->thispage = $title->getPrefixedDBkey(); 00211 $this->titletxt = $title->getPrefixedText(); 00212 $this->userpage = $user->getUserPage()->getPrefixedText(); 00213 $query = array(); 00214 if ( !$request->wasPosted() ) { 00215 $query = $request->getValues(); 00216 unset( $query['title'] ); 00217 unset( $query['returnto'] ); 00218 unset( $query['returntoquery'] ); 00219 } 00220 $this->thisquery = wfArrayToCgi( $query ); 00221 $this->loggedin = $user->isLoggedIn(); 00222 $this->username = $user->getName(); 00223 00224 if ( $this->loggedin || $this->showIPinHeader() ) { 00225 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage ); 00226 } else { 00227 # This won't be used in the standard skins, but we define it to preserve the interface 00228 # To save time, we check for existence 00229 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage ); 00230 } 00231 00232 wfProfileOut( __METHOD__ . '-stuff' ); 00233 00234 wfProfileOut( __METHOD__ ); 00235 00236 return $tpl; 00237 } 00238 00244 function outputPage( OutputPage $out = null ) { 00245 wfProfileIn( __METHOD__ ); 00246 Profiler::instance()->setTemplated( true ); 00247 00248 $oldContext = null; 00249 if ( $out !== null ) { 00250 // @todo Add wfDeprecated in 1.20 00251 $oldContext = $this->getContext(); 00252 $this->setContext( $out->getContext() ); 00253 } 00254 00255 $out = $this->getOutput(); 00256 00257 wfProfileIn( __METHOD__ . '-init' ); 00258 $this->initPage( $out ); 00259 wfProfileOut( __METHOD__ . '-init' ); 00260 $tpl = $this->prepareQuickTemplate( $out ); 00261 // execute template 00262 wfProfileIn( __METHOD__ . '-execute' ); 00263 $res = $tpl->execute(); 00264 wfProfileOut( __METHOD__ . '-execute' ); 00265 00266 // result may be an error 00267 $this->printOrError( $res ); 00268 00269 if ( $oldContext ) { 00270 $this->setContext( $oldContext ); 00271 } 00272 00273 wfProfileOut( __METHOD__ ); 00274 } 00275 00282 protected function prepareQuickTemplate() { 00283 global $wgContLang, $wgScript, $wgStylePath, 00284 $wgMimeType, $wgJsMimeType, $wgXhtmlNamespaces, $wgHtml5Version, 00285 $wgDisableCounters, $wgSitename, $wgLogo, $wgMaxCredits, 00286 $wgShowCreditsIfMax, $wgPageShowWatchingUsers, $wgArticlePath, 00287 $wgScriptPath, $wgServer; 00288 00289 wfProfileIn( __METHOD__ ); 00290 00291 $title = $this->getTitle(); 00292 $request = $this->getRequest(); 00293 $out = $this->getOutput(); 00294 $tpl = $this->setupTemplateForOutput(); 00295 00296 wfProfileIn( __METHOD__ . '-stuff-head' ); 00297 if ( !$this->useHeadElement ) { 00298 $tpl->set( 'pagecss', false ); 00299 $tpl->set( 'usercss', false ); 00300 00301 $tpl->set( 'userjs', false ); 00302 $tpl->set( 'userjsprev', false ); 00303 00304 $tpl->set( 'jsvarurl', false ); 00305 00306 $tpl->set( 'xhtmldefaultnamespace', 'http://www.w3.org/1999/xhtml' ); 00307 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces ); 00308 $tpl->set( 'html5version', $wgHtml5Version ); 00309 $tpl->set( 'headlinks', $out->getHeadLinks() ); 00310 $tpl->set( 'csslinks', $out->buildCssLinks() ); 00311 $tpl->set( 'pageclass', $this->getPageClasses( $title ) ); 00312 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer::escapeClass( $this->getSkinName() ) ) ); 00313 } 00314 wfProfileOut( __METHOD__ . '-stuff-head' ); 00315 00316 wfProfileIn( __METHOD__ . '-stuff2' ); 00317 $tpl->set( 'title', $out->getPageTitle() ); 00318 $tpl->set( 'pagetitle', $out->getHTMLTitle() ); 00319 $tpl->set( 'displaytitle', $out->mPageLinkTitle ); 00320 00321 $tpl->setRef( 'thispage', $this->thispage ); 00322 $tpl->setRef( 'titleprefixeddbkey', $this->thispage ); 00323 $tpl->set( 'titletext', $title->getText() ); 00324 $tpl->set( 'articleid', $title->getArticleID() ); 00325 00326 $tpl->set( 'isarticle', $out->isArticle() ); 00327 00328 $subpagestr = $this->subPageSubtitle(); 00329 if ( $subpagestr !== '' ) { 00330 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>'; 00331 } 00332 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() ); 00333 00334 $undelete = $this->getUndeleteLink(); 00335 if ( $undelete === '' ) { 00336 $tpl->set( 'undelete', '' ); 00337 } else { 00338 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' ); 00339 } 00340 00341 $tpl->set( 'catlinks', $this->getCategories() ); 00342 if ( $out->isSyndicated() ) { 00343 $feeds = array(); 00344 foreach ( $out->getSyndicationLinks() as $format => $link ) { 00345 $feeds[$format] = array( 00346 // Messages: feed-atom, feed-rss 00347 'text' => $this->msg( "feed-$format" )->text(), 00348 'href' => $link 00349 ); 00350 } 00351 $tpl->setRef( 'feeds', $feeds ); 00352 } else { 00353 $tpl->set( 'feeds', false ); 00354 } 00355 00356 $tpl->setRef( 'mimetype', $wgMimeType ); 00357 $tpl->setRef( 'jsmimetype', $wgJsMimeType ); 00358 $tpl->set( 'charset', 'UTF-8' ); 00359 $tpl->setRef( 'wgScript', $wgScript ); 00360 $tpl->setRef( 'skinname', $this->skinname ); 00361 $tpl->set( 'skinclass', get_class( $this ) ); 00362 $tpl->setRef( 'skin', $this ); 00363 $tpl->setRef( 'stylename', $this->stylename ); 00364 $tpl->set( 'printable', $out->isPrintable() ); 00365 $tpl->set( 'handheld', $request->getBool( 'handheld' ) ); 00366 $tpl->setRef( 'loggedin', $this->loggedin ); 00367 $tpl->set( 'notspecialpage', !$title->isSpecialPage() ); 00368 /* XXX currently unused, might get useful later 00369 $tpl->set( 'editable', ( !$title->isSpecialPage() ) ); 00370 $tpl->set( 'exists', $title->getArticleID() != 0 ); 00371 $tpl->set( 'watch', $user->isWatched( $title ) ? 'unwatch' : 'watch' ); 00372 $tpl->set( 'protect', count( $title->isProtected() ) ? 'unprotect' : 'protect' ); 00373 $tpl->set( 'helppage', $this->msg( 'helppage' )->text() ); 00374 */ 00375 $tpl->set( 'searchaction', $this->escapeSearchLink() ); 00376 $tpl->set( 'searchtitle', SpecialPage::getTitleFor( 'Search' )->getPrefixedDBkey() ); 00377 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) ); 00378 $tpl->setRef( 'stylepath', $wgStylePath ); 00379 $tpl->setRef( 'articlepath', $wgArticlePath ); 00380 $tpl->setRef( 'scriptpath', $wgScriptPath ); 00381 $tpl->setRef( 'serverurl', $wgServer ); 00382 $tpl->setRef( 'logopath', $wgLogo ); 00383 $tpl->setRef( 'sitename', $wgSitename ); 00384 00385 $userLang = $this->getLanguage(); 00386 $userLangCode = $userLang->getHtmlCode(); 00387 $userLangDir = $userLang->getDir(); 00388 00389 $tpl->set( 'lang', $userLangCode ); 00390 $tpl->set( 'dir', $userLangDir ); 00391 $tpl->set( 'rtl', $userLang->isRTL() ); 00392 00393 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' ); 00394 $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed 00395 $tpl->set( 'username', $this->loggedin ? $this->username : null ); 00396 $tpl->setRef( 'userpage', $this->userpage ); 00397 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href'] ); 00398 $tpl->set( 'userlang', $userLangCode ); 00399 00400 // Users can have their language set differently than the 00401 // content of the wiki. For these users, tell the web browser 00402 // that interface elements are in a different language. 00403 $tpl->set( 'userlangattributes', '' ); 00404 $tpl->set( 'specialpageattributes', '' ); # obsolete 00405 // Used by VectorBeta to insert HTML before content but after the heading for the page title. Defaults to empty string. 00406 $tpl->set( 'prebodyhtml', '' ); 00407 00408 if ( $userLangCode !== $wgContLang->getHtmlCode() || $userLangDir !== $wgContLang->getDir() ) { 00409 $escUserlang = htmlspecialchars( $userLangCode ); 00410 $escUserdir = htmlspecialchars( $userLangDir ); 00411 // Attributes must be in double quotes because htmlspecialchars() doesn't 00412 // escape single quotes 00413 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\""; 00414 $tpl->set( 'userlangattributes', $attrs ); 00415 } 00416 00417 wfProfileOut( __METHOD__ . '-stuff2' ); 00418 00419 wfProfileIn( __METHOD__ . '-stuff3' ); 00420 $tpl->set( 'newtalk', $this->getNewtalks() ); 00421 $tpl->set( 'logo', $this->logoText() ); 00422 00423 $tpl->set( 'copyright', false ); 00424 $tpl->set( 'viewcount', false ); 00425 $tpl->set( 'lastmod', false ); 00426 $tpl->set( 'credits', false ); 00427 $tpl->set( 'numberofwatchingusers', false ); 00428 if ( $out->isArticle() && $title->exists() ) { 00429 if ( $this->isRevisionCurrent() ) { 00430 if ( !$wgDisableCounters ) { 00431 $viewcount = $this->getWikiPage()->getCount(); 00432 if ( $viewcount ) { 00433 $tpl->set( 'viewcount', $this->msg( 'viewcount' )->numParams( $viewcount )->parse() ); 00434 } 00435 } 00436 00437 if ( $wgPageShowWatchingUsers ) { 00438 $dbr = wfGetDB( DB_SLAVE ); 00439 $num = $dbr->selectField( 'watchlist', 'COUNT(*)', 00440 array( 'wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace() ), 00441 __METHOD__ 00442 ); 00443 if ( $num > 0 ) { 00444 $tpl->set( 'numberofwatchingusers', 00445 $this->msg( 'number_of_watching_users_pageview' )->numParams( $num )->parse() 00446 ); 00447 } 00448 } 00449 00450 if ( $wgMaxCredits != 0 ) { 00451 $tpl->set( 'credits', Action::factory( 'credits', $this->getWikiPage(), 00452 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) ); 00453 } else { 00454 $tpl->set( 'lastmod', $this->lastModified() ); 00455 } 00456 } 00457 $tpl->set( 'copyright', $this->getCopyright() ); 00458 } 00459 wfProfileOut( __METHOD__ . '-stuff3' ); 00460 00461 wfProfileIn( __METHOD__ . '-stuff4' ); 00462 $tpl->set( 'copyrightico', $this->getCopyrightIcon() ); 00463 $tpl->set( 'poweredbyico', $this->getPoweredBy() ); 00464 $tpl->set( 'disclaimer', $this->disclaimerLink() ); 00465 $tpl->set( 'privacy', $this->privacyLink() ); 00466 $tpl->set( 'about', $this->aboutLink() ); 00467 00468 $tpl->set( 'footerlinks', array( 00469 'info' => array( 00470 'lastmod', 00471 'viewcount', 00472 'numberofwatchingusers', 00473 'credits', 00474 'copyright', 00475 ), 00476 'places' => array( 00477 'privacy', 00478 'about', 00479 'disclaimer', 00480 ), 00481 ) ); 00482 00483 global $wgFooterIcons; 00484 $tpl->set( 'footericons', $wgFooterIcons ); 00485 foreach ( $tpl->data['footericons'] as $footerIconsKey => &$footerIconsBlock ) { 00486 if ( count( $footerIconsBlock ) > 0 ) { 00487 foreach ( $footerIconsBlock as &$footerIcon ) { 00488 if ( isset( $footerIcon['src'] ) ) { 00489 if ( !isset( $footerIcon['width'] ) ) { 00490 $footerIcon['width'] = 88; 00491 } 00492 if ( !isset( $footerIcon['height'] ) ) { 00493 $footerIcon['height'] = 31; 00494 } 00495 } 00496 } 00497 } else { 00498 unset( $tpl->data['footericons'][$footerIconsKey] ); 00499 } 00500 } 00501 00502 $tpl->set( 'sitenotice', $this->getSiteNotice() ); 00503 $tpl->set( 'bottomscripts', $this->bottomScripts() ); 00504 $tpl->set( 'printfooter', $this->printSource() ); 00505 00506 # An ID that includes the actual body text; without categories, contentSub, ... 00507 $realBodyAttribs = array( 'id' => 'mw-content-text' ); 00508 00509 # Add a mw-content-ltr/rtl class to be able to style based on text direction 00510 # when the content is different from the UI language, i.e.: 00511 # not for special pages or file pages AND only when viewing AND if the page exists 00512 # (or is in MW namespace, because that has default content) 00513 if ( !in_array( $title->getNamespace(), array( NS_SPECIAL, NS_FILE ) ) && 00514 Action::getActionName( $this ) === 'view' && 00515 ( $title->exists() || $title->getNamespace() == NS_MEDIAWIKI ) ) { 00516 $pageLang = $title->getPageViewLanguage(); 00517 $realBodyAttribs['lang'] = $pageLang->getHtmlCode(); 00518 $realBodyAttribs['dir'] = $pageLang->getDir(); 00519 $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir(); 00520 } 00521 00522 $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext ); 00523 $tpl->setRef( 'bodytext', $out->mBodytext ); 00524 00525 $language_urls = $this->getLanguages(); 00526 if ( count( $language_urls ) ) { 00527 $tpl->setRef( 'language_urls', $language_urls ); 00528 } else { 00529 $tpl->set( 'language_urls', false ); 00530 } 00531 wfProfileOut( __METHOD__ . '-stuff4' ); 00532 00533 wfProfileIn( __METHOD__ . '-stuff5' ); 00534 # Personal toolbar 00535 $tpl->set( 'personal_urls', $this->buildPersonalUrls() ); 00536 $content_navigation = $this->buildContentNavigationUrls(); 00537 $content_actions = $this->buildContentActionUrls( $content_navigation ); 00538 $tpl->setRef( 'content_navigation', $content_navigation ); 00539 $tpl->setRef( 'content_actions', $content_actions ); 00540 00541 $tpl->set( 'sidebar', $this->buildSidebar() ); 00542 $tpl->set( 'nav_urls', $this->buildNavUrls() ); 00543 00544 // Set the head scripts near the end, in case the above actions resulted in added scripts 00545 if ( $this->useHeadElement ) { 00546 $tpl->set( 'headelement', $out->headElement( $this ) ); 00547 } else { 00548 $tpl->set( 'headscripts', $out->getHeadScripts() . $out->getHeadItems() ); 00549 } 00550 00551 $tpl->set( 'debug', '' ); 00552 $tpl->set( 'debughtml', $this->generateDebugHTML() ); 00553 $tpl->set( 'reporttime', wfReportTime() ); 00554 00555 // original version by hansm 00556 if ( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) { 00557 wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" ); 00558 } 00559 00560 // Set the bodytext to another key so that skins can just output it on it's own 00561 // and output printfooter and debughtml separately 00562 $tpl->set( 'bodycontent', $tpl->data['bodytext'] ); 00563 00564 // Append printfooter and debughtml onto bodytext so that skins that were already 00565 // using bodytext before they were split out don't suddenly start not outputting information 00566 $tpl->data['bodytext'] .= Html::rawElement( 'div', array( 'class' => 'printfooter' ), "\n{$tpl->data['printfooter']}" ) . "\n"; 00567 $tpl->data['bodytext'] .= $tpl->data['debughtml']; 00568 00569 // allow extensions adding stuff after the page content. 00570 // See Skin::afterContentHook() for further documentation. 00571 $tpl->set( 'dataAfterContent', $this->afterContentHook() ); 00572 wfProfileOut( __METHOD__ . '-stuff5' ); 00573 00574 wfProfileOut( __METHOD__ ); 00575 return $tpl; 00576 } 00577 00582 public function getPersonalToolsList() { 00583 $tpl = $this->setupTemplateForOutput(); 00584 $tpl->set( 'personal_urls', $this->buildPersonalUrls() ); 00585 $html = ''; 00586 foreach ( $tpl->getPersonalTools() as $key => $item ) { 00587 $html .= $tpl->makeListItem( $key, $item ); 00588 } 00589 return $html; 00590 } 00591 00600 function formatLanguageName( $name ) { 00601 return $this->getLanguage()->ucfirst( $name ); 00602 } 00603 00612 function printOrError( $str ) { 00613 echo $str; 00614 } 00615 00625 function useCombinedLoginLink() { 00626 global $wgUseCombinedLoginLink; 00627 return $wgUseCombinedLoginLink; 00628 } 00629 00634 protected function buildPersonalUrls() { 00635 $title = $this->getTitle(); 00636 $request = $this->getRequest(); 00637 $pageurl = $title->getLocalURL(); 00638 wfProfileIn( __METHOD__ ); 00639 00640 /* set up the default links for the personal toolbar */ 00641 $personal_urls = array(); 00642 00643 # Due to bug 32276, if a user does not have read permissions, 00644 # $this->getTitle() will just give Special:Badtitle, which is 00645 # not especially useful as a returnto parameter. Use the title 00646 # from the request instead, if there was one. 00647 if ( $this->getUser()->isAllowed( 'read' ) ) { 00648 $page = $this->getTitle(); 00649 } else { 00650 $page = Title::newFromText( $request->getVal( 'title', '' ) ); 00651 } 00652 $page = $request->getVal( 'returnto', $page ); 00653 $a = array(); 00654 if ( strval( $page ) !== '' ) { 00655 $a['returnto'] = $page; 00656 $query = $request->getVal( 'returntoquery', $this->thisquery ); 00657 if ( $query != '' ) { 00658 $a['returntoquery'] = $query; 00659 } 00660 } 00661 00662 $returnto = wfArrayToCgi( $a ); 00663 if ( $this->loggedin ) { 00664 $personal_urls['userpage'] = array( 00665 'text' => $this->username, 00666 'href' => &$this->userpageUrlDetails['href'], 00667 'class' => $this->userpageUrlDetails['exists'] ? false : 'new', 00668 'active' => ( $this->userpageUrlDetails['href'] == $pageurl ), 00669 'dir' => 'auto' 00670 ); 00671 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage ); 00672 $personal_urls['mytalk'] = array( 00673 'text' => $this->msg( 'mytalk' )->text(), 00674 'href' => &$usertalkUrlDetails['href'], 00675 'class' => $usertalkUrlDetails['exists'] ? false : 'new', 00676 'active' => ( $usertalkUrlDetails['href'] == $pageurl ) 00677 ); 00678 $href = self::makeSpecialUrl( 'Preferences' ); 00679 $personal_urls['preferences'] = array( 00680 'text' => $this->msg( 'mypreferences' )->text(), 00681 'href' => $href, 00682 'active' => ( $href == $pageurl ) 00683 ); 00684 00685 if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) { 00686 $href = self::makeSpecialUrl( 'Watchlist' ); 00687 $personal_urls['watchlist'] = array( 00688 'text' => $this->msg( 'mywatchlist' )->text(), 00689 'href' => $href, 00690 'active' => ( $href == $pageurl ) 00691 ); 00692 } 00693 00694 # We need to do an explicit check for Special:Contributions, as we 00695 # have to match both the title, and the target, which could come 00696 # from request values (Special:Contributions?target=Jimbo_Wales) 00697 # or be specified in "sub page" form 00698 # (Special:Contributions/Jimbo_Wales). The plot 00699 # thickens, because the Title object is altered for special pages, 00700 # so it doesn't contain the original alias-with-subpage. 00701 $origTitle = Title::newFromText( $request->getText( 'title' ) ); 00702 if ( $origTitle instanceof Title && $origTitle->isSpecialPage() ) { 00703 list( $spName, $spPar ) = SpecialPageFactory::resolveAlias( $origTitle->getText() ); 00704 $active = $spName == 'Contributions' 00705 && ( ( $spPar && $spPar == $this->username ) 00706 || $request->getText( 'target' ) == $this->username ); 00707 } else { 00708 $active = false; 00709 } 00710 00711 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username ); 00712 $personal_urls['mycontris'] = array( 00713 'text' => $this->msg( 'mycontris' )->text(), 00714 'href' => $href, 00715 'active' => $active 00716 ); 00717 $personal_urls['logout'] = array( 00718 'text' => $this->msg( 'pt-userlogout' )->text(), 00719 'href' => self::makeSpecialUrl( 'Userlogout', 00720 // userlogout link must always contain an & character, otherwise we might not be able 00721 // to detect a buggy precaching proxy (bug 17790) 00722 $title->isSpecial( 'Preferences' ) ? 'noreturnto' : $returnto 00723 ), 00724 'active' => false 00725 ); 00726 } else { 00727 $useCombinedLoginLink = $this->useCombinedLoginLink(); 00728 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink 00729 ? 'nav-login-createaccount' 00730 : 'pt-login'; 00731 $is_signup = $request->getText( 'type' ) == 'signup'; 00732 00733 $login_url = array( 00734 'text' => $this->msg( $loginlink )->text(), 00735 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ), 00736 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == 'nav-login-createaccount' || !$is_signup ), 00737 ); 00738 $createaccount_url = array( 00739 'text' => $this->msg( 'pt-createaccount' )->text(), 00740 'href' => self::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ), 00741 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup, 00742 ); 00743 00744 if ( $this->showIPinHeader() ) { 00745 $href = &$this->userpageUrlDetails['href']; 00746 $personal_urls['anonuserpage'] = array( 00747 'text' => $this->username, 00748 'href' => $href, 00749 'class' => $this->userpageUrlDetails['exists'] ? false : 'new', 00750 'active' => ( $pageurl == $href ) 00751 ); 00752 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage ); 00753 $href = &$usertalkUrlDetails['href']; 00754 $personal_urls['anontalk'] = array( 00755 'text' => $this->msg( 'anontalk' )->text(), 00756 'href' => $href, 00757 'class' => $usertalkUrlDetails['exists'] ? false : 'new', 00758 'active' => ( $pageurl == $href ) 00759 ); 00760 } 00761 00762 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) { 00763 $personal_urls['createaccount'] = $createaccount_url; 00764 } 00765 00766 $personal_urls['login'] = $login_url; 00767 } 00768 00769 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title, $this ) ); 00770 wfProfileOut( __METHOD__ ); 00771 return $personal_urls; 00772 } 00773 00785 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) { 00786 $classes = array(); 00787 if ( $selected ) { 00788 $classes[] = 'selected'; 00789 } 00790 if ( $checkEdit && !$title->isKnown() ) { 00791 $classes[] = 'new'; 00792 if ( $query !== '' ) { 00793 $query = 'action=edit&redlink=1&' . $query; 00794 } else { 00795 $query = 'action=edit&redlink=1'; 00796 } 00797 } 00798 00799 // wfMessageFallback will nicely accept $message as an array of fallbacks 00800 // or just a single key 00801 $msg = wfMessageFallback( $message )->setContext( $this->getContext() ); 00802 if ( is_array( $message ) ) { 00803 // for hook compatibility just keep the last message name 00804 $message = end( $message ); 00805 } 00806 if ( $msg->exists() ) { 00807 $text = $msg->text(); 00808 } else { 00809 global $wgContLang; 00810 $text = $wgContLang->getFormattedNsText( 00811 MWNamespace::getSubject( $title->getNamespace() ) ); 00812 } 00813 00814 $result = array(); 00815 if ( !wfRunHooks( 'SkinTemplateTabAction', array( &$this, 00816 $title, $message, $selected, $checkEdit, 00817 &$classes, &$query, &$text, &$result ) ) ) { 00818 return $result; 00819 } 00820 00821 return array( 00822 'class' => implode( ' ', $classes ), 00823 'text' => $text, 00824 'href' => $title->getLocalURL( $query ), 00825 'primary' => true ); 00826 } 00827 00828 function makeTalkUrlDetails( $name, $urlaction = '' ) { 00829 $title = Title::newFromText( $name ); 00830 if ( !is_object( $title ) ) { 00831 throw new MWException( __METHOD__ . " given invalid pagename $name" ); 00832 } 00833 $title = $title->getTalkPage(); 00834 self::checkTitle( $title, $name ); 00835 return array( 00836 'href' => $title->getLocalURL( $urlaction ), 00837 'exists' => $title->getArticleID() != 0, 00838 ); 00839 } 00840 00841 function makeArticleUrlDetails( $name, $urlaction = '' ) { 00842 $title = Title::newFromText( $name ); 00843 $title = $title->getSubjectPage(); 00844 self::checkTitle( $title, $name ); 00845 return array( 00846 'href' => $title->getLocalURL( $urlaction ), 00847 'exists' => $title->getArticleID() != 0, 00848 ); 00849 } 00850 00884 protected function buildContentNavigationUrls() { 00885 global $wgDisableLangConversion; 00886 00887 wfProfileIn( __METHOD__ ); 00888 00889 // Display tabs for the relevant title rather than always the title itself 00890 $title = $this->getRelevantTitle(); 00891 $onPage = $title->equals( $this->getTitle() ); 00892 00893 $out = $this->getOutput(); 00894 $request = $this->getRequest(); 00895 $user = $this->getUser(); 00896 00897 $content_navigation = array( 00898 'namespaces' => array(), 00899 'views' => array(), 00900 'actions' => array(), 00901 'variants' => array() 00902 ); 00903 00904 // parameters 00905 $action = $request->getVal( 'action', 'view' ); 00906 00907 $userCanRead = $title->quickUserCan( 'read', $user ); 00908 00909 $preventActiveTabs = false; 00910 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) ); 00911 00912 // Checks if page is some kind of content 00913 if ( $title->canExist() ) { 00914 // Gets page objects for the related namespaces 00915 $subjectPage = $title->getSubjectPage(); 00916 $talkPage = $title->getTalkPage(); 00917 00918 // Determines if this is a talk page 00919 $isTalk = $title->isTalkPage(); 00920 00921 // Generates XML IDs from namespace names 00922 $subjectId = $title->getNamespaceKey( '' ); 00923 00924 if ( $subjectId == 'main' ) { 00925 $talkId = 'talk'; 00926 } else { 00927 $talkId = "{$subjectId}_talk"; 00928 } 00929 00930 $skname = $this->skinname; 00931 00932 // Adds namespace links 00933 $subjectMsg = array( "nstab-$subjectId" ); 00934 if ( $subjectPage->isMainPage() ) { 00935 array_unshift( $subjectMsg, 'mainpage-nstab' ); 00936 } 00937 $content_navigation['namespaces'][$subjectId] = $this->tabAction( 00938 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead 00939 ); 00940 $content_navigation['namespaces'][$subjectId]['context'] = 'subject'; 00941 $content_navigation['namespaces'][$talkId] = $this->tabAction( 00942 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead 00943 ); 00944 $content_navigation['namespaces'][$talkId]['context'] = 'talk'; 00945 00946 if ( $userCanRead ) { 00947 $isForeignFile = $title->inNamespace( NS_FILE ) && $this->canUseWikiPage() && 00948 $this->getWikiPage() instanceof WikiFilePage && !$this->getWikiPage()->isLocal(); 00949 00950 // Adds view view link 00951 if ( $title->exists() || $isForeignFile ) { 00952 $content_navigation['views']['view'] = $this->tabAction( 00953 $isTalk ? $talkPage : $subjectPage, 00954 array( "$skname-view-view", 'view' ), 00955 ( $onPage && ( $action == 'view' || $action == 'purge' ) ), '', true 00956 ); 00957 // signal to hide this from simple content_actions 00958 $content_navigation['views']['view']['redundant'] = true; 00959 } 00960 00961 // If it is a non-local file, show a link to the file in its own repository 00962 if ( $isForeignFile ) { 00963 $file = $this->getWikiPage()->getFile(); 00964 $content_navigation['views']['view-foreign'] = array( 00965 'class' => '', 00966 'text' => wfMessageFallback( "$skname-view-foreign", 'view-foreign' )-> 00967 setContext( $this->getContext() )-> 00968 params( $file->getRepo()->getDisplayName() )->text(), 00969 'href' => $file->getDescriptionUrl(), 00970 'primary' => false, 00971 ); 00972 } 00973 00974 wfProfileIn( __METHOD__ . '-edit' ); 00975 00976 // Checks if user can edit the current page if it exists or create it otherwise 00977 if ( $title->quickUserCan( 'edit', $user ) && ( $title->exists() || $title->quickUserCan( 'create', $user ) ) ) { 00978 // Builds CSS class for talk page links 00979 $isTalkClass = $isTalk ? ' istalk' : ''; 00980 // Whether the user is editing the page 00981 $isEditing = $onPage && ( $action == 'edit' || $action == 'submit' ); 00982 // Whether to show the "Add a new section" tab 00983 // Checks if this is a current rev of talk page and is not forced to be hidden 00984 $showNewSection = !$out->forceHideNewSectionLink() 00985 && ( ( $isTalk && $this->isRevisionCurrent() ) || $out->showNewSectionLink() ); 00986 $section = $request->getVal( 'section' ); 00987 00988 if ( $title->exists() || ( $title->getNamespace() == NS_MEDIAWIKI && $title->getDefaultMessageText() !== false ) ) { 00989 $msgKey = $isForeignFile ? 'edit-local' : 'edit'; 00990 } else { 00991 $msgKey = $isForeignFile ? 'create-local' : 'create'; 00992 } 00993 $content_navigation['views']['edit'] = array( 00994 'class' => ( $isEditing && ( $section !== 'new' || !$showNewSection ) ? 'selected' : '' ) . $isTalkClass, 00995 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->setContext( $this->getContext() )->text(), 00996 'href' => $title->getLocalURL( $this->editUrlOptions() ), 00997 'primary' => !$isForeignFile, // don't collapse this in vector 00998 ); 00999 01000 // section link 01001 if ( $showNewSection ) { 01002 // Adds new section link 01003 //$content_navigation['actions']['addsection'] 01004 $content_navigation['views']['addsection'] = array( 01005 'class' => ( $isEditing && $section == 'new' ) ? 'selected' : false, 01006 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->setContext( $this->getContext() )->text(), 01007 'href' => $title->getLocalURL( 'action=edit§ion=new' ) 01008 ); 01009 } 01010 // Checks if the page has some kind of viewable content 01011 } elseif ( $title->hasSourceText() ) { 01012 // Adds view source view link 01013 $content_navigation['views']['viewsource'] = array( 01014 'class' => ( $onPage && $action == 'edit' ) ? 'selected' : false, 01015 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->setContext( $this->getContext() )->text(), 01016 'href' => $title->getLocalURL( $this->editUrlOptions() ), 01017 'primary' => true, // don't collapse this in vector 01018 ); 01019 } 01020 wfProfileOut( __METHOD__ . '-edit' ); 01021 01022 wfProfileIn( __METHOD__ . '-live' ); 01023 // Checks if the page exists 01024 if ( $title->exists() ) { 01025 // Adds history view link 01026 $content_navigation['views']['history'] = array( 01027 'class' => ( $onPage && $action == 'history' ) ? 'selected' : false, 01028 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->setContext( $this->getContext() )->text(), 01029 'href' => $title->getLocalURL( 'action=history' ), 01030 'rel' => 'archives', 01031 ); 01032 01033 if ( $title->quickUserCan( 'delete', $user ) ) { 01034 $content_navigation['actions']['delete'] = array( 01035 'class' => ( $onPage && $action == 'delete' ) ? 'selected' : false, 01036 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->setContext( $this->getContext() )->text(), 01037 'href' => $title->getLocalURL( 'action=delete' ) 01038 ); 01039 } 01040 01041 if ( $title->quickUserCan( 'move', $user ) ) { 01042 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $title->getPrefixedDBkey() ); 01043 $content_navigation['actions']['move'] = array( 01044 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ? 'selected' : false, 01045 'text' => wfMessageFallback( "$skname-action-move", 'move' )->setContext( $this->getContext() )->text(), 01046 'href' => $moveTitle->getLocalURL() 01047 ); 01048 } 01049 } else { 01050 // article doesn't exist or is deleted 01051 if ( $user->isAllowed( 'deletedhistory' ) ) { 01052 $n = $title->isDeleted(); 01053 if ( $n ) { 01054 $undelTitle = SpecialPage::getTitleFor( 'Undelete' ); 01055 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead 01056 $msgKey = $user->isAllowed( 'undelete' ) ? 'undelete' : 'viewdeleted'; 01057 $content_navigation['actions']['undelete'] = array( 01058 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ? 'selected' : false, 01059 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" ) 01060 ->setContext( $this->getContext() )->numParams( $n )->text(), 01061 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) ) 01062 ); 01063 } 01064 } 01065 } 01066 01067 if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() && 01068 MWNamespace::getRestrictionLevels( $title->getNamespace(), $user ) !== array( '' ) 01069 ) { 01070 $mode = $title->isProtected() ? 'unprotect' : 'protect'; 01071 $content_navigation['actions'][$mode] = array( 01072 'class' => ( $onPage && $action == $mode ) ? 'selected' : false, 01073 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->setContext( $this->getContext() )->text(), 01074 'href' => $title->getLocalURL( "action=$mode" ) 01075 ); 01076 } 01077 01078 wfProfileOut( __METHOD__ . '-live' ); 01079 01080 // Checks if the user is logged in 01081 if ( $this->loggedin && $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) { 01091 $mode = $user->isWatched( $title ) ? 'unwatch' : 'watch'; 01092 $token = WatchAction::getWatchToken( $title, $user, $mode ); 01093 $content_navigation['actions'][$mode] = array( 01094 'class' => $onPage && ( $action == 'watch' || $action == 'unwatch' ) ? 'selected' : false, 01095 // uses 'watch' or 'unwatch' message 01096 'text' => $this->msg( $mode )->text(), 01097 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) ) 01098 ); 01099 } 01100 } 01101 01102 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) ); 01103 01104 if ( $userCanRead && !$wgDisableLangConversion ) { 01105 $pageLang = $title->getPageLanguage(); 01106 // Gets list of language variants 01107 $variants = $pageLang->getVariants(); 01108 // Checks that language conversion is enabled and variants exist 01109 // And if it is not in the special namespace 01110 if ( count( $variants ) > 1 ) { 01111 // Gets preferred variant (note that user preference is 01112 // only possible for wiki content language variant) 01113 $preferred = $pageLang->getPreferredVariant(); 01114 if ( Action::getActionName( $this ) === 'view' ) { 01115 $params = $request->getQueryValues(); 01116 unset( $params['title'] ); 01117 } else { 01118 $params = array(); 01119 } 01120 // Loops over each variant 01121 foreach ( $variants as $code ) { 01122 // Gets variant name from language code 01123 $varname = $pageLang->getVariantname( $code ); 01124 // Appends variant link 01125 $content_navigation['variants'][] = array( 01126 'class' => ( $code == $preferred ) ? 'selected' : false, 01127 'text' => $varname, 01128 'href' => $title->getLocalURL( array( 'variant' => $code ) + $params ), 01129 'lang' => wfBCP47( $code ), 01130 'hreflang' => wfBCP47( $code ), 01131 ); 01132 } 01133 } 01134 } 01135 } else { 01136 // If it's not content, it's got to be a special page 01137 $content_navigation['namespaces']['special'] = array( 01138 'class' => 'selected', 01139 'text' => $this->msg( 'nstab-special' )->text(), 01140 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510 01141 'context' => 'subject' 01142 ); 01143 01144 wfRunHooks( 'SkinTemplateNavigation::SpecialPage', 01145 array( &$this, &$content_navigation ) ); 01146 } 01147 01148 // Equiv to SkinTemplateContentActions 01149 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) ); 01150 01151 // Setup xml ids and tooltip info 01152 foreach ( $content_navigation as $section => &$links ) { 01153 foreach ( $links as $key => &$link ) { 01154 $xmlID = $key; 01155 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) { 01156 $xmlID = 'ca-nstab-' . $xmlID; 01157 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) { 01158 $xmlID = 'ca-talk'; 01159 } elseif ( $section == 'variants' ) { 01160 $xmlID = 'ca-varlang-' . $xmlID; 01161 } else { 01162 $xmlID = 'ca-' . $xmlID; 01163 } 01164 $link['id'] = $xmlID; 01165 } 01166 } 01167 01168 # We don't want to give the watch tab an accesskey if the 01169 # page is being edited, because that conflicts with the 01170 # accesskey on the watch checkbox. We also don't want to 01171 # give the edit tab an accesskey, because that's fairly 01172 # superfluous and conflicts with an accesskey (Ctrl-E) often 01173 # used for editing in Safari. 01174 if ( in_array( $action, array( 'edit', 'submit' ) ) ) { 01175 if ( isset( $content_navigation['views']['edit'] ) ) { 01176 $content_navigation['views']['edit']['tooltiponly'] = true; 01177 } 01178 if ( isset( $content_navigation['actions']['watch'] ) ) { 01179 $content_navigation['actions']['watch']['tooltiponly'] = true; 01180 } 01181 if ( isset( $content_navigation['actions']['unwatch'] ) ) { 01182 $content_navigation['actions']['unwatch']['tooltiponly'] = true; 01183 } 01184 } 01185 01186 wfProfileOut( __METHOD__ ); 01187 01188 return $content_navigation; 01189 } 01190 01196 function buildContentActionUrls( $content_navigation ) { 01197 01198 wfProfileIn( __METHOD__ ); 01199 01200 // content_actions has been replaced with content_navigation for backwards 01201 // compatibility and also for skins that just want simple tabs content_actions 01202 // is now built by flattening the content_navigation arrays into one 01203 01204 $content_actions = array(); 01205 01206 foreach ( $content_navigation as $links ) { 01207 01208 foreach ( $links as $key => $value ) { 01209 01210 if ( isset( $value['redundant'] ) && $value['redundant'] ) { 01211 // Redundant tabs are dropped from content_actions 01212 continue; 01213 } 01214 01215 // content_actions used to have ids built using the "ca-$key" pattern 01216 // so the xmlID based id is much closer to the actual $key that we want 01217 // for that reason we'll just strip out the ca- if present and use 01218 // the latter potion of the "id" as the $key 01219 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) { 01220 $key = substr( $value['id'], 3 ); 01221 } 01222 01223 if ( isset( $content_actions[$key] ) ) { 01224 wfDebug( __METHOD__ . ": Found a duplicate key for $key while flattening " . 01225 "content_navigation into content_actions.\n" ); 01226 continue; 01227 } 01228 01229 $content_actions[$key] = $value; 01230 01231 } 01232 01233 } 01234 01235 wfProfileOut( __METHOD__ ); 01236 01237 return $content_actions; 01238 } 01239 01245 protected function buildNavUrls() { 01246 global $wgUploadNavigationUrl; 01247 01248 wfProfileIn( __METHOD__ ); 01249 01250 $out = $this->getOutput(); 01251 $request = $this->getRequest(); 01252 01253 $nav_urls = array(); 01254 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() ); 01255 if ( $wgUploadNavigationUrl ) { 01256 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl ); 01257 } elseif ( UploadBase::isEnabled() && UploadBase::isAllowed( $this->getUser() ) === true ) { 01258 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) ); 01259 } else { 01260 $nav_urls['upload'] = false; 01261 } 01262 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) ); 01263 01264 $nav_urls['print'] = false; 01265 $nav_urls['permalink'] = false; 01266 $nav_urls['info'] = false; 01267 $nav_urls['whatlinkshere'] = false; 01268 $nav_urls['recentchangeslinked'] = false; 01269 $nav_urls['contributions'] = false; 01270 $nav_urls['log'] = false; 01271 $nav_urls['blockip'] = false; 01272 $nav_urls['emailuser'] = false; 01273 $nav_urls['userrights'] = false; 01274 01275 // A print stylesheet is attached to all pages, but nobody ever 01276 // figures that out. :) Add a link... 01277 if ( !$out->isPrintable() && ( $out->isArticle() || $this->getTitle()->isSpecialPage() ) ) { 01278 $nav_urls['print'] = array( 01279 'text' => $this->msg( 'printableversion' )->text(), 01280 'href' => $this->getTitle()->getLocalURL( 01281 $request->appendQueryValue( 'printable', 'yes', true ) ) 01282 ); 01283 } 01284 01285 if ( $out->isArticle() ) { 01286 // Also add a "permalink" while we're at it 01287 $revid = $this->getRevisionId(); 01288 if ( $revid ) { 01289 $nav_urls['permalink'] = array( 01290 'text' => $this->msg( 'permalink' )->text(), 01291 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" ) 01292 ); 01293 } 01294 01295 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals 01296 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', 01297 array( &$this, &$nav_urls, &$revid, &$revid ) ); 01298 } 01299 01300 if ( $out->isArticleRelated() ) { 01301 $nav_urls['whatlinkshere'] = array( 01302 'href' => SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage )->getLocalURL() 01303 ); 01304 01305 $nav_urls['info'] = array( 01306 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(), 01307 'href' => $this->getTitle()->getLocalURL( "action=info" ) 01308 ); 01309 01310 if ( $this->getTitle()->getArticleID() ) { 01311 $nav_urls['recentchangeslinked'] = array( 01312 'href' => SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage )->getLocalURL() 01313 ); 01314 } 01315 } 01316 01317 $user = $this->getRelevantUser(); 01318 if ( $user ) { 01319 $rootUser = $user->getName(); 01320 01321 $nav_urls['contributions'] = array( 01322 'text' => $this->msg( 'contributions', $rootUser )->text(), 01323 'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser ) 01324 ); 01325 01326 $nav_urls['log'] = array( 01327 'href' => self::makeSpecialUrlSubpage( 'Log', $rootUser ) 01328 ); 01329 01330 if ( $this->getUser()->isAllowed( 'block' ) ) { 01331 $nav_urls['blockip'] = array( 01332 'href' => self::makeSpecialUrlSubpage( 'Block', $rootUser ) 01333 ); 01334 } 01335 01336 if ( $this->showEmailUser( $user ) ) { 01337 $nav_urls['emailuser'] = array( 01338 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser ) 01339 ); 01340 } 01341 01342 if ( !$user->isAnon() ) { 01343 $sur = new UserrightsPage; 01344 $sur->setContext( $this->getContext() ); 01345 if ( $sur->userCanExecute( $this->getUser() ) ) { 01346 $nav_urls['userrights'] = array( 01347 'href' => self::makeSpecialUrlSubpage( 'Userrights', $rootUser ) 01348 ); 01349 } 01350 } 01351 } 01352 01353 wfProfileOut( __METHOD__ ); 01354 return $nav_urls; 01355 } 01356 01362 function getNameSpaceKey() { 01363 return $this->getTitle()->getNamespaceKey(); 01364 } 01365 } 01366 01372 abstract class QuickTemplate { 01376 function __construct() { 01377 $this->data = array(); 01378 $this->translator = new MediaWiki_I18N(); 01379 } 01380 01386 public function set( $name, $value ) { 01387 $this->data[$name] = $value; 01388 } 01389 01397 public function get( $name, $default = null ) { 01398 if ( isset( $this->data[$name] ) ) { 01399 return $this->data[$name]; 01400 } else { 01401 return $default; 01402 } 01403 } 01404 01409 public function setRef( $name, &$value ) { 01410 $this->data[$name] =& $value; 01411 } 01412 01416 public function setTranslator( &$t ) { 01417 $this->translator = &$t; 01418 } 01419 01424 abstract public function execute(); 01425 01429 function text( $str ) { 01430 echo htmlspecialchars( $this->data[$str] ); 01431 } 01432 01436 function html( $str ) { 01437 echo $this->data[$str]; 01438 } 01439 01443 function msg( $str ) { 01444 echo htmlspecialchars( $this->translator->translate( $str ) ); 01445 } 01446 01450 function msgHtml( $str ) { 01451 echo $this->translator->translate( $str ); 01452 } 01453 01458 function msgWiki( $str ) { 01459 global $wgOut; 01460 01461 $text = $this->translator->translate( $str ); 01462 echo $wgOut->parse( $text ); 01463 } 01464 01469 function haveData( $str ) { 01470 return isset( $this->data[$str] ); 01471 } 01472 01478 function haveMsg( $str ) { 01479 $msg = $this->translator->translate( $str ); 01480 return ( $msg != '-' ) && ( $msg != '' ); # ???? 01481 } 01482 01488 public function getSkin() { 01489 return $this->data['skin']; 01490 } 01491 01498 public function getHTML() { 01499 ob_start(); 01500 $this->execute(); 01501 $html = ob_get_contents(); 01502 ob_end_clean(); 01503 return $html; 01504 } 01505 } 01506 01512 abstract class BaseTemplate extends QuickTemplate { 01513 01520 public function getMsg( $name ) { 01521 return $this->getSkin()->msg( $name ); 01522 } 01523 01524 function msg( $str ) { 01525 echo $this->getMsg( $str )->escaped(); 01526 } 01527 01528 function msgHtml( $str ) { 01529 echo $this->getMsg( $str )->text(); 01530 } 01531 01532 function msgWiki( $str ) { 01533 echo $this->getMsg( $str )->parseAsBlock(); 01534 } 01535 01543 function getToolbox() { 01544 wfProfileIn( __METHOD__ ); 01545 01546 $toolbox = array(); 01547 if ( isset( $this->data['nav_urls']['whatlinkshere'] ) && $this->data['nav_urls']['whatlinkshere'] ) { 01548 $toolbox['whatlinkshere'] = $this->data['nav_urls']['whatlinkshere']; 01549 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere'; 01550 } 01551 if ( isset( $this->data['nav_urls']['recentchangeslinked'] ) && $this->data['nav_urls']['recentchangeslinked'] ) { 01552 $toolbox['recentchangeslinked'] = $this->data['nav_urls']['recentchangeslinked']; 01553 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox'; 01554 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked'; 01555 } 01556 if ( isset( $this->data['feeds'] ) && $this->data['feeds'] ) { 01557 $toolbox['feeds']['id'] = 'feedlinks'; 01558 $toolbox['feeds']['links'] = array(); 01559 foreach ( $this->data['feeds'] as $key => $feed ) { 01560 $toolbox['feeds']['links'][$key] = $feed; 01561 $toolbox['feeds']['links'][$key]['id'] = "feed-$key"; 01562 $toolbox['feeds']['links'][$key]['rel'] = 'alternate'; 01563 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml"; 01564 $toolbox['feeds']['links'][$key]['class'] = 'feedlink'; 01565 } 01566 } 01567 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'userrights', 'upload', 'specialpages' ) as $special ) { 01568 if ( isset( $this->data['nav_urls'][$special] ) && $this->data['nav_urls'][$special] ) { 01569 $toolbox[$special] = $this->data['nav_urls'][$special]; 01570 $toolbox[$special]['id'] = "t-$special"; 01571 } 01572 } 01573 if ( isset( $this->data['nav_urls']['print'] ) && $this->data['nav_urls']['print'] ) { 01574 $toolbox['print'] = $this->data['nav_urls']['print']; 01575 $toolbox['print']['id'] = 't-print'; 01576 $toolbox['print']['rel'] = 'alternate'; 01577 $toolbox['print']['msg'] = 'printableversion'; 01578 } 01579 if ( isset( $this->data['nav_urls']['permalink'] ) && $this->data['nav_urls']['permalink'] ) { 01580 $toolbox['permalink'] = $this->data['nav_urls']['permalink']; 01581 if ( $toolbox['permalink']['href'] === '' ) { 01582 unset( $toolbox['permalink']['href'] ); 01583 $toolbox['ispermalink']['tooltiponly'] = true; 01584 $toolbox['ispermalink']['id'] = 't-ispermalink'; 01585 $toolbox['ispermalink']['msg'] = 'permalink'; 01586 } else { 01587 $toolbox['permalink']['id'] = 't-permalink'; 01588 } 01589 } 01590 if ( isset( $this->data['nav_urls']['info'] ) && $this->data['nav_urls']['info'] ) { 01591 $toolbox['info'] = $this->data['nav_urls']['info']; 01592 $toolbox['info']['id'] = 't-info'; 01593 } 01594 01595 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) ); 01596 wfProfileOut( __METHOD__ ); 01597 return $toolbox; 01598 } 01599 01610 function getPersonalTools() { 01611 $personal_tools = array(); 01612 foreach ( $this->get( 'personal_urls' ) as $key => $plink ) { 01613 # The class on a personal_urls item is meant to go on the <a> instead 01614 # of the <li> so we have to use a single item "links" array instead 01615 # of using most of the personal_url's keys directly. 01616 $ptool = array( 01617 'links' => array( 01618 array( 'single-id' => "pt-$key" ), 01619 ), 01620 'id' => "pt-$key", 01621 ); 01622 if ( isset( $plink['active'] ) ) { 01623 $ptool['active'] = $plink['active']; 01624 } 01625 foreach ( array( 'href', 'class', 'text', 'dir' ) as $k ) { 01626 if ( isset( $plink[$k] ) ) { 01627 $ptool['links'][0][$k] = $plink[$k]; 01628 } 01629 } 01630 $personal_tools[$key] = $ptool; 01631 } 01632 return $personal_tools; 01633 } 01634 01635 function getSidebar( $options = array() ) { 01636 // Force the rendering of the following portals 01637 $sidebar = $this->data['sidebar']; 01638 if ( !isset( $sidebar['SEARCH'] ) ) { 01639 $sidebar['SEARCH'] = true; 01640 } 01641 if ( !isset( $sidebar['TOOLBOX'] ) ) { 01642 $sidebar['TOOLBOX'] = true; 01643 } 01644 if ( !isset( $sidebar['LANGUAGES'] ) ) { 01645 $sidebar['LANGUAGES'] = true; 01646 } 01647 01648 if ( !isset( $options['search'] ) || $options['search'] !== true ) { 01649 unset( $sidebar['SEARCH'] ); 01650 } 01651 if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) { 01652 unset( $sidebar['TOOLBOX'] ); 01653 } 01654 if ( isset( $options['languages'] ) && $options['languages'] === false ) { 01655 unset( $sidebar['LANGUAGES'] ); 01656 } 01657 01658 $boxes = array(); 01659 foreach ( $sidebar as $boxName => $content ) { 01660 if ( $content === false ) { 01661 continue; 01662 } 01663 switch ( $boxName ) { 01664 case 'SEARCH': 01665 // Search is a special case, skins should custom implement this 01666 $boxes[$boxName] = array( 01667 'id' => 'p-search', 01668 'header' => $this->getMsg( 'search' )->text(), 01669 'generated' => false, 01670 'content' => true, 01671 ); 01672 break; 01673 case 'TOOLBOX': 01674 $msgObj = $this->getMsg( 'toolbox' ); 01675 $boxes[$boxName] = array( 01676 'id' => 'p-tb', 01677 'header' => $msgObj->exists() ? $msgObj->text() : 'toolbox', 01678 'generated' => false, 01679 'content' => $this->getToolbox(), 01680 ); 01681 break; 01682 case 'LANGUAGES': 01683 if ( $this->data['language_urls'] ) { 01684 $msgObj = $this->getMsg( 'otherlanguages' ); 01685 $boxes[$boxName] = array( 01686 'id' => 'p-lang', 01687 'header' => $msgObj->exists() ? $msgObj->text() : 'otherlanguages', 01688 'generated' => false, 01689 'content' => $this->data['language_urls'], 01690 ); 01691 } 01692 break; 01693 default: 01694 $msgObj = $this->getMsg( $boxName ); 01695 $boxes[$boxName] = array( 01696 'id' => "p-$boxName", 01697 'header' => $msgObj->exists() ? $msgObj->text() : $boxName, 01698 'generated' => true, 01699 'content' => $content, 01700 ); 01701 break; 01702 } 01703 } 01704 01705 // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd 01706 $hookContents = null; 01707 if ( isset( $boxes['TOOLBOX'] ) ) { 01708 ob_start(); 01709 // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox 01710 // can abort and avoid outputting double toolbox links 01711 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) ); 01712 $hookContents = ob_get_contents(); 01713 ob_end_clean(); 01714 if ( !trim( $hookContents ) ) { 01715 $hookContents = null; 01716 } 01717 } 01718 // END hack 01719 01720 if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) { 01721 foreach ( $boxes as $boxName => $box ) { 01722 if ( is_array( $box['content'] ) ) { 01723 $content = '<ul>'; 01724 foreach ( $box['content'] as $key => $val ) { 01725 $content .= "\n " . $this->makeListItem( $key, $val ); 01726 } 01727 // HACK, shove the toolbox end onto the toolbox if we're rendering itself 01728 if ( $hookContents ) { 01729 $content .= "\n $hookContents"; 01730 } 01731 // END hack 01732 $content .= "\n</ul>\n"; 01733 $boxes[$boxName]['content'] = $content; 01734 } 01735 } 01736 } else { 01737 if ( $hookContents ) { 01738 $boxes['TOOLBOXEND'] = array( 01739 'id' => 'p-toolboxend', 01740 'header' => $boxes['TOOLBOX']['header'], 01741 'generated' => false, 01742 'content' => "<ul>{$hookContents}</ul>", 01743 ); 01744 // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX 01745 $boxes2 = array(); 01746 foreach ( $boxes as $key => $box ) { 01747 if ( $key === 'TOOLBOXEND' ) { 01748 continue; 01749 } 01750 $boxes2[$key] = $box; 01751 if ( $key === 'TOOLBOX' ) { 01752 $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND']; 01753 } 01754 } 01755 $boxes = $boxes2; 01756 // END hack 01757 } 01758 } 01759 01760 return $boxes; 01761 } 01762 01766 protected function renderAfterPortlet( $name ) { 01767 $content = ''; 01768 wfRunHooks( 'BaseTemplateAfterPortlet', array( $this, $name, &$content ) ); 01769 01770 if ( $content !== '' ) { 01771 echo "<div class='after-portlet after-portlet-$name'>$content</div>"; 01772 } 01773 01774 } 01775 01819 function makeLink( $key, $item, $options = array() ) { 01820 if ( isset( $item['text'] ) ) { 01821 $text = $item['text']; 01822 } else { 01823 $text = $this->translator->translate( isset( $item['msg'] ) ? $item['msg'] : $key ); 01824 } 01825 01826 $html = htmlspecialchars( $text ); 01827 01828 if ( isset( $options['text-wrapper'] ) ) { 01829 $wrapper = $options['text-wrapper']; 01830 if ( isset( $wrapper['tag'] ) ) { 01831 $wrapper = array( $wrapper ); 01832 } 01833 while ( count( $wrapper ) > 0 ) { 01834 $element = array_pop( $wrapper ); 01835 $html = Html::rawElement( $element['tag'], isset( $element['attributes'] ) ? $element['attributes'] : null, $html ); 01836 } 01837 } 01838 01839 if ( isset( $item['href'] ) || isset( $options['link-fallback'] ) ) { 01840 $attrs = $item; 01841 foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly', 'context', 'primary' ) as $k ) { 01842 unset( $attrs[$k] ); 01843 } 01844 01845 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) { 01846 $item['single-id'] = $item['id']; 01847 } 01848 if ( isset( $item['single-id'] ) ) { 01849 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) { 01850 $title = Linker::titleAttrib( $item['single-id'] ); 01851 if ( $title !== false ) { 01852 $attrs['title'] = $title; 01853 } 01854 } else { 01855 $tip = Linker::tooltipAndAccesskeyAttribs( $item['single-id'] ); 01856 if ( isset( $tip['title'] ) && $tip['title'] !== false ) { 01857 $attrs['title'] = $tip['title']; 01858 } 01859 if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) { 01860 $attrs['accesskey'] = $tip['accesskey']; 01861 } 01862 } 01863 } 01864 if ( isset( $options['link-class'] ) ) { 01865 if ( isset( $attrs['class'] ) ) { 01866 $attrs['class'] .= " {$options['link-class']}"; 01867 } else { 01868 $attrs['class'] = $options['link-class']; 01869 } 01870 } 01871 $html = Html::rawElement( isset( $attrs['href'] ) ? 'a' : $options['link-fallback'], $attrs, $html ); 01872 } 01873 01874 return $html; 01875 } 01876 01905 function makeListItem( $key, $item, $options = array() ) { 01906 if ( isset( $item['links'] ) ) { 01907 $links = array(); 01908 foreach ( $item['links'] as $linkKey => $link ) { 01909 $links[] = $this->makeLink( $linkKey, $link, $options ); 01910 } 01911 $html = implode( ' ', $links ); 01912 } else { 01913 $link = $item; 01914 // These keys are used by makeListItem and shouldn't be passed on to the link 01915 foreach ( array( 'id', 'class', 'active', 'tag', 'itemtitle' ) as $k ) { 01916 unset( $link[$k] ); 01917 } 01918 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) { 01919 // The id goes on the <li> not on the <a> for single links 01920 // but makeSidebarLink still needs to know what id to use when 01921 // generating tooltips and accesskeys. 01922 $link['single-id'] = $item['id']; 01923 } 01924 $html = $this->makeLink( $key, $link, $options ); 01925 } 01926 01927 $attrs = array(); 01928 foreach ( array( 'id', 'class' ) as $attr ) { 01929 if ( isset( $item[$attr] ) ) { 01930 $attrs[$attr] = $item[$attr]; 01931 } 01932 } 01933 if ( isset( $item['active'] ) && $item['active'] ) { 01934 if ( !isset( $attrs['class'] ) ) { 01935 $attrs['class'] = ''; 01936 } 01937 $attrs['class'] .= ' active'; 01938 $attrs['class'] = trim( $attrs['class'] ); 01939 } 01940 if ( isset( $item['itemtitle'] ) ) { 01941 $attrs['title'] = $item['itemtitle']; 01942 } 01943 return Html::rawElement( isset( $options['tag'] ) ? $options['tag'] : 'li', $attrs, $html ); 01944 } 01945 01946 function makeSearchInput( $attrs = array() ) { 01947 $realAttrs = array( 01948 'type' => 'search', 01949 'name' => 'search', 01950 'placeholder' => wfMessage( 'searchsuggest-search' )->text(), 01951 'value' => $this->get( 'search', '' ), 01952 ); 01953 $realAttrs = array_merge( $realAttrs, Linker::tooltipAndAccesskeyAttribs( 'search' ), $attrs ); 01954 return Html::element( 'input', $realAttrs ); 01955 } 01956 01957 function makeSearchButton( $mode, $attrs = array() ) { 01958 switch ( $mode ) { 01959 case 'go': 01960 case 'fulltext': 01961 $realAttrs = array( 01962 'type' => 'submit', 01963 'name' => $mode, 01964 'value' => $this->translator->translate( 01965 $mode == 'go' ? 'searcharticle' : 'searchbutton' ), 01966 ); 01967 $realAttrs = array_merge( 01968 $realAttrs, 01969 Linker::tooltipAndAccesskeyAttribs( "search-$mode" ), 01970 $attrs 01971 ); 01972 return Html::element( 'input', $realAttrs ); 01973 case 'image': 01974 $buttonAttrs = array( 01975 'type' => 'submit', 01976 'name' => 'button', 01977 ); 01978 $buttonAttrs = array_merge( 01979 $buttonAttrs, 01980 Linker::tooltipAndAccesskeyAttribs( 'search-fulltext' ), 01981 $attrs 01982 ); 01983 unset( $buttonAttrs['src'] ); 01984 unset( $buttonAttrs['alt'] ); 01985 unset( $buttonAttrs['width'] ); 01986 unset( $buttonAttrs['height'] ); 01987 $imgAttrs = array( 01988 'src' => $attrs['src'], 01989 'alt' => isset( $attrs['alt'] ) 01990 ? $attrs['alt'] 01991 : $this->translator->translate( 'searchbutton' ), 01992 'width' => isset( $attrs['width'] ) ? $attrs['width'] : null, 01993 'height' => isset( $attrs['height'] ) ? $attrs['height'] : null, 01994 ); 01995 return Html::rawElement( 'button', $buttonAttrs, Html::element( 'img', $imgAttrs ) ); 01996 default: 01997 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' ); 01998 } 01999 } 02000 02009 function getFooterLinks( $option = null ) { 02010 $footerlinks = $this->get( 'footerlinks' ); 02011 02012 // Reduce footer links down to only those which are being used 02013 $validFooterLinks = array(); 02014 foreach ( $footerlinks as $category => $links ) { 02015 $validFooterLinks[$category] = array(); 02016 foreach ( $links as $link ) { 02017 if ( isset( $this->data[$link] ) && $this->data[$link] ) { 02018 $validFooterLinks[$category][] = $link; 02019 } 02020 } 02021 if ( count( $validFooterLinks[$category] ) <= 0 ) { 02022 unset( $validFooterLinks[$category] ); 02023 } 02024 } 02025 02026 if ( $option == 'flat' ) { 02027 // fold footerlinks into a single array using a bit of trickery 02028 $validFooterLinks = call_user_func_array( 02029 'array_merge', 02030 array_values( $validFooterLinks ) 02031 ); 02032 } 02033 02034 return $validFooterLinks; 02035 } 02036 02048 function getFooterIcons( $option = null ) { 02049 // Generate additional footer icons 02050 $footericons = $this->get( 'footericons' ); 02051 02052 if ( $option == 'icononly' ) { 02053 // Unset any icons which don't have an image 02054 foreach ( $footericons as &$footerIconsBlock ) { 02055 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) { 02056 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) { 02057 unset( $footerIconsBlock[$footerIconKey] ); 02058 } 02059 } 02060 } 02061 // Redo removal of any empty blocks 02062 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) { 02063 if ( count( $footerIconsBlock ) <= 0 ) { 02064 unset( $footericons[$footerIconsKey] ); 02065 } 02066 } 02067 } elseif ( $option == 'nocopyright' ) { 02068 unset( $footericons['copyright']['copyright'] ); 02069 if ( count( $footericons['copyright'] ) <= 0 ) { 02070 unset( $footericons['copyright'] ); 02071 } 02072 } 02073 02074 return $footericons; 02075 } 02076 02082 function printTrail() { ?> 02083 <?php echo MWDebug::getDebugHTML( $this->getSkin()->getContext() ); ?> 02084 <?php $this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?> 02085 <?php $this->html( 'reporttime' ) ?> 02086 <?php 02087 } 02088 02089 }