registration: Allow custom prefixes for configuration settings
authorKunal Mehta <legoktm@gmail.com>
Sun, 23 Aug 2015 22:56:59 +0000 (15:56 -0700)
committerTTO <at.light@live.com.au>
Thu, 3 Sep 2015 12:44:46 +0000 (12:44 +0000)
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
includes/registration/ExtensionProcessor.php
tests/phpunit/includes/registration/ExtensionProcessorTest.php

index 1d78ecc..63bf1b5 100644 (file)
                "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"],
index dc35347..ca84a51 100644 (file)
@@ -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;
                                }
                        }
                }
index 0964137..1cb8a5d 100644 (file)
@@ -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() {