From: Timo Tijhof Date: Thu, 11 Apr 2019 20:28:53 +0000 (+0100) Subject: resourceloader: Move expandModuleNames() to ResourceLoader.php X-Git-Tag: 1.34.0-rc.0~2042^2 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=f2bf73a4c491019f420ee6d6f1d8bd643659adbe;p=lhc%2Fweb%2Fwiklou.git resourceloader: Move expandModuleNames() to ResourceLoader.php This has always been an odd case, as indicicated by the cross-class comment references, and the fact that its test cases are already in ResourceLoaderTest.php, for convenience, as that's also where the creation of 'module name strings' is done and tested. Actually move it there instead of pretending it is there. Change-Id: Ied9569436cc78704a5c1b75eeebb73f8631350f6 --- diff --git a/RELEASE-NOTES-1.33 b/RELEASE-NOTES-1.33 index fd316c4e27..88217fd3b0 100644 --- a/RELEASE-NOTES-1.33 +++ b/RELEASE-NOTES-1.33 @@ -435,6 +435,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 diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index 02e02bbdf9..7fb2df2d3f 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -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 diff --git a/includes/resourceloader/ResourceLoaderContext.php b/includes/resourceloader/ResourceLoaderContext.php index 372d12dd85..7afbfb21b9 100644 --- a/includes/resourceloader/ResourceLoaderContext.php +++ b/includes/resourceloader/ResourceLoaderContext.php @@ -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 ); } /** diff --git a/resources/src/startup/mediawiki.js b/resources/src/startup/mediawiki.js index 0a8dfb8b92..f961da2652 100644 --- a/resources/src/startup/mediawiki.js +++ b/resources/src/startup/mediawiki.js @@ -1490,7 +1490,7 @@ * 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 diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderContextTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderContextTest.php index 1b7e0fe401..5c53040b0f 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderContextTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderContextTest.php @@ -2,10 +2,9 @@ /** * See also: - * - ResourceLoaderTest::testExpandModuleNames * - ResourceLoaderImageModuleTest::testContext * - * @group Cache + * @group ResourceLoader * @covers ResourceLoaderContext */ class ResourceLoaderContextTest extends PHPUnit\Framework\TestCase { diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php index 3f7925f914..7239afc8c1 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php @@ -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 ); } diff --git a/tests/qunit/data/load.mock.php b/tests/qunit/data/load.mock.php index 2238fcebf5..9f57190ea4 100644 --- a/tests/qunit/data/load.mock.php +++ b/tests/qunit/data/load.mock.php @@ -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' ) {