Partial workaround for bug 6220: at least make files on shared repositories show...
[lhc/web/wiklou.git] / includes / OutputPage.php
index 9c2f992..19d0a7f 100644 (file)
@@ -2289,6 +2289,16 @@ class OutputPage {
                return $ret;
        }
 
+       /**
+        * Get a ResourceLoader object associated with this OutputPage
+        */
+       public function getResourceLoader() {
+               if ( is_null( $this->mResourceLoader ) ) {
+                       $this->mResourceLoader = new ResourceLoader();
+               }
+               return $this->mResourceLoader;
+       }               
+
        /**
         * TODO: Document
         * @param $skin Skin
@@ -2301,9 +2311,6 @@ class OutputPage {
                global $wgUser, $wgLang, $wgLoadScript, $wgResourceLoaderUseESI,
                        $wgResourceLoaderInlinePrivateModules;
                // Lazy-load ResourceLoader
-               if ( is_null( $this->mResourceLoader ) ) {
-                       $this->mResourceLoader = new ResourceLoader();
-               }
                // TODO: Should this be a static function of ResourceLoader instead?
                // TODO: Divide off modules starting with "user", and add the user parameter to them
                $query = array(
@@ -2335,8 +2342,9 @@ class OutputPage {
                
                // Create keyed-by-group list of module objects from modules list
                $groups = array();
+               $resourceLoader = $this->getResourceLoader();
                foreach ( (array) $modules as $name ) {
-                       $module = $this->mResourceLoader->getModule( $name );
+                       $module = $resourceLoader->getModule( $name );
                        $group = $module->getGroup();
                        if ( !isset( $groups[$group] ) ) {
                                $groups[$group] = array();
@@ -2352,26 +2360,27 @@ class OutputPage {
                        }
                        // Support inlining of private modules if configured as such
                        if ( $group === 'private' && $wgResourceLoaderInlinePrivateModules ) {
-                               $context = new ResourceLoaderContext( $this->mResourceLoader, new FauxRequest( $query ) );
+                               $context = new ResourceLoaderContext( $resourceLoader, new FauxRequest( $query ) );
                                if ( $only == 'styles' ) {
                                        $links .= Html::inlineStyle(
-                                               $this->mResourceLoader->makeModuleResponse( $context, $modules )
+                                               $resourceLoader->makeModuleResponse( $context, $modules )
                                        );
                                } else {
                                        $links .= Html::inlineScript(
                                                ResourceLoader::makeLoaderConditionalScript(
-                                                       $this->mResourceLoader->makeModuleResponse( $context, $modules )
+                                                       $resourceLoader->makeModuleResponse( $context, $modules )
                                                )
                                        );
                                }
                                continue;
                        }
-                       // Special handling for user and site groups; because users might change their stuff on-wiki like site or
-                       // user pages, or user preferences; we need to find the highest timestamp of these user-changable modules so
-                       // we can ensure cache misses on change
+                       // Special handling for user and site groups; because users might change their stuff
+                       // on-wiki like site or user pages, or user preferences; we need to find the highest
+                       // timestamp of these user-changable modules so we can ensure cache misses on change
                        if ( $group === 'user' || $group === 'site' ) {
-                               // Create a fake request based on the one we are about to make so modules return correct times
-                               $context = new ResourceLoaderContext( $this->mResourceLoader, new FauxRequest( $query ) );
+                               // Create a fake request based on the one we are about to make so modules return
+                               // correct times
+                               $context = new ResourceLoaderContext( $resourceLoader, new FauxRequest( $query ) );
                                // Get the maximum timestamp
                                $timestamp = 1;
                                foreach ( $modules as $module ) {
@@ -2417,26 +2426,32 @@ class OutputPage {
                // Startup - this will immediately load jquery and mediawiki modules
                $scripts = $this->makeResourceLoaderLink( $sk, 'startup', 'scripts', true );
 
-               // Configuration -- This could be merged together with the load and go, but makeGlobalVariablesScript returns a
-               // whole script tag -- grumble grumble...
+               // Configuration -- This could be merged together with the load and go, but
+               // makeGlobalVariablesScript returns a whole script tag -- grumble grumble...
                $scripts .= Skin::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n";
 
-               // Script and Messages "only"
-               
-               // Scripts
+               // Script and Messages "only" requests
                $scripts .= $this->makeResourceLoaderLink( $sk, $this->getModuleScripts(), 'scripts' );
-
-               // Messages
                $scripts .= $this->makeResourceLoaderLink( $sk, $this->getModuleMessages(), 'messages' );
 
-               // Modules - let the client calculate dependencies and batch requests as it likes
+               // Modules requests - let the client calculate dependencies and batch requests as it likes
                if ( $this->getModules() ) {
-                       $modules = FormatJson::encode( $this->getModules() );
                        $scripts .= Html::inlineScript(
-                               "if ( window.mediaWiki ) { mediaWiki.loader.load( {$modules} ); mediaWiki.loader.go(); }"
+                               ResourceLoader::makeLoaderConditionalScript(
+                                       Xml::encodeJsCall( 'mediaWiki.loader.load', array( $this->getModules() ) ) .
+                                       Xml::encodeJsCall( 'mediaWiki.loader.go', array() )
+                               )
                        ) . "\n";
                }
 
+               // Legacy Scripts
+               $scripts .= "\n" . $this->mScripts;
+
+               // Add site JS if enabled
+               if ( $wgUseSiteJs ) {
+                       $scripts .= $this->makeResourceLoaderLink( $sk, 'site', 'scripts' );
+               }
+
                // Add user JS if enabled - trying to load user.options as a bundle if possible
                $userOptionsAdded = false;
                if ( $this->isUserJsAllowed() && $wgUser->isLoggedIn() ) {
@@ -2445,20 +2460,16 @@ class OutputPage {
                                # XXX: additional security check/prompt?
                                $this->addInlineScript( $wgRequest->getText( 'wpTextbox1' ) );
                        } else {
-                               $scripts .= $this->makeResourceLoaderLink( $sk, array( 'user', 'user.options' ), 'scripts' );
+                               $scripts .= $this->makeResourceLoaderLink(
+                                       $sk, array( 'user', 'user.options' ), 'scripts'
+                               );
                                $userOptionsAdded = true;
                        }
                }
                if ( !$userOptionsAdded ) {
                        $scripts .= $this->makeResourceLoaderLink( $sk, 'user.options', 'scripts' );
                }
-               $scripts .= "\n" . $this->mScripts;
-
-               // Add site JS if enabled
-               if ( $wgUseSiteJs ) {
-                       $scripts .= $this->makeResourceLoaderLink( $sk, 'site', 'scripts' );
-               }
-
+               
                return $scripts;
        }
 
@@ -2577,8 +2588,15 @@ class OutputPage {
                        }
                }
 
-               $tags[] = $this->makeResourceLoaderLink( $sk, $this->getModuleStyles(), 'styles' );
-
+               // Split the styles into two groups, not user (0) and user (1)
+               $styles = array( array(), array() );
+               $resourceLoader = $this->getResourceLoader();
+               foreach ( $this->getModuleStyles() as $name ) {
+                       $styles[$resourceLoader->getModule( $name )->getGroup() === 'user' ? 1 : 0][] = $name;
+               }
+               // Add styles to tags, user modules last
+               $tags[] = $this->makeResourceLoaderLink( $sk, $styles[0], 'styles' );
+               $tags[] = $this->makeResourceLoaderLink( $sk, $styles[1], 'styles' );
                return implode( "\n", $tags );
        }