Merge "resourceloader: Move expandModuleNames() to ResourceLoader.php"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 11 Apr 2019 22:31:25 +0000 (22:31 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 11 Apr 2019 22:31:25 +0000 (22:31 +0000)
RELEASE-NOTES-1.33
includes/resourceloader/ResourceLoader.php
includes/resourceloader/ResourceLoaderContext.php
resources/src/startup/mediawiki.js
tests/phpunit/includes/resourceloader/ResourceLoaderContextTest.php
tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
tests/qunit/data/load.mock.php

index 09fd35e..e28957d 100644 (file)
@@ -437,6 +437,8 @@ because of Phabricator reports.
 * Calling Maintenance::hasArg() as well as Maintenance::getArg() with no
   parameter has been deprecated. Please pass the argument number 0.
 * The MWNamespace class is deprecated.  Use MediaWikiServices::getNamespaceInfo.
+* ResourceLoaderContext::expandModuleNames has been deprecated.
+  Use ResourceLoader::expandModuleNames instead.
 
 === Other changes in 1.33 ===
 * (T201747) Html::openElement() warns if given an element name with a space
index 02e02bb..7fb2df2 100644 (file)
@@ -1567,7 +1567,7 @@ MESSAGE;
         * For example, `[ 'foo.bar', 'foo.baz', 'bar.baz', 'bar.quux' ]`
         * becomes `'foo.bar,baz|bar.baz,quux'`.
         *
-        * This process is reversed by ResourceLoaderContext::expandModuleNames().
+        * This process is reversed by ResourceLoader::expandModuleNames().
         * See also mw.loader#buildModulesString() which is a port of this, used
         * on the client-side.
         *
@@ -1591,6 +1591,44 @@ MESSAGE;
                return implode( '|', $arr );
        }
 
+       /**
+        * Expand a string of the form `jquery.foo,bar|jquery.ui.baz,quux` to
+        * an array of module names like `[ 'jquery.foo', 'jquery.bar',
+        * 'jquery.ui.baz', 'jquery.ui.quux' ]`.
+        *
+        * This process is reversed by ResourceLoader::makePackedModulesString().
+        *
+        * @since 1.33
+        * @param string $modules Packed module name list
+        * @return array Array of module names
+        */
+       public static function expandModuleNames( $modules ) {
+               $retval = [];
+               $exploded = explode( '|', $modules );
+               foreach ( $exploded as $group ) {
+                       if ( strpos( $group, ',' ) === false ) {
+                               // This is not a set of modules in foo.bar,baz notation
+                               // but a single module
+                               $retval[] = $group;
+                       } else {
+                               // This is a set of modules in foo.bar,baz notation
+                               $pos = strrpos( $group, '.' );
+                               if ( $pos === false ) {
+                                       // Prefixless modules, i.e. without dots
+                                       $retval = array_merge( $retval, explode( ',', $group ) );
+                               } else {
+                                       // We have a prefix and a bunch of suffixes
+                                       $prefix = substr( $group, 0, $pos ); // 'foo'
+                                       $suffixes = explode( ',', substr( $group, $pos + 1 ) ); // [ 'bar', 'baz' ]
+                                       foreach ( $suffixes as $suffix ) {
+                                               $retval[] = "$prefix.$suffix";
+                                       }
+                               }
+                       }
+               }
+               return $retval;
+       }
+
        /**
         * Determine whether debug mode was requested
         * Order of priority is 1) request param, 2) cookie, 3) $wg setting
index 372d12d..7afbfb2 100644 (file)
@@ -68,7 +68,7 @@ class ResourceLoaderContext implements MessageLocalizer {
 
                // List of modules
                $modules = $request->getRawVal( 'modules' );
-               $this->modules = $modules ? self::expandModuleNames( $modules ) : [];
+               $this->modules = $modules ? ResourceLoader::expandModuleNames( $modules ) : [];
 
                // Various parameters
                $this->user = $request->getRawVal( 'user' );
@@ -91,40 +91,16 @@ class ResourceLoaderContext implements MessageLocalizer {
        }
 
        /**
-        * Expand a string of the form `jquery.foo,bar|jquery.ui.baz,quux` to
-        * an array of module names like `[ 'jquery.foo', 'jquery.bar',
-        * 'jquery.ui.baz', 'jquery.ui.quux' ]`.
-        *
-        * This process is reversed by ResourceLoader::makePackedModulesString().
+        * Reverse the process done by ResourceLoader::makePackedModulesString().
         *
+        * @deprecated since 1.33 Use ResourceLoader::expandModuleNames instead.
         * @param string $modules Packed module name list
         * @return array Array of module names
+        * @codeCoverageIgnore
         */
        public static function expandModuleNames( $modules ) {
-               $retval = [];
-               $exploded = explode( '|', $modules );
-               foreach ( $exploded as $group ) {
-                       if ( strpos( $group, ',' ) === false ) {
-                               // This is not a set of modules in foo.bar,baz notation
-                               // but a single module
-                               $retval[] = $group;
-                       } else {
-                               // This is a set of modules in foo.bar,baz notation
-                               $pos = strrpos( $group, '.' );
-                               if ( $pos === false ) {
-                                       // Prefixless modules, i.e. without dots
-                                       $retval = array_merge( $retval, explode( ',', $group ) );
-                               } else {
-                                       // We have a prefix and a bunch of suffixes
-                                       $prefix = substr( $group, 0, $pos ); // 'foo'
-                                       $suffixes = explode( ',', substr( $group, $pos + 1 ) ); // [ 'bar', 'baz' ]
-                                       foreach ( $suffixes as $suffix ) {
-                                               $retval[] = "$prefix.$suffix";
-                                       }
-                               }
-                       }
-               }
-               return $retval;
+               wfDeprecated( __METHOD__, '1.33' );
+               return ResourceLoader::expandModuleNames( $modules );
        }
 
        /**
index 0a8dfb8..f961da2 100644 (file)
                         * to a query string of the form `foo.bar,baz|bar.baz,quux`.
                         *
                         * See `ResourceLoader::makePackedModulesString()` in PHP, of which this is a port.
-                        * On the server, unpacking is done by `ResourceLoaderContext::expandModuleNames()`.
+                        * On the server, unpacking is done by `ResourceLoader::expandModuleNames()`.
                         *
                         * Note: This is only half of the logic, the other half has to be in #batchRequest(),
                         * because its implementation needs to keep track of potential string size in order
index 1b7e0fe..5c53040 100644 (file)
@@ -2,10 +2,9 @@
 
 /**
  * See also:
- * - ResourceLoaderTest::testExpandModuleNames
  * - ResourceLoaderImageModuleTest::testContext
  *
- * @group Cache
+ * @group ResourceLoader
  * @covers ResourceLoaderContext
  */
 class ResourceLoaderContextTest extends PHPUnit\Framework\TestCase {
index 3f7925f..7239afc 100644 (file)
@@ -288,12 +288,12 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
 
        /**
         * @dataProvider providePackedModules
-        * @covers ResourceLoaderContext::expandModuleNames
+        * @covers ResourceLoader::expandModuleNames
         */
        public function testExpandModuleNames( $desc, $modules, $packed, $unpacked = null ) {
                $this->assertEquals(
                        $unpacked ?: $modules,
-                       ResourceLoaderContext::expandModuleNames( $packed ),
+                       ResourceLoader::expandModuleNames( $packed ),
                        $desc
                );
        }
index 2238fce..9f57190 100644 (file)
@@ -77,8 +77,8 @@ mw.loader.implement( 'testUrlOrder.b', function () {} );
 
 $response = '';
 
-// Does not support the full behaviour of ResourceLoaderContext::expandModuleNames(),
-// Only supports dotless module names joined by comma,
+// Does not support the full behaviour of the real load.php.
+// This only supports dotless module names joined by comma,
 // with the exception of the hardcoded cases for testUrl*.
 if ( isset( $_GET['modules'] ) ) {
        if ( $_GET['modules'] === 'testUrlInc,testUrlIncDump|testUrlInc.a,b' ) {