registration: Improve duplicate config setting exception
authorKunal Mehta <legoktm@member.fsf.org>
Tue, 15 May 2018 17:26:43 +0000 (10:26 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Tue, 15 May 2018 17:32:22 +0000 (10:32 -0700)
We don't keep track of what set a specific global, so at least mention
the name of the extension that is setting a duplicate for easier
debugging.

Also, fix the case where if the first extension to be loaded was setting
a core setting, it would not throw an exception since config was being
processed before the rest of extension.json. Now we process config after
all core settings, going only before attributes.

Bug: T194319
Change-Id: I4fd96e7d167cf0652ee3e8e66167c86f2b91b992

includes/registration/ExtensionProcessor.php

index 0d0a6e4..14d4a17 100644 (file)
@@ -186,12 +186,6 @@ class ExtensionProcessor implements Processor {
         */
        public function extractInfo( $path, array $info, $version ) {
                $dir = dirname( $path );
-               if ( $version === 2 ) {
-                       $this->extractConfig2( $info, $dir );
-               } else {
-                       // $version === 1
-                       $this->extractConfig1( $info );
-               }
                $this->extractHooks( $info );
                $this->extractExtensionMessagesFiles( $dir, $info );
                $this->extractMessagesDirs( $dir, $info );
@@ -216,6 +210,15 @@ class ExtensionProcessor implements Processor {
                        $this->callbacks[$name] = $info['callback'];
                }
 
+               // config should be after all core globals are extracted,
+               // so duplicate setting detection will work fully
+               if ( $version === 2 ) {
+                       $this->extractConfig2( $info, $dir );
+               } else {
+                       // $version === 1
+                       $this->extractConfig1( $info );
+               }
+
                if ( $version === 2 ) {
                        $this->extractAttributes( $path, $info );
                }
@@ -463,7 +466,7 @@ class ExtensionProcessor implements Processor {
                        }
                        foreach ( $info['config'] as $key => $val ) {
                                if ( $key[0] !== '@' ) {
-                                       $this->addConfigGlobal( "$prefix$key", $val );
+                                       $this->addConfigGlobal( "$prefix$key", $val, $info['name'] );
                                }
                        }
                }
@@ -491,7 +494,7 @@ class ExtensionProcessor implements Processor {
                                if ( isset( $data['path'] ) && $data['path'] ) {
                                        $value = "$dir/$value";
                                }
-                               $this->addConfigGlobal( "$prefix$key", $value );
+                               $this->addConfigGlobal( "$prefix$key", $value, $info['name'] );
                        }
                }
        }
@@ -501,12 +504,13 @@ class ExtensionProcessor implements Processor {
         *
         * @param string $key The config key with the prefix and anything
         * @param mixed $value The value of the config
+        * @param string $extName Name of the extension
         */
-       private function addConfigGlobal( $key, $value ) {
+       private function addConfigGlobal( $key, $value, $extName ) {
                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." );
+                               "The configuration setting '$key' was already set by MediaWiki core or"
+                               . " another extension, and cannot be set again by $extName." );
                }
                $this->globals[$key] = $value;
        }