diff options
Diffstat (limited to 'includes/Skin.php')
-rw-r--r-- | includes/Skin.php | 104 |
1 files changed, 45 insertions, 59 deletions
diff --git a/includes/Skin.php b/includes/Skin.php index 0ca95f7e..f9e17057 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -22,6 +22,7 @@ class Skin extends Linker { 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 */ @@ -292,19 +293,21 @@ class Skin extends Linker { * The odd calling convention is for backwards compatibility */ static function makeGlobalVariablesScript( $data ) { - global $wgStylePath, $wgUser; + global $wgScript, $wgStylePath, $wgUser; global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang; global $wgTitle, $wgCanonicalNamespaceNames, $wgOut, $wgArticle; global $wgBreakFrames, $wgRequest; + global $wgUseAjax, $wgAjaxWatch; $ns = $wgTitle->getNamespace(); $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText(); - + $vars = array( 'skin' => $data['skinname'], 'stylepath' => $wgStylePath, 'wgArticlePath' => $wgArticlePath, 'wgScriptPath' => $wgScriptPath, + 'wgScript' => $wgScript, 'wgServer' => $wgServer, 'wgCanonicalNamespace' => $nsname, 'wgCanonicalSpecialPageName' => SpecialPage::resolveAlias( $wgTitle->getDBKey() ), @@ -312,6 +315,8 @@ class Skin extends Linker { 'wgPageName' => $wgTitle->getPrefixedDBKey(), 'wgTitle' => $wgTitle->getText(), 'wgAction' => $wgRequest->getText( 'action', 'view' ), + 'wgRestrictionEdit' => $wgTitle->getRestrictions( 'edit' ), + 'wgRestrictionMove' => $wgTitle->getRestrictions( 'move' ), 'wgArticleId' => $wgTitle->getArticleId(), 'wgIsArticle' => $wgOut->isArticle(), 'wgUserName' => $wgUser->isAnon() ? NULL : $wgUser->getName(), @@ -330,24 +335,33 @@ class Skin extends Linker { $vars['wgLivepreviewMessageError'] = wfMsg( 'livepreview-error' ); } + 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() { - global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType, $wgStyleVersion; + function getHeadScripts( $allowUserJs ) { + global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion; $r = self::makeGlobalVariablesScript( array( 'skinname' => $this->getSkinName() ) ); $r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>\n"; global $wgUseSiteJs; if ($wgUseSiteJs) { - if ($wgUser->isLoggedIn()) { - $r .= "<script type=\"$wgJsMimeType\" src=\"".htmlspecialchars(self::makeUrl('-','action=raw&smaxage=0&gen=js'))."\"><!-- site js --></script>\n"; - } else { - $r .= "<script type=\"$wgJsMimeType\" src=\"".htmlspecialchars(self::makeUrl('-','action=raw&gen=js'))."\"><!-- site js --></script>\n"; - } - } - if( $wgAllowUserJs && $wgUser->isLoggedIn() ) { + $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : ''; + $r .= "<script type=\"$wgJsMimeType\" src=\"". + htmlspecialchars(self::makeUrl('-', + "action=raw$jsCache&gen=js&useskin=" . + urlencode( $this->getSkinName() ) ) ) . + "\"><!-- site js --></script>\n"; + } + if( $allowUserJs && $wgUser->isLoggedIn() ) { $userpage = $wgUser->getUserPage(); $userjs = htmlspecialchars( self::makeUrl( $userpage->getPrefixedText().'/'.$this->getSkinName().'.js', @@ -385,7 +399,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"; @@ -398,36 +413,28 @@ 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() { + 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 ) ) { $s .= $commonJs; } - - global $wgUseAjax, $wgAjaxWatch; - if($wgUseAjax && $wgAjaxWatch) { - $s .= " - -/* AJAX (un)watch (see /skins/common/ajaxwatch.js) */ -var wgAjaxWatch = { - watchMsg: '". str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'watch', array() ) )."', - unwatchMsg: '". str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'unwatch', array() ) )."', - watchingMsg: '". str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'watching', array() ) )."', - unwatchingMsg: '". str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'unwatching', array() ) )."' -};"; - } - wfProfileOut( __METHOD__ ); return $s; } @@ -701,7 +708,9 @@ END; */ function bottomScripts() { global $wgJsMimeType; - return "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n"; + $bottomScriptText = "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n"; + wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) ); + return $bottomScriptText; } /** @return string Retrievied from HTML text */ @@ -739,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 .= " | <a href=\"{$link}\"{$style}>{$name}</a>"; @@ -1427,29 +1436,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; @@ -1668,5 +1654,5 @@ END; wfProfileOut( $fname ); return $bar; } -} -?> + +}
\ No newline at end of file |