From 77a813f21f385a889052dab1cb88fb54fe0b14ac Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Thu, 2 Apr 2015 10:12:52 -0700 Subject: [PATCH] registration: Support ResourceModuleSkinStyles Structurally, it's set up exactly the same as ResourceModules, so we can re-use the same code. Bug: T91566 Change-Id: I7cd1330edc3e97b4658c81aac67071a90ac61fb6 --- docs/extension.schema.json | 4 ++ includes/registration/ExtensionProcessor.php | 18 ++++--- .../convertExtensionToRegistration.php | 1 + .../registration/ExtensionProcessorTest.php | 51 +++++++++++++++++++ 4 files changed, 66 insertions(+), 8 deletions(-) diff --git a/docs/extension.schema.json b/docs/extension.schema.json index dd35d0541c..1d891d2d25 100644 --- a/docs/extension.schema.json +++ b/docs/extension.schema.json @@ -417,6 +417,10 @@ } } }, + "ResourceModuleSkinStyles": { + "type": "object", + "description": "ResourceLoader modules for custom skin styles" + }, "ResourceLoaderSources": { "type": "object", "description": "ResourceLoader sources to register" diff --git a/includes/registration/ExtensionProcessor.php b/includes/registration/ExtensionProcessor.php index f85b8781f7..4945958924 100644 --- a/includes/registration/ExtensionProcessor.php +++ b/includes/registration/ExtensionProcessor.php @@ -193,15 +193,17 @@ class ExtensionProcessor implements Processor { $defaultPaths['localBasePath'] = "$dir/{$defaultPaths['localBasePath']}"; } - if ( isset( $info['ResourceModules'] ) ) { - foreach ( $info['ResourceModules'] as $name => $data ) { - if ( isset( $data['localBasePath'] ) ) { - $data['localBasePath'] = "$dir/{$data['localBasePath']}"; + foreach ( array( 'ResourceModules', 'ResourceModuleSkinStyles' ) as $setting ) { + if ( isset( $info[$setting] ) ) { + foreach ( $info[$setting] as $name => $data ) { + if ( isset( $data['localBasePath'] ) ) { + $data['localBasePath'] = "$dir/{$data['localBasePath']}"; + } + if ( $defaultPaths ) { + $data += $defaultPaths; + } + $this->globals["wg$setting"][$name] = $data; } - if ( $defaultPaths ) { - $data += $defaultPaths; - } - $this->globals['wgResourceModules'][$name] = $data; } } } diff --git a/maintenance/convertExtensionToRegistration.php b/maintenance/convertExtensionToRegistration.php index 76bc982459..a83529c048 100644 --- a/maintenance/convertExtensionToRegistration.php +++ b/maintenance/convertExtensionToRegistration.php @@ -10,6 +10,7 @@ class ConvertExtensionToRegistration extends Maintenance { 'AutoloadClasses' => 'removeAbsolutePath', 'ExtensionCredits' => 'handleCredits', 'ResourceModules' => 'handleResourceModules', + 'ResourceModuleSkinStyles' => 'handleResourceModules', 'Hooks' => 'handleHooks', 'ExtensionFunctions' => 'handleExtensionFunctions', ); diff --git a/tests/phpunit/includes/registration/ExtensionProcessorTest.php b/tests/phpunit/includes/registration/ExtensionProcessorTest.php index b4c225c802..b95316c20b 100644 --- a/tests/phpunit/includes/registration/ExtensionProcessorTest.php +++ b/tests/phpunit/includes/registration/ExtensionProcessorTest.php @@ -261,6 +261,57 @@ class ExtensionProcessorTest extends MediaWikiTestCase { ), ), ), + // ResourceModuleSkinStyles with file module paths + array( + // Input + array( + 'ResourceFileModulePaths' => array( + 'localBasePath' => '', + 'remoteSkinPath' => 'FooBar', + ), + 'ResourceModuleSkinStyles' => array( + 'foobar' => array( + 'test.foo' => 'foo.css', + ) + ), + ), + // Expected + array( + 'wgResourceModuleSkinStyles' => array( + 'foobar' => array( + 'test.foo' => 'foo.css', + 'localBasePath' => $dir, + 'remoteSkinPath' => 'FooBar', + ), + ), + ), + ), + // ResourceModuleSkinStyles with file module paths and an override + array( + // Input + array( + 'ResourceFileModulePaths' => array( + 'localBasePath' => '', + 'remoteSkinPath' => 'FooBar', + ), + 'ResourceModuleSkinStyles' => array( + 'foobar' => array( + 'test.foo' => 'foo.css', + 'remoteSkinPath' => 'BarFoo' + ), + ), + ), + // Expected + array( + 'wgResourceModuleSkinStyles' => array( + 'foobar' => array( + 'test.foo' => 'foo.css', + 'localBasePath' => $dir, + 'remoteSkinPath' => 'BarFoo', + ), + ), + ), + ), ); } -- 2.20.1