registration: Improve duplicate config setting exception
[lhc/web/wiklou.git] / includes / registration / ExtensionProcessor.php
index fe617c5..14d4a17 100644 (file)
@@ -186,24 +186,39 @@ 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 );
                $this->extractNamespaces( $info );
                $this->extractResourceLoaderModules( $dir, $info );
-               $this->extractServiceWiringFiles( $dir, $info );
-               $this->extractParserTestFiles( $dir, $info );
+               if ( isset( $info['ServiceWiringFiles'] ) ) {
+                       $this->extractPathBasedGlobal(
+                               'wgServiceWiringFiles',
+                               $dir,
+                               $info['ServiceWiringFiles']
+                       );
+               }
+               if ( isset( $info['ParserTestFiles'] ) ) {
+                       $this->extractPathBasedGlobal(
+                               'wgParserTestFiles',
+                               $dir,
+                               $info['ParserTestFiles']
+                       );
+               }
                $name = $this->extractCredits( $path, $info );
                if ( isset( $info['callback'] ) ) {
                        $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 );
                }
@@ -451,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'] );
                                }
                        }
                }
@@ -479,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'] );
                        }
                }
        }
@@ -489,29 +504,20 @@ 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;
        }
 
-       protected function extractServiceWiringFiles( $dir, array $info ) {
-               if ( isset( $info['ServiceWiringFiles'] ) ) {
-                       foreach ( $info['ServiceWiringFiles'] as $path ) {
-                               $this->globals['wgServiceWiringFiles'][] = "$dir/$path";
-                       }
-               }
-       }
-
-       protected function extractParserTestFiles( $dir, array $info ) {
-               if ( isset( $info['ParserTestFiles'] ) ) {
-                       foreach ( $info['ParserTestFiles'] as $path ) {
-                               $this->globals['wgParserTestFiles'][] = "$dir/$path";
-                       }
+       protected function extractPathBasedGlobal( $global, $dir, $paths ) {
+               foreach ( $paths as $path ) {
+                       $this->globals[$global][] = "$dir/$path";
                }
        }