registration: Only allow one extension to set a specific config setting
[lhc/web/wiklou.git] / includes / registration / ExtensionProcessor.php
index d14be3f..14d8222 100644 (file)
@@ -308,8 +308,15 @@ class ExtensionProcessor implements Processor {
        protected function extractNamespaces( array $info ) {
                if ( isset( $info['namespaces'] ) ) {
                        foreach ( $info['namespaces'] as $ns ) {
-                               $id = $ns['id'];
-                               $this->defines[$ns['constant']] = $id;
+                               if ( defined( $ns['constant'] ) ) {
+                                       // If the namespace constant is already defined, use it.
+                                       // This allows namespace IDs to be overwritten locally.
+                                       $id = constant( $ns['constant'] );
+                               } else {
+                                       $id = $ns['id'];
+                                       $this->defines[ $ns['constant'] ] = $id;
+                               }
+
                                if ( !( isset( $ns['conditional'] ) && $ns['conditional'] ) ) {
                                        // If it is not conditional, register it
                                        $this->attributes['ExtensionNamespaces'][$id] = $ns['name'];
@@ -371,7 +378,7 @@ class ExtensionProcessor implements Processor {
 
        protected function extractExtensionMessagesFiles( $dir, array $info ) {
                if ( isset( $info['ExtensionMessagesFiles'] ) ) {
-                       $this->globals["wgExtensionMessagesFiles"] += array_map( function( $file ) use ( $dir ) {
+                       $this->globals["wgExtensionMessagesFiles"] += array_map( function ( $file ) use ( $dir ) {
                                return "$dir/$file";
                        }, $info['ExtensionMessagesFiles'] );
                }
@@ -443,7 +450,7 @@ class ExtensionProcessor implements Processor {
                        }
                        foreach ( $info['config'] as $key => $val ) {
                                if ( $key[0] !== '@' ) {
-                                       $this->globals["$prefix$key"] = $val;
+                                       $this->addConfigGlobal( "$prefix$key", $val );
                                }
                        }
                }
@@ -471,11 +478,26 @@ class ExtensionProcessor implements Processor {
                                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 ) {