* (bug 20720) moved userjs and sitejs to after core scripts and before all extension...
authorMichael Dale <dale@users.mediawiki.org>
Tue, 22 Sep 2009 01:00:06 +0000 (01:00 +0000)
committerMichael Dale <dale@users.mediawiki.org>
Tue, 22 Sep 2009 01:00:06 +0000 (01:00 +0000)
* 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
includes/Skin.php
includes/SkinTemplate.php
skins/MonoBook.php
skins/Standard.php

index 8f80ce4..95c49a9 100644 (file)
@@ -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;
 
index 60fe1ca..49da137 100644 (file)
@@ -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 <head>
-        */
-       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
index 2423c19..cbf9b14 100644 (file)
@@ -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
index 5c3996e..b816e57 100644 (file)
@@ -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 );
-       }
 }
 
 /**
index 1dc2d48..2a17b0e 100644 (file)
@@ -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