Merge "mediawiki.requestIdleCallback: Re-enable use of native requestIdleCallback"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderClientHtml.php
index 5729218..8c792ad 100644 (file)
@@ -56,7 +56,7 @@ class ResourceLoaderClientHtml {
 
        /**
         * @param ResourceLoaderContext $context
-        * @param aray $target [optional] Custom 'target' parameter for the startup module
+        * @param string|null $target [optional] Custom 'target' parameter for the startup module
         */
        public function __construct( ResourceLoaderContext $context, $target = null ) {
                $this->context = $context;
@@ -130,26 +130,15 @@ class ResourceLoaderClientHtml {
                        'states' => [
                                // moduleName => state
                        ],
-                       'general' => [
-                               // position => [ moduleName ]
-                               'top' => [],
-                               'bottom' => [],
-                       ],
+                       'general' => [],
                        'styles' => [
                                // moduleName
                        ],
-                       'scripts' => [
-                               // position => [ moduleName ]
-                               'top' => [],
-                               'bottom' => [],
-                       ],
+                       'scripts' => [],
                        // Embedding for private modules
                        'embed' => [
                                'styles' => [],
-                               'general' => [
-                                       'top' => [],
-                                       'bottom' => [],
-                               ],
+                               'general' => [],
                        ],
 
                ];
@@ -161,16 +150,15 @@ class ResourceLoaderClientHtml {
                        }
 
                        $group = $module->getGroup();
-                       $position = $module->getPosition();
 
                        if ( $group === 'private' ) {
                                // Embed via mw.loader.implement per T36907.
-                               $data['embed']['general'][$position][] = $name;
+                               $data['embed']['general'][] = $name;
                                // Avoid duplicate request from mw.loader
                                $data['states'][$name] = 'loading';
                        } else {
                                // Load via mw.loader.load()
-                               $data['general'][$position][] = $name;
+                               $data['general'][] = $name;
                        }
                }
 
@@ -216,14 +204,13 @@ class ResourceLoaderClientHtml {
                        }
 
                        $group = $module->getGroup();
-                       $position = $module->getPosition();
                        $context = $this->getContext( $group, ResourceLoaderModule::TYPE_SCRIPTS );
                        if ( $module->isKnownEmpty( $context ) ) {
                                // Avoid needless request for empty module
                                $data['states'][$name] = 'ready';
                        } else {
                                // Load from load.php?only=scripts via <script src></script>
-                               $data['scripts'][$position][] = $name;
+                               $data['scripts'][] = $name;
 
                                // Avoid duplicate request from mw.loader
                                $data['states'][$name] = 'loading';
@@ -282,24 +269,24 @@ class ResourceLoaderClientHtml {
                }
 
                // Inline RLQ: Embedded modules
-               if ( $data['embed']['general']['top'] ) {
+               if ( $data['embed']['general'] ) {
                        $chunks[] = $this->getLoad(
-                               $data['embed']['general']['top'],
+                               $data['embed']['general'],
                                ResourceLoaderModule::TYPE_COMBINED
                        );
                }
 
                // Inline RLQ: Load general modules
-               if ( $data['general']['top'] ) {
+               if ( $data['general'] ) {
                        $chunks[] = ResourceLoader::makeInlineScript(
-                               Xml::encodeJsCall( 'mw.loader.load', [ $data['general']['top'] ] )
+                               Xml::encodeJsCall( 'mw.loader.load', [ $data['general'] ] )
                        );
                }
 
                // Inline RLQ: Load only=scripts
-               if ( $data['scripts']['top'] ) {
+               if ( $data['scripts'] ) {
                        $chunks[] = $this->getLoad(
-                               $data['scripts']['top'],
+                               $data['scripts'],
                                ResourceLoaderModule::TYPE_SCRIPTS
                        );
                }
@@ -336,33 +323,7 @@ class ResourceLoaderClientHtml {
         * @return string|WrappedStringList HTML
         */
        public function getBodyHtml() {
-               $data = $this->getData();
-               $chunks = [];
-
-               // Inline RLQ: Embedded modules
-               if ( $data['embed']['general']['bottom'] ) {
-                       $chunks[] = $this->getLoad(
-                               $data['embed']['general']['bottom'],
-                               ResourceLoaderModule::TYPE_COMBINED
-                       );
-               }
-
-               // Inline RLQ: Load only=scripts
-               if ( $data['scripts']['bottom'] ) {
-                       $chunks[] = $this->getLoad(
-                               $data['scripts']['bottom'],
-                               ResourceLoaderModule::TYPE_SCRIPTS
-                       );
-               }
-
-               // Inline RLQ: Load general modules
-               if ( $data['general']['bottom'] ) {
-                       $chunks[] = ResourceLoader::makeInlineScript(
-                               Xml::encodeJsCall( 'mw.loader.load', [ $data['general']['bottom'] ] )
-                       );
-               }
-
-               return WrappedStringList::join( "\n", $chunks );
+               return '';
        }
 
        private function getContext( $group, $type ) {
@@ -404,7 +365,11 @@ class ResourceLoaderClientHtml {
                $rl = $mainContext->getResourceLoader();
                $chunks = [];
 
+               // Sort module names so requests are more uniform
+               sort( $modules );
+
                if ( $mainContext->getDebug() && count( $modules ) > 1 ) {
+
                        $chunks = [];
                        // Recursively call us for every item
                        foreach ( $modules as $name ) {
@@ -413,8 +378,6 @@ class ResourceLoaderClientHtml {
                        return new WrappedStringList( "\n", $chunks );
                }
 
-               // Sort module names so requests are more uniform
-               sort( $modules );
                // Create keyed-by-source and then keyed-by-group list of module objects from modules list
                $sortedModules = [];
                foreach ( $modules as $name ) {
@@ -454,7 +417,7 @@ class ResourceLoaderClientHtml {
                                // Special handling for the user group; because users might change their stuff
                                // on-wiki like user pages, or user preferences; we need to find the highest
                                // timestamp of these user-changeable modules so we can ensure cache misses on change
-                               // This should NOT be done for the site group (bug 27564) because anons get that too
+                               // This should NOT be done for the site group (T29564) because anons get that too
                                // and we shouldn't be putting timestamps in CDN-cached HTML
                                if ( $group === 'user' ) {
                                        // Must setModules() before makeVersionQuery()