X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSkin.php;h=fe4bb93974d3d6c65be670631ee7a2244361d451;hb=2cdff4cf67b77a3a7bb54c656a05bfe8a529ae3d;hp=4c91987dc31be0af1f32f358e291937c0b68c76d;hpb=3328372650d06234fb666f5f071d81e804711881;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Skin.php b/includes/Skin.php index 4c91987dc3..fe4bb93974 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -2,38 +2,34 @@ if ( ! defined( 'MEDIAWIKI' ) ) die( 1 ); -/** - * - * @package MediaWiki - * @subpackage Skins - */ - # See skin.txt /** * The main skin class that provide methods and properties for all other skins. * This base class is also the "Standard" skin. - * @package MediaWiki + * + * See docs/skin.txt for more information. + * + * @addtogroup Skins */ class Skin extends Linker { /**#@+ * @private */ - var $lastdate, $lastline; - var $rc_cache ; # Cache for Enhanced Recent Changes - var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle - var $rcMoveIndex; + var $mWatchLinkNum = 0; // Appended to end of watch link id's /**#@-*/ + protected $mRevisionId; // The revision ID we're looking at, null if not applicable. + protected $skinname = 'standard' ; /** Constructor, call parent constructor */ - function Skin() { parent::Linker(); } + function Skin() { parent::__construct(); } /** * Fetch the set of available skins. * @return array of strings * @static */ - static function &getSkinNames() { + static function getSkinNames() { global $wgValidSkinNames; static $skinsInitialised = false; if ( !$skinsInitialised ) { @@ -48,6 +44,7 @@ class Skin extends Linker { # while code from www.php.net while (false !== ($file = $skinDir->read())) { // Skip non-PHP files, hidden files, and '.dep' includes + $matches = array(); if(preg_match('/^([^.]*)\.php$/',$file, $matches)) { $aSkin = $matches[1]; $wgValidSkinNames[strtolower($aSkin)] = $aSkin; @@ -96,8 +93,7 @@ class Skin extends Linker { if( isset( $skinNames[$key] ) ) { return $key; } else { - // The old built-in skin - return 'standard'; + return 'monobook'; } } @@ -114,24 +110,25 @@ class Skin extends Linker { $skinNames = Skin::getSkinNames(); $skinName = $skinNames[$key]; + $className = 'Skin'.ucfirst($key); # Grab the skin class and initialise it. - wfSuppressWarnings(); - // Preload base classes to work around APC/PHP5 bug - include_once( "{$wgStyleDirectory}/{$skinName}.deps.php" ); - wfRestoreWarnings(); - require_once( "{$wgStyleDirectory}/{$skinName}.php" ); - - # Check if we got if not failback to default skin - $className = 'Skin'.$skinName; - if( !class_exists( $className ) ) { - # DO NOT die if the class isn't found. This breaks maintenance - # scripts and can cause a user account to be unrecoverable - # except by SQL manipulation if a previously valid skin name - # is no longer valid. - wfDebug( "Skin class does not exist: $className\n" ); - $className = 'SkinStandard'; - require_once( "{$wgStyleDirectory}/Standard.php" ); + if ( !class_exists( $className ) ) { + // Preload base classes to work around APC/PHP5 bug + $deps = "{$wgStyleDirectory}/{$skinName}.deps.php"; + if( file_exists( $deps ) ) include_once( $deps ); + require_once( "{$wgStyleDirectory}/{$skinName}.php" ); + + # Check if we got if not failback to default skin + if( !class_exists( $className ) ) { + # DO NOT die if the class isn't found. This breaks maintenance + # scripts and can cause a user account to be unrecoverable + # except by SQL manipulation if a previously valid skin name + # is no longer valid. + wfDebug( "Skin class does not exist: $className\n" ); + $className = 'SkinMonobook'; + require_once( "{$wgStyleDirectory}/MonoBook.php" ); + } } $skin = new $className; return $skin; @@ -139,38 +136,45 @@ class Skin extends Linker { /** @return string path to the skin stylesheet */ function getStylesheet() { - return 'common/wikistandard.css?1'; + return 'common/wikistandard.css'; } /** @return string skin name */ - function getSkinName() { - return 'standard'; + public function getSkinName() { + return $this->skinname; } function qbSetting() { global $wgOut, $wgUser; if ( $wgOut->isQuickbarSuppressed() ) { return 0; } - $q = $wgUser->getOption( 'quickbar' ); - if ( '' == $q ) { $q = 0; } + $q = $wgUser->getOption( 'quickbar', 0 ); return $q; } function initPage( &$out ) { - global $wgFavicon, $wgScriptPath; + global $wgFavicon, $wgAppleTouchIcon, $wgScriptPath, $wgSitename, $wgContLang; - $fname = 'Skin::initPage'; - wfProfileIn( $fname ); + wfProfileIn( __METHOD__ ); if( false !== $wgFavicon ) { $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) ); } + + if( false !== $wgAppleTouchIcon ) { + $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) ); + } + + $code = $wgContLang->getCode(); + $name = $wgContLang->getLanguageName( $code ); + $langName = $name ? $name : $code; # OpenSearch description link $out->addLink( array( 'rel' => 'search', 'type' => 'application/opensearchdescription+xml', - 'href' => "$wgScriptPath/opensearch_desc.php" + 'href' => "$wgScriptPath/opensearch_desc.php", + 'title' => "$wgSitename ($langName)", )); $this->addMetadataLinks($out); @@ -179,7 +183,7 @@ class Skin extends Linker { $this->preloadExistence(); - wfProfileOut( $fname ); + wfProfileOut( __METHOD__ ); } /** @@ -188,16 +192,19 @@ class Skin extends Linker { function preloadExistence() { global $wgUser, $wgTitle; - if ( $wgTitle->isTalkPage() ) { - $otherTab = $wgTitle->getSubjectPage(); + // User/talk link + $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() ); + + // Other tab link + if ( $wgTitle->getNamespace() == NS_SPECIAL ) { + // nothing + } elseif ( $wgTitle->isTalkPage() ) { + $titles[] = $wgTitle->getSubjectPage(); } else { - $otherTab = $wgTitle->getTalkPage(); + $titles[] = $wgTitle->getTalkPage(); } - $lb = new LinkBatch( array( - $wgUser->getUserPage(), - $wgUser->getTalkPage(), - $otherTab - )); + + $lb = new LinkBatch( $titles ); $lb->execute(); } @@ -240,7 +247,7 @@ class Skin extends Linker { function outputPage( &$out ) { global $wgDebugComments; - wfProfileIn( 'Skin::outputPage' ); + wfProfileIn( __METHOD__ ); $this->initPage( $out ); $out->out( $out->headElement() ); @@ -267,63 +274,102 @@ class Skin extends Linker { $out->out( $out->reportTime() ); $out->out( "\n" ); + wfProfileOut( __METHOD__ ); } - static function makeGlobalVariablesScript( $data ) { - $r = ' - '; - + static function makeVariablesScript( $data ) { + global $wgJsMimeType; + + $r = "\n"; + return $r; } - function getHeadScripts() { - global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType; + /** + * Make a \n"; - if( $wgAllowUserJs && $wgUser->isLoggedIn() ) { + if($wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) { + $msgs = (object)array(); + foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching' ) as $msgName ) { + $msgs->{$msgName . 'Msg'} = wfMsg( $msgName ); + } + $vars['wgAjaxWatch'] = $msgs; + } + + return self::makeVariablesScript( $vars ); + } + + function getHeadScripts( $allowUserJs ) { + global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion; + + $r = self::makeGlobalVariablesScript( array( 'skinname' => $this->getSkinName() ) ); + + $r .= "\n"; + global $wgUseSiteJs; + if ($wgUseSiteJs) { + $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : ''; + $r .= "\n"; + } + if( $allowUserJs && $wgUser->isLoggedIn() ) { $userpage = $wgUser->getUserPage(); $userjs = htmlspecialchars( self::makeUrl( $userpage->getPrefixedText().'/'.$this->getSkinName().'.js', @@ -359,11 +405,12 @@ class Skin extends Linker { # get the user/site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way) function getUserStylesheet() { - global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage; + global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage, $wgStyleVersion; $sheet = $this->getStylesheet(); - $action = $wgRequest->getText('action'); - $s = "@import \"$wgStylePath/$sheet\";\n"; - if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n"; + $s = "@import \"$wgStylePath/common/shared.css?$wgStyleVersion\";\n"; + $s .= "@import \"$wgStylePath/common/oldshared.css?$wgStyleVersion\";\n"; + $s .= "@import \"$wgStylePath/$sheet?$wgStyleVersion\";\n"; + if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css?$wgStyleVersion\";\n"; $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage"; $s .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) . "\";\n" . @@ -374,9 +421,31 @@ class Skin extends Linker { } /** - * placeholder, returns generated js in monobook + * This returns MediaWiki:Common.js, and derived classes may add other JS. + * Despite its name, it does *not* return any custom user JS from user + * subpages. The returned script is sitewide and publicly cacheable and + * therefore must not include anything that varies according to user, + * interface language, etc. (although it may vary by skin). See + * makeGlobalVariablesScript for things that can vary per page view and are + * not cacheable. + * + * @return string Raw JavaScript to be returned */ - function getUserJs() { return; } + public function getUserJs() { + wfProfileIn( __METHOD__ ); + + global $wgStylePath; + $s = "/* generated javascript */\n"; + $s .= "var skin = '" . Xml::escapeJsString( $this->getSkinName() ) . "';\n"; + $s .= "var stylepath = '" . Xml::escapeJsString( $wgStylePath ) . "';"; + $s .= "\n\n/* MediaWiki:Common.js */\n"; + $commonJs = wfMsgForContent('common.js'); + if ( !wfEmptyMsg ( 'common.js', $commonJs ) ) { + $s .= $commonJs; + } + wfProfileOut( __METHOD__ ); + return $s; + } /** * Return html code that include User stylesheets @@ -415,7 +484,7 @@ class Skin extends Linker { function reallyDoGetUserStyles() { global $wgUser; $s = ''; - if (($undopt = $wgUser->getOption("underline")) != 2) { + if (($undopt = $wgUser->getOption("underline")) < 2) { $underline = $undopt ? 'underline' : 'none'; $s .= "a { text-decoration: $underline; }\n"; } @@ -426,17 +495,14 @@ class Skin extends Linker { a.new, #quickbar a.new, a.stub, #quickbar a.stub { color: inherit; - text-decoration: inherit; } a.new:after, #quickbar a.new:after { content: "?"; color: #CC2200; - text-decoration: $underline; } a.stub:after, #quickbar a.stub:after { content: "!"; color: #772233; - text-decoration: $underline; } END; } @@ -462,8 +528,7 @@ END; } else $a = array( 'bgcolor' => '#FFFFFF' ); if($wgOut->isArticle() && $wgUser->getOption('editondblclick') && - $wgTitle->userCanEdit() ) { - $t = wfMsg( 'editthispage' ); + $wgTitle->userCan( 'edit' ) ) { $s = $wgTitle->getFullURL( $this->editUrlOptions() ); $s = 'document.location = "' .wfEscapeJSString( $s ) .'";'; $a += array ('ondblclick' => $s); @@ -476,7 +541,8 @@ END; } $a['onload'] .= 'setupRightClickEdit()'; } - $a['class'] = 'ns-'.$wgTitle->getNamespace().' '.($wgContLang->isRTL() ? "rtl" : "ltr"); + $a['class'] = 'ns-'.$wgTitle->getNamespace().' '.($wgContLang->isRTL() ? "rtl" : "ltr"). + ' '.Sanitizer::escapeClass( 'page-'.$wgTitle->getPrefixedText() ); return $a; } @@ -575,9 +641,8 @@ END; $pop = ''; $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks ) . $pop; - $msg = wfMsgExt('categories', array('parsemag', 'escape'), count( $wgOut->mCategoryLinks )); - $s = $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Categories' ), - $msg, 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) ) + $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escape' ), count( $wgOut->mCategoryLinks ) ); + $s = $this->makeLinkObj( Title::newFromText( wfMsgForContent('pagecategorieslink') ), $msg ) . ': ' . $t; # optional 'dmoz-like' category browser. Will be shown under the list @@ -648,7 +713,9 @@ END; */ function bottomScripts() { global $wgJsMimeType; - return "\n\t\t\n"; + $bottomScriptText = "\n\t\t\n"; + wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) ); + return $bottomScriptText; } /** @return string Retrievied from HTML text */ @@ -669,7 +736,8 @@ END; function pageTitleLinks() { global $wgOut, $wgTitle, $wgUser, $wgRequest; - extract( $wgRequest->getValues( 'oldid', 'diff' ) ); + $oldid = $wgRequest->getVal( 'oldid' ); + $diff = $wgRequest->getVal( 'diff' ); $action = $wgRequest->getText( 'action' ); $s = $this->printableLink(); @@ -685,8 +753,8 @@ END; if ( $wgOut->isArticleRelated() ) { if ( $wgTitle->getNamespace() == NS_IMAGE ) { $name = $wgTitle->getDBkey(); - $image = new Image( $wgTitle ); - if( $image->exists() ) { + $image = wfFindFile( $wgTitle ); + if( $image ) { $link = htmlspecialchars( $image->getURL() ); $style = $this->getInternalLinkAttributes( $link, $name ); $s .= " | {$name}"; @@ -719,20 +787,20 @@ END; } function getUndeleteLink() { - global $wgUser, $wgTitle, $wgContLang, $action; + global $wgUser, $wgTitle, $wgContLang, $wgLang, $action; if( $wgUser->isAllowed( 'deletedhistory' ) && (($wgTitle->getArticleId() == 0) || ($action == "history")) && ($n = $wgTitle->isDeleted() ) ) { - if ( $wgUser->isAllowed( 'delete' ) ) { + if ( $wgUser->isAllowed( 'undelete' ) ) { $msg = 'thisisdeleted'; } else { $msg = 'viewdeleted'; } return wfMsg( $msg, - $this->makeKnownLink( - $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ), - wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) ); + $this->makeKnownLinkObj( + SpecialPage::getTitleFor( 'Undelete', $wgTitle->getPrefixedDBkey() ), + wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ) ) ); } return ''; } @@ -740,13 +808,6 @@ END; function printableLink() { global $wgOut, $wgFeedClasses, $wgRequest; - $baseurl = $_SERVER['REQUEST_URI']; - if( strpos( '?', $baseurl ) == false ) { - $baseurl .= '?'; - } else { - $baseurl .= '&'; - } - $baseurl = htmlspecialchars( $baseurl ); $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' ); $s = "" . wfMsg( 'printableversion' ) . ''; @@ -808,15 +869,22 @@ END; return $subpages; } + /** + * Returns true if the IP should be shown in the header + */ + function showIPinHeader() { + global $wgShowIPinHeader; + return $wgShowIPinHeader && session_id() != ''; + } + function nameAndLogin() { - global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader; + global $wgUser, $wgTitle, $wgLang, $wgContLang; - $li = $wgContLang->specialPage( 'Userlogin' ); $lo = $wgContLang->specialPage( 'Userlogout' ); $s = ''; if ( $wgUser->isAnon() ) { - if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) { + if( $this->showIPinHeader() ) { $n = wfGetIP(); $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), @@ -833,7 +901,7 @@ END; } else { $q = "returnto={$rt}"; } $s .= "\n
" . $this->makeKnownLinkObj( - Title::makeTitle( NS_SPECIAL, 'Userlogin' ), + SpecialPage::getTitleFor( 'Userlogin' ), wfMsg( 'login' ), $q ); } else { $n = $wgUser->getName(); @@ -845,7 +913,7 @@ END; $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(), $n ) . "{$tl}
" . - $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Userlogout' ), wfMsg( 'logout' ), + $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ), "returnto={$rt}" ) . ' | ' . $this->specialLink( 'preferences' ); } @@ -856,7 +924,7 @@ END; } function getSearchLink() { - $searchPage =& Title::makeTitle( NS_SPECIAL, 'Search' ); + $searchPage = SpecialPage::getTitleFor( 'Search' ); return $searchPage->getLocalURL(); } @@ -872,7 +940,7 @@ END; . $this->escapeSearchLink() . "\">\n" . '\n" - . ' ' + . ' ' . '\n"; return $s; @@ -891,7 +959,38 @@ END; } # Many people don't like this dropdown box #$s .= $sep . $this->specialPagesList(); + + $s .= $this->variantLinks(); + + $s .= $this->extensionTabLinks(); + return $s; + } + + /** + * Compatibility for extensions adding functionality through tabs. + * Eventually these old skins should be replaced with SkinTemplate-based + * versions, sigh... + * @return string + */ + function extensionTabLinks() { + $tabs = array(); + $s = ''; + wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) ); + foreach( $tabs as $tab ) { + $s .= ' | ' . Xml::element( 'a', + array( 'href' => $tab['href'] ), + $tab['text'] ); + } + return $s; + } + + /** + * Language/charset variant links for classic-style skins + * @return string + */ + function variantLinks() { + $s = ''; /* show links to different language variants */ global $wgDisableLangConversion, $wgContLang, $wgTitle; $variants = $wgContLang->getVariants(); @@ -900,10 +999,9 @@ END; $varname = $wgContLang->getVariantname( $code ); if( $varname == 'disable' ) continue; - $s .= ' | ' . $varname . ''; + $s .= ' | ' . htmlspecialchars( $varname ) . ''; } } - return $s; } @@ -954,7 +1052,8 @@ END; global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser; global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers; - extract( $wgRequest->getValues( 'oldid', 'diff' ) ); + $oldid = $wgRequest->getVal( 'oldid' ); + $diff = $wgRequest->getVal( 'diff' ); if ( ! $wgOut->isArticle() ) { return ''; } if ( isset( $oldid ) || isset( $diff ) ) { return ''; } if ( 0 == $wgArticle->getID() ) { return ''; } @@ -975,14 +1074,17 @@ END; } if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) { - $dbr =& wfGetDB( DB_SLAVE ); - extract( $dbr->tableNames( 'watchlist' ) ); + $dbr = wfGetDB( DB_SLAVE ); + $watchlist = $dbr->tableName( 'watchlist' ); $sql = "SELECT COUNT(*) AS n FROM $watchlist - WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) . + WHERE wl_title='" . $dbr->strencode($wgTitle->getDBkey()) . "' AND wl_namespace=" . $wgTitle->getNamespace() ; $res = $dbr->query( $sql, 'Skin::pageStats'); $x = $dbr->fetchObject( $res ); - $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n ); + + $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview', + array( 'parseinline' ), $wgLang->formatNum($x->n) + ); } return $s . ' ' . $this->getCopyright(); @@ -1044,7 +1146,7 @@ END; function getPoweredBy() { global $wgStylePath; $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" ); - $img = 'MediaWiki'; + $img = 'Powered by MediaWiki'; return $img; } @@ -1070,12 +1172,8 @@ END; else { $a = ''; } $mp = wfMsg( 'mainpage' ); - $titleObj = Title::newFromText( $mp ); - if ( is_object( $titleObj ) ) { - $url = $titleObj->escapeLocalURL(); - } else { - $url = ''; - } + $mptitle = Title::newMainPage(); + $url = ( is_object($mptitle) ? $mptitle->escapeLocalURL() : '' ); $logourl = $this->getLogo(); $s = ""; @@ -1087,8 +1185,6 @@ END; */ function specialPagesList() { global $wgUser, $wgContLang, $wgServer, $wgRedirectScript; - require_once('SpecialPage.php'); - $a = array(); $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() ); foreach ( $pages as $name => $page ) { $pages[$name] = $page->getDescription(); @@ -1115,9 +1211,7 @@ END; } function mainPageLink() { - $mp = wfMsgForContent( 'mainpage' ); - $mptxt = wfMsg( 'mainpage'); - $s = $this->makeKnownLink( $mp, $mptxt ); + $s = $this->makeKnownLinkObj( Title::newMainPage(), wfMsg( 'mainpage' ) ); return $s; } @@ -1127,29 +1221,30 @@ END; return $s; } - function privacyLink() { - $privacy = wfMsg( 'privacy' ); - if ($privacy == '-') { + private function footerLink ( $desc, $page ) { + // if the link description has been set to "-" in the default language, + if ( wfMsgForContent( $desc ) == '-') { + // then it is disabled, for all languages. return ''; } else { - return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy); + // Otherwise, we display the link for the user, described in their + // language (which may or may not be the same as the default language), + // but we make the link target be the one site-wide page. + return $this->makeKnownLink( wfMsgForContent( $page ), + wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) ) ); } } + function privacyLink() { + return $this->footerLink( 'privacy', 'privacypage' ); + } + function aboutLink() { - $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ), - wfMsg( 'aboutsite' ) ); - return $s; + return $this->footerLink( 'aboutsite', 'aboutpage' ); } function disclaimerLink() { - $disclaimers = wfMsg( 'disclaimers' ); - if ($disclaimers == '-') { - return ''; - } else { - return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ), - $disclaimers ); - } + return $this->footerLink( 'disclaimers', 'disclaimerpage' ); } function editThisPage() { @@ -1158,7 +1253,7 @@ END; if ( ! $wgOut->isArticleRelated() ) { $s = wfMsg( 'protectedpage' ); } else { - if ( $wgTitle->userCanEdit() ) { + if ( $wgTitle->userCan( 'edit' ) ) { $t = wfMsg( 'editthispage' ); } else { $t = wfMsg( 'viewsource' ); @@ -1221,16 +1316,19 @@ END; function watchThisPage() { global $wgOut, $wgTitle; + ++$this->mWatchLinkNum; if ( $wgOut->isArticleRelated() ) { if ( $wgTitle->userIsWatching() ) { $t = wfMsg( 'unwatchthispage' ); $q = 'action=unwatch'; + $id = "mw-unwatch-link".$this->mWatchLinkNum; } else { $t = wfMsg( 'watchthispage' ); $q = 'action=watch'; + $id = 'mw-watch-link'.$this->mWatchLinkNum; } - $s = $this->makeKnownLinkObj( $wgTitle, $t, $q ); + $s = $this->makeKnownLinkObj( $wgTitle, $t, $q, '', '', " id=\"$id\"" ); } else { $s = wfMsg( 'notanarticle' ); } @@ -1240,8 +1338,8 @@ END; function moveThisPage() { global $wgTitle; - if ( $wgTitle->userCanMove() ) { - return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Movepage' ), + if ( $wgTitle->userCan( 'move' ) ) { + return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ), wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() ); } else { // no message if page is protected - would be redundant @@ -1259,15 +1357,17 @@ END; function whatLinksHere() { global $wgTitle; - return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' ), - wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() ); + return $this->makeKnownLinkObj( + SpecialPage::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ), + wfMsg( 'whatlinkshere' ) ); } function userContribsLink() { global $wgTitle; - return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ), - wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() ); + return $this->makeKnownLinkObj( + SpecialPage::getTitleFor( 'Contributions', $wgTitle->getDBkey() ), + wfMsg( 'contributions' ) ); } function showEmailUser( $id ) { @@ -1284,8 +1384,9 @@ END; function emailUserLink() { global $wgTitle; - return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Emailuser' ), - wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() ); + return $this->makeKnownLinkObj( + SpecialPage::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ), + wfMsg( 'emailuser' ) ); } function watchPageLinksLink() { @@ -1294,9 +1395,9 @@ END; if ( ! $wgOut->isArticleRelated() ) { return '(' . wfMsg( 'notanarticle' ) . ')'; } else { - return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, - 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ), - 'target=' . $wgTitle->getPrefixedURL() ); + return $this->makeKnownLinkObj( + SpecialPage::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ), + wfMsg( 'recentchangeslinked' ) ); } } @@ -1344,29 +1445,6 @@ END; return $s; } - function dateLink() { - $t1 = Title::newFromText( gmdate( 'F j' ) ); - $t2 = Title::newFromText( gmdate( 'Y' ) ); - - $id = $t1->getArticleID(); - - if ( 0 == $id ) { - $s = $this->makeBrokenLink( $t1->getText() ); - } else { - $s = $this->makeKnownLink( $t1->getText() ); - } - $s .= ', '; - - $id = $t2->getArticleID(); - - if ( 0 == $id ) { - $s .= $this->makeBrokenLink( $t2->getText() ); - } else { - $s .= $this->makeKnownLink( $t2->getText() ); - } - return $s; - } - function talkLink() { global $wgTitle; @@ -1426,19 +1504,30 @@ END; # If it's present, the link points to this page, otherwise # it points to the talk page if( $wgTitle->isTalkPage() ) { - $title =& $wgTitle; + $title = $wgTitle; } elseif( $wgOut->showNewSectionLink() ) { - $title =& $wgTitle; + $title = $wgTitle; } else { - $title =& $wgTitle->getTalkPage(); + $title = $wgTitle->getTalkPage(); } return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit§ion=new' ); } /* these are used extensively in SkinTemplate, but also some other places */ + static function makeMainPageUrl( $urlaction = '' ) { + $title = Title::newMainPage(); + self::checkTitle( $title, '' ); + return $title->getLocalURL( $urlaction ); + } + static function makeSpecialUrl( $name, $urlaction = '' ) { - $title = Title::makeTitle( NS_SPECIAL, $name ); + $title = SpecialPage::getTitleFor( $name ); + return $title->getLocalURL( $urlaction ); + } + + static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) { + $title = SpecialPage::getSafeTitleFor( $name, $subpage ); return $title->getLocalURL( $urlaction ); } @@ -1494,7 +1583,7 @@ END; } # make sure we have some title to operate on - static function checkTitle( &$title, &$name ) { + static function checkTitle( &$title, $name ) { if( !is_object( $title ) ) { $title = Title::newFromText( $name ); if( !is_object( $title ) ) { @@ -1510,14 +1599,14 @@ END; * @private */ function buildSidebar() { - global $wgDBname, $parserMemc, $wgEnableSidebarCache; + global $parserMemc, $wgEnableSidebarCache; global $wgLang, $wgContLang; $fname = 'SkinTemplate::buildSidebar'; wfProfileIn( $fname ); - $key = "{$wgDBname}:sidebar"; + $key = wfMemcKey( 'sidebar' ); $cacheSidebar = $wgEnableSidebarCache && ($wgLang->getCode() == $wgContLang->getCode()); @@ -1547,7 +1636,19 @@ END; $text = $line[1]; if (wfEmptyMsg($line[0], $link)) $link = $line[0]; - $href = self::makeInternalOrExternalUrl( $link ); + + if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) { + $href = $link; + } else { + $title = Title::newFromText( $link ); + if ( $title ) { + $title = $title->fixSpecialName(); + $href = $title->getLocalURL(); + } else { + $href = 'INVALID-TITLE'; + } + } + $bar[$heading][] = array( 'text' => $text, 'href' => $href, @@ -1558,9 +1659,9 @@ END; } } if ($cacheSidebar) - $cachednotice = $parserMemc->set( $key, $bar, 86400 ); + $parserMemc->set( $key, $bar, 86400 ); wfProfileOut( $fname ); return $bar; } + } -?>