X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSkin.php;h=1001572d53a00d6d93952a887cfd7ae52aa1548b;hb=0495f90ebb83c0295f67b9da410ddf3b0534ca38;hp=45e8f2803d2d7a4a7b5b02d266a11d6cab3eb643;hpb=0e2426cc655578e4d9a4f3c68b113a8a58da62fe;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Skin.php b/includes/Skin.php index 45e8f2803d..1001572d53 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -2,18 +2,15 @@ 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 { /**#@+ @@ -23,17 +20,20 @@ class Skin extends Linker { 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 ) { @@ -143,35 +143,37 @@ class Skin extends Linker { } /** @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, $wgSitename, $wgLanguageCode, $wgLanguageNames; + global $wgFavicon, $wgScriptPath, $wgSitename, $wgContLang; - $fname = 'Skin::initPage'; - wfProfileIn( $fname ); + wfProfileIn( __METHOD__ ); if( false !== $wgFavicon ) { $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) ); } + $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", - 'title' => "$wgSitename ({$wgLanguageNames[$wgLanguageCode]})", + 'title' => "$wgSitename ($langName)", )); $this->addMetadataLinks($out); @@ -180,7 +182,7 @@ class Skin extends Linker { $this->preloadExistence(); - wfProfileOut( $fname ); + wfProfileOut( __METHOD__ ); } /** @@ -189,16 +191,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(); } @@ -241,7 +246,7 @@ class Skin extends Linker { function outputPage( &$out ) { global $wgDebugComments; - wfProfileIn( 'Skin::outputPage' ); + wfProfileIn( __METHOD__ ); $this->initPage( $out ); $out->out( $out->headElement() ); @@ -268,75 +273,98 @@ 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, $wgStyleVersion; + /** + * Make a \n"; global $wgUseSiteJs; if ($wgUseSiteJs) { - if ($wgUser->isLoggedIn()) { - $r .= "\n"; - } else { - $r .= "\n"; - } - } - if( $wgAllowUserJs && $wgUser->isLoggedIn() ) { + $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : ''; + $r .= "\n"; + } + if( $allowUserJs && $wgUser->isLoggedIn() ) { $userpage = $wgUser->getUserPage(); $userjs = htmlspecialchars( self::makeUrl( $userpage->getPrefixedText().'/'.$this->getSkinName().'.js', @@ -374,7 +402,8 @@ class Skin extends Linker { function getUserStylesheet() { global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage, $wgStyleVersion; $sheet = $this->getStylesheet(); - $s = "@import \"$wgStylePath/common/common.css?$wgStyleVersion\";\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"; @@ -387,27 +416,31 @@ class Skin extends Linker { } /** - * This returns MediaWiki:Common.js. For some bizarre reason, it does - * *not* return any custom user JS from user subpages. Huh? + * 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 + * @return string Raw JavaScript to be returned */ - function getUserJs() { - $fname = 'Skin::getUserJs'; - wfProfileIn( $fname ); + public function getUserJs() { + wfProfileIn( __METHOD__ ); global $wgStylePath; $s = "/* generated javascript */\n"; - $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';"; + $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 ) ) { + $commonJs = wfMsgForContent('common.js'); + if ( !wfEmptyMsg ( 'common.js', $commonJs ) ) { $s .= $commonJs; } - - wfProfileOut( $fname ); + wfProfileOut( __METHOD__ ); return $s; - } + } /** * Return html code that include User stylesheets @@ -446,7 +479,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"; } @@ -457,17 +490,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; } @@ -493,7 +523,7 @@ END; } else $a = array( 'bgcolor' => '#FFFFFF' ); if($wgOut->isArticle() && $wgUser->getOption('editondblclick') && - $wgTitle->userCanEdit() ) { + $wgTitle->userCan( 'edit' ) ) { $s = $wgTitle->getFullURL( $this->editUrlOptions() ); $s = 'document.location = "' .wfEscapeJSString( $s ) .'";'; $a += array ('ondblclick' => $s); @@ -507,7 +537,7 @@ END; $a['onload'] .= 'setupRightClickEdit()'; } $a['class'] = 'ns-'.$wgTitle->getNamespace().' '.($wgContLang->isRTL() ? "rtl" : "ltr"). - ' '.Sanitizer::escapeId( 'page-'.$wgTitle->getPrefixedText() ); + ' '.Sanitizer::escapeClass( 'page-'.$wgTitle->getPrefixedText() ); return $a; } @@ -678,7 +708,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 */ @@ -716,8 +748,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}"; @@ -750,7 +782,7 @@ 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() ) ) @@ -761,9 +793,9 @@ END; $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 ''; } @@ -771,13 +803,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' ) . ''; @@ -839,14 +864,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; $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(), @@ -1036,14 +1069,17 @@ END; } if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) { - $dbr =& wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_SLAVE ); $watchlist = $dbr->tableName( 'watchlist' ); $sql = "SELECT COUNT(*) AS n FROM $watchlist 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(); @@ -1105,7 +1141,7 @@ END; function getPoweredBy() { global $wgStylePath; $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" ); - $img = 'MediaWiki'; + $img = 'Powered by MediaWiki'; return $img; } @@ -1180,29 +1216,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() { @@ -1211,7 +1248,7 @@ END; if ( ! $wgOut->isArticleRelated() ) { $s = wfMsg( 'protectedpage' ); } else { - if ( $wgTitle->userCanEdit() ) { + if ( $wgTitle->userCan( 'edit' ) ) { $t = wfMsg( 'editthispage' ); } else { $t = wfMsg( 'viewsource' ); @@ -1274,16 +1311,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' ); } @@ -1293,7 +1333,7 @@ END; function moveThisPage() { global $wgTitle; - if ( $wgTitle->userCanMove() ) { + if ( $wgTitle->userCan( 'move' ) ) { return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ), wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() ); } else { @@ -1400,29 +1440,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; @@ -1482,11 +1499,11 @@ 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' ); @@ -1495,7 +1512,7 @@ END; /* these are used extensively in SkinTemplate, but also some other places */ static function makeMainPageUrl( $urlaction = '' ) { $title = Title::newMainPage(); - self::checkTitle( $title, $name ); + self::checkTitle( $title, '' ); return $title->getLocalURL( $urlaction ); } @@ -1504,6 +1521,11 @@ END; return $title->getLocalURL( $urlaction ); } + static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) { + $title = SpecialPage::getSafeTitleFor( $name, $subpage ); + return $title->getLocalURL( $urlaction ); + } + static function makeI18nUrl( $name, $urlaction = '' ) { $title = Title::newFromText( wfMsgForContent( $name ) ); self::checkTitle( $title, $name ); @@ -1556,7 +1578,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 ) ) { @@ -1636,5 +1658,5 @@ END; wfProfileOut( $fname ); return $bar; } + } -?>