Reception123 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/373134 )

Change subject: registration: Only allow one extension to set a specific config 
setting
......................................................................

registration: Only allow one extension to set a specific config setting

ExtensionProcessor would previously just blindly overwrite duplicate
config settings, which ends up depending upon load order.

It's relatively hard to debug since it is silently overwritten. This now
throws exceptions in case of duplicate config settings.

This will also have some side-effects of catching people putting things
like "ResourceModules" in their "config" section when it should be a
top-level item.

Bug: T152929
Change-Id: Iaef32efab397e82ff70ddca8ac79c545c5b7d2bb

Causing errors with the WikiForum extension and ConfirmEdit when using 1.29. 
Please backport

Change-Id: I0f437f2b26be0e24c660b10c325806eea1476461
---
M includes/registration/ExtensionProcessor.php
M tests/phpunit/includes/registration/ExtensionProcessorTest.php
2 files changed, 59 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/34/373134/1

diff --git a/includes/registration/ExtensionProcessor.php 
b/includes/registration/ExtensionProcessor.php
index d14be3f..312e680 100644
--- a/includes/registration/ExtensionProcessor.php
+++ b/includes/registration/ExtensionProcessor.php
@@ -443,7 +443,7 @@
                        }
                        foreach ( $info['config'] as $key => $val ) {
                                if ( $key[0] !== '@' ) {
-                                       $this->globals["$prefix$key"] = $val;
+                                       $this->addConfigGlobal( "$prefix$key", 
$val );
                                }
                        }
                }
@@ -471,11 +471,26 @@
                                if ( isset( $data['path'] ) && $data['path'] ) {
                                        $value = "$dir/$value";
                                }
-                               $this->globals["$prefix$key"] = $value;
+                               $this->addConfigGlobal( "$prefix$key", $value );
                        }
                }
        }
 
+       /**
+        * Helper function to set a value to a specific global, if it isn't set 
already.
+        *
+        * @param string $key The config key with the prefix and anything
+        * @param mixed $value The value of the config
+        */
+       private function addConfigGlobal( $key, $value ) {
+               if ( array_key_exists( $key, $this->globals ) ) {
+                       throw new RuntimeException(
+                               "The configuration setting '$key' was already 
set by another extension,"
+                               . " and cannot be set again." );
+               }
+               $this->globals[$key] = $value;
+       }
+
        protected function extractServiceWiringFiles( $dir, array $info ) {
                if ( isset( $info['ServiceWiringFiles'] ) ) {
                        foreach ( $info['ServiceWiringFiles'] as $path ) {
diff --git a/tests/phpunit/includes/registration/ExtensionProcessorTest.php 
b/tests/phpunit/includes/registration/ExtensionProcessorTest.php
index ebe0bde..503f698 100644
--- a/tests/phpunit/includes/registration/ExtensionProcessorTest.php
+++ b/tests/phpunit/includes/registration/ExtensionProcessorTest.php
@@ -168,6 +168,48 @@
                $this->assertEquals( 'somevalue', 
$extracted['globals']['egBar'] );
        }
 
+       /**
+        * @covers ExtensionProcessor::addConfigGlobal()
+        * @expectedException RuntimeException
+        */
+       public function testDuplicateConfigKey1() {
+               $processor = new ExtensionProcessor;
+               $info = [
+                       'config' => [
+                               'Bar' => '',
+                       ]
+               ] + self::$default;
+               $info2 = [
+                       'config' => [
+                               'Bar' => 'g',
+                       ],
+                       'name' => 'FooBar2',
+               ];
+               $processor->extractInfo( $this->dir, $info, 1 );
+               $processor->extractInfo( $this->dir, $info2, 1 );
+       }
+
+       /**
+        * @covers ExtensionProcessor::addConfigGlobal()
+        * @expectedException RuntimeException
+        */
+       public function testDuplicateConfigKey2() {
+               $processor = new ExtensionProcessor;
+               $info = [
+                       'config' => [
+                               'Bar' => [ 'value' => 'somevalue' ],
+                       ]
+               ] + self::$default;
+               $info2 = [
+                       'config' => [
+                               'Bar' => [ 'value' => 'somevalue' ],
+                       ],
+                       'name' => 'FooBar2',
+               ];
+               $processor->extractInfo( $this->dir, $info, 2 );
+               $processor->extractInfo( $this->dir, $info2, 2 );
+       }
+
        public static function provideExtractExtensionMessagesFiles() {
                $dir = __DIR__ . '/FooBar/';
                return [

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0f437f2b26be0e24c660b10c325806eea1476461
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: REL1_29
Gerrit-Owner: Reception123 <utilizator.receptie...@gmail.com>
Gerrit-Reviewer: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to