From 7496a8e6c5d8dca1cf6afe52a38402b2b75a219a Mon Sep 17 00:00:00 2001 From: Michael Dale Date: Tue, 22 Sep 2009 01:00:06 +0000 Subject: [PATCH] * (bug 20720) moved userjs and sitejs to after core scripts and before all extension code. * removed setupSkinUserJs (not called anywhere) same functionality in getHeadScripts * moved Skin::getHeadScripts() to outputPage::getHeadScripts() ** ( part of an effort to clean up scripts insertion to OutputPage ) ** Standard skin was the only skin that implemented the getHeadScripts method. Has been merged into a skin::OutputPage method. --- includes/OutputPage.php | 54 ++++++++++++++++++++++++++++++++++----- includes/Skin.php | 34 ------------------------ includes/SkinTemplate.php | 14 ---------- skins/MonoBook.php | 15 ----------- skins/Standard.php | 17 +++++------- 5 files changed, 54 insertions(+), 80 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 8f80ce4c01..95c49a9bdc 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -167,9 +167,12 @@ class OutputPage { /** * Add the core scripts that are included on every page, for later output into the header + * + * this includes the conditional sitejs */ function addCoreScripts2Top(){ global $wgEnableScriptLoader, $wgJSAutoloadLocalClasses, $wgScriptPath, $wgEnableJS2system; + global $wgUseSiteJs, $wgUser, $wgJsMimeType; // @todo We should deprecate wikibits in favor of mv_embed and jQuery if( $wgEnableJS2system ){ @@ -178,19 +181,33 @@ class OutputPage { $core_classes = array( 'wikibits' ); } + //make sure scripts are on top: + $postScripts = $this->mScripts; + $this->mScripts = ''; + if( $wgEnableScriptLoader ){ - //add core to top of mScripts - $this->mScripts = $this->getScriptLoaderJs( $core_classes ) . $this->mScripts; + //directly add script_loader call + //(separate from other scriptloader calls that may include extensions with conditional js) + $this->mScripts = $this->getScriptLoaderJs( $core_classes ); } else { $so = ''; - //make sure scripts are on top: - $postMscripts = $this->mScripts; - $this->mScripts = ''; foreach( $core_classes as $js_class ){ $this->addScriptClass( $js_class ); } - $this->mScripts .= $postMscripts; } + + $sk = $wgUser->getSkin(); + //add site js: + if( $wgUseSiteJs ) { + $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : ''; + $this->addScriptFile( Skin::makeUrl( '-', + "action=raw$jsCache&gen=js&useskin=" . + urlencode( $sk->getSkinName() ) + ) + ); + } + //now re-append any scripts that got added prior to the addCoreScripts2Top call + $this->mScripts = $this->mScripts . $postScripts; } /** @@ -1747,7 +1764,7 @@ class OutputPage { $ret .= implode( "\n", array( $this->getHeadLinks(), $this->buildCssLinks(), - $sk->getHeadScripts( $this ), + $this->getHeadScripts(), $this->getHeadItems(), )); if( $sk->usercss ){ @@ -1764,6 +1781,29 @@ class OutputPage { return $ret; } + /* + * gets the global variables and mScripts + * + * also adds userjs to the end if enabled: + */ + function getHeadScripts() { + global $wgUser; + $sk = $wgUser->getSkin(); + + $vars = Skin::makeGlobalVariablesScript( $sk->getSkinName() ); + + //add user js if enabled: + if( $this->isUserJsAllowed() && $wgUser->isLoggedIn() ) { + $userpage = $wgUser->getUserPage(); + $userjs = Skin::makeUrl( + $userpage->getPrefixedText() . '/' . $sk->getSkinName() . '.js', + 'action=raw&ctype=' . $wgJsMimeType ); + $this->addScriptFile( $userjs ); + } + + return $vars . "\n" . $this->mScripts; + } + protected function addDefaultMeta() { global $wgVersion, $wgHtml5; diff --git a/includes/Skin.php b/includes/Skin.php index 60fe1cae04..49da137513 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -453,40 +453,6 @@ class Skin extends Linker { return self::makeVariablesScript( $vars ); } - /** - * Return a random selection of the scripts we want in the header, - * according to no particular rhyme or reason. Various other scripts are - * returned from a haphazard assortment of other functions scattered over - * various files. This entire hackish system needs to be burned to the - * ground and rebuilt. - * - * @param $out OutputPage object, should be $wgOut - * - * @return string Raw HTML to output to - */ - function getHeadScripts( OutputPage $out ) { - global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion, $wgOut; - global $wgUseSiteJs; - - $vars = self::makeGlobalVariablesScript( $this->getSkinName() ); - - if( $wgUseSiteJs ) { - $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : ''; - $wgOut->addScriptFile( self::makeUrl( '-', - "action=raw$jsCache&gen=js&useskin=" . - urlencode( $this->getSkinName() ) - ) - ); - } - if( $out->isUserJsAllowed() && $wgUser->isLoggedIn() ) { - $userpage = $wgUser->getUserPage(); - $userjs = self::makeUrl( - $userpage->getPrefixedText() . '/' . $this->getSkinName() . '.js', - 'action=raw&ctype=' . $wgJsMimeType ); - $wgOut->addScriptFile( $userjs ); - } - return $vars . "\n" . $out->mScripts; - } /** * To make it harder for someone to slip a user a fake diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 2423c197bd..cbf9b14c39 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -99,20 +99,6 @@ class SkinTemplate extends Skin { $out->addStyle( 'common/commonPrint.css', 'print' ); } - /** - * Add specific JavaScript the base Skin class. - * FIXME: not called from anywhere - */ - function setupSkinUserJs( OutputPage $out ) { - global $wgUseSiteJs; - if( $wgUseSiteJs ) { - $jsCache = $this->loggedin ? '&smaxage=0' : ''; - $siteGenScriptFile = self::makeUrl( '-', - "action=raw$jsCache&gen=js&useskin=" . urlencode( $this->getSkinName() ) ); - $this->jsvarurl = $siteGenScriptFile; - } - } - /** * Create the template engine object; we feed it a bunch of data * and eventually it spits out some HTML. Should have interface diff --git a/skins/MonoBook.php b/skins/MonoBook.php index 5c3996e90c..b816e57612 100644 --- a/skins/MonoBook.php +++ b/skins/MonoBook.php @@ -51,21 +51,6 @@ class SkinMonoBook extends SkinTemplate { $out->addInlineStyle( $this->usercss ); } - - function setupSkinUserJs( OutputPage $out ) { - parent::setupSkinUserJs( $out ); - $out->addScriptFile( 'wikibits.js' ); - - // @todo We can move to parent once we update all the skins (to avoid including things twice) - if( isset( $this->jsvarurl ) && $this->jsvarurl ) - $out->addScriptFile( $this->jsvarurl ); - - if( isset( $this->userjs ) && $this->userjs ) - $out->addScriptFile( $this->userjs ); - - if( isset( $this->userjsprev ) && $this->userjsprev ) - $out->addInlineScript( $this->userjsprev ); - } } /** diff --git a/skins/Standard.php b/skins/Standard.php index 1dc2d48707..2a17b0ea82 100644 --- a/skins/Standard.php +++ b/skins/Standard.php @@ -14,22 +14,19 @@ if( !defined( 'MEDIAWIKI' ) ) * @ingroup Skins */ class SkinStandard extends Skin { - - /** - * + /* + * OutputPage */ - function getHeadScripts( OutputPage $out ) { - global $wgStylePath, $wgJsMimeType, $wgStyleVersion; - - $s = parent::getHeadScripts( $out ); - if ( 3 == $this->qbSetting() ) { # Floating left + function outputPage( OutputPage $out ) { + global $wgStylePath; + if ( 3 == $this->qbSetting() ) { # Floating left $out->addScriptFile ( "{$wgStylePath}/common/sticky.js" ); } - return $s; + parent::outputPage( $out ); } /** - * + * */ function setupSkinUserCss( OutputPage $out ){ if ( 3 == $this->qbSetting() ) { # Floating left -- 2.20.1