From 17a41f9277061f045e5c2081e41d668deb04f995 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Sun, 23 Aug 2015 15:56:59 -0700 Subject: [PATCH] registration: Allow custom prefixes for configuration settings Allow extensions which are using "$eg" or any other prefix to migrate. Extensions can override the default of "wg" by setting a magic "_prefix" key in the "config" object. Note that the migration helper script will not be able to automatically migrate custom-prefixed configuration settings. Bug: T97186 Change-Id: I79203cd5e3a2405b92ad01da869de3bd3d359d19 --- docs/extension.schema.json | 7 +++++++ includes/registration/ExtensionProcessor.php | 8 +++++++- .../includes/registration/ExtensionProcessorTest.php | 9 +++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/docs/extension.schema.json b/docs/extension.schema.json index 1d78eccfc9..63bf1b5025 100644 --- a/docs/extension.schema.json +++ b/docs/extension.schema.json @@ -639,6 +639,13 @@ "config": { "type": "object", "description": "Configuration options for this extension", + "properties": { + "_prefix": { + "type": "string", + "default": "wg", + "description": "Prefix to put in front of configuration settings when exporting them to $GLOBALS" + } + }, "patternProperties": { "^[a-zA-Z_\u007f-\u00ff][a-zA-Z0-9_\u007f-\u00ff]*$": { "type": ["object", "array", "string", "integer", "null", "boolean"], diff --git a/includes/registration/ExtensionProcessor.php b/includes/registration/ExtensionProcessor.php index dc35347bdb..ca84a513ef 100644 --- a/includes/registration/ExtensionProcessor.php +++ b/includes/registration/ExtensionProcessor.php @@ -305,9 +305,15 @@ class ExtensionProcessor implements Processor { */ protected function extractConfig( array $info ) { if ( isset( $info['config'] ) ) { + if ( isset( $info['config']['_prefix'] ) ) { + $prefix = $info['config']['_prefix']; + unset( $info['config']['_prefix'] ); + } else { + $prefix = 'wg'; + } foreach ( $info['config'] as $key => $val ) { if ( $key[0] !== '@' ) { - $this->globals["wg$key"] = $val; + $this->globals["$prefix$key"] = $val; } } } diff --git a/tests/phpunit/includes/registration/ExtensionProcessorTest.php b/tests/phpunit/includes/registration/ExtensionProcessorTest.php index 09641377da..1cb8a5d964 100644 --- a/tests/phpunit/includes/registration/ExtensionProcessorTest.php +++ b/tests/phpunit/includes/registration/ExtensionProcessorTest.php @@ -113,11 +113,20 @@ class ExtensionProcessorTest extends MediaWikiTestCase { '@IGNORED' => 'yes', ), ) + self::$default; + $info2 = array( + 'config' => array( + '_prefix' => 'eg', + 'Bar' => 'somevalue' + ), + ) + self::$default; $processor->extractInfo( $this->dir, $info, 1 ); + $processor->extractInfo( $this->dir, $info2, 1 ); $extracted = $processor->getExtractedInfo(); $this->assertEquals( 'somevalue', $extracted['globals']['wgBar'] ); $this->assertEquals( 10, $extracted['globals']['wgFoo'] ); $this->assertArrayNotHasKey( 'wg@IGNORED', $extracted['globals'] ); + // Custom prefix: + $this->assertEquals( 'somevalue', $extracted['globals']['egBar'] ); } public static function provideExtracttExtensionMessagesFiles() { -- 2.20.1