Merge "resourceloader: Support loading group=user modules with addModules()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 19 Apr 2018 19:01:10 +0000 (19:01 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 19 Apr 2018 19:01:10 +0000 (19:01 +0000)
includes/resourceloader/ResourceLoaderClientHtml.php
tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php

index 545fd3b..6c4a5d0 100644 (file)
@@ -148,15 +148,22 @@ class ResourceLoaderClientHtml {
                                continue;
                        }
 
-                       $context = $this->getContext( $module->getGroup(), ResourceLoaderModule::TYPE_COMBINED );
+                       $group = $module->getGroup();
+                       $context = $this->getContext( $group, ResourceLoaderModule::TYPE_COMBINED );
                        if ( $module->isKnownEmpty( $context ) ) {
                                // Avoid needless request or embed for empty module
                                $data['states'][$name] = 'ready';
                                continue;
                        }
 
-                       if ( $module->shouldEmbedModule( $this->context ) ) {
-                               // Embed via mw.loader.implement per T36907.
+                       if ( $group === 'user' || $module->shouldEmbedModule( $this->context ) ) {
+                               // Call makeLoad() to decide how to load these, instead of
+                               // loading via mw.loader.load().
+                               // - For group=user: We need to provide a pre-generated load.php
+                               //   url to the client that has the 'user' and 'version' parameters
+                               //   filled in. Without this, the client would wrongly use the static
+                               //   version hash, per T64602.
+                               // - For shouldEmbed=true:  Embed via mw.loader.implement, per T36907.
                                $data['embed']['general'][] = $name;
                                // Avoid duplicate request from mw.loader
                                $data['states'][$name] = 'loading';
index 07956f1..ea3d199 100644 (file)
@@ -45,6 +45,7 @@ class ResourceLoaderClientHtmlTest extends PHPUnit\Framework\TestCase {
                        'test.private' => [ 'group' => 'private' ],
                        'test.shouldembed.empty' => [ 'shouldEmbed' => true, 'isKnownEmpty' => true ],
                        'test.shouldembed' => [ 'shouldEmbed' => true ],
+                       'test.user' => [ 'group' => 'user' ],
 
                        'test.styles.pure' => [ 'type' => ResourceLoaderModule::LOAD_STYLES ],
                        'test.styles.mixed' => [],
@@ -115,6 +116,7 @@ class ResourceLoaderClientHtmlTest extends PHPUnit\Framework\TestCase {
                        'test.private',
                        'test.shouldembed.empty',
                        'test.shouldembed',
+                       'test.user',
                        'test.unregistered',
                ] );
                $client->setModuleStyles( [
@@ -138,6 +140,7 @@ class ResourceLoaderClientHtmlTest extends PHPUnit\Framework\TestCase {
                                'test.private' => 'loading',
                                'test.shouldembed.empty' => 'ready',
                                'test.shouldembed' => 'loading',
+                               'test.user' => 'loading',
                                'test.styles.pure' => 'ready',
                                'test.styles.user.empty' => 'ready',
                                'test.styles.private' => 'ready',
@@ -163,6 +166,7 @@ class ResourceLoaderClientHtmlTest extends PHPUnit\Framework\TestCase {
                                'general' => [
                                        'test.private',
                                        'test.shouldembed',
+                                       'test.user',
                                ],
                        ],
                ];
@@ -319,6 +323,12 @@ class ResourceLoaderClientHtmlTest extends PHPUnit\Framework\TestCase {
                                'only' => ResourceLoaderModule::TYPE_SCRIPTS,
                                'output' => '<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.load("/w/load.php?debug=false\u0026lang=nl\u0026modules=test.scripts.user\u0026only=scripts\u0026skin=fallback\u0026user=Example\u0026version=0a56zyi");});</script>',
                        ],
+                       [
+                               'context' => [],
+                               'modules' => [ 'test.user' ],
+                               'only' => ResourceLoaderModule::TYPE_COMBINED,
+                               'output' => '<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.load("/w/load.php?debug=false\u0026lang=nl\u0026modules=test.user\u0026skin=fallback\u0026user=Example\u0026version=0a56zyi");});</script>',
+                       ],
                        [
                                'context' => [ 'debug' => true ],
                                'modules' => [ 'test.styles.pure', 'test.styles.mixed' ],