jenkins-bot has submitted this change and it was merged.

Change subject: registration: Allow custom prefixes for configuration settings
......................................................................


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
---
M docs/extension.schema.json
M includes/registration/ExtensionProcessor.php
M tests/phpunit/includes/registration/ExtensionProcessorTest.php
3 files changed, 23 insertions(+), 1 deletion(-)

Approvals:
  Paladox: Looks good to me, but someone else must approve
  Legoktm: Looks good to me, approved
  TTO: Looks good to me, approved
  Florianschmidtwelzow: Looks good to me, but someone else must approve
  MarkAHershberger: Verified; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/docs/extension.schema.json b/docs/extension.schema.json
index 1d78ecc..63bf1b5 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 dc35347..ca84a51 100644
--- a/includes/registration/ExtensionProcessor.php
+++ b/includes/registration/ExtensionProcessor.php
@@ -305,9 +305,15 @@
         */
        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 0964137..1cb8a5d 100644
--- a/tests/phpunit/includes/registration/ExtensionProcessorTest.php
+++ b/tests/phpunit/includes/registration/ExtensionProcessorTest.php
@@ -113,11 +113,20 @@
                                '@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() {

-- 
To view, visit https://gerrit.wikimedia.org/r/233331
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I79203cd5e3a2405b92ad01da869de3bd3d359d19
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: Chad <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Lewis Cawte <[email protected]>
Gerrit-Reviewer: MarkAHershberger <[email protected]>
Gerrit-Reviewer: Paladox <[email protected]>
Gerrit-Reviewer: TTO <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to