registration: Expose config array to ExtensionRegistry
[lhc/web/wiklou.git] / includes / registration / ExtensionProcessor.php
index 0d0a6e4..d0a9871 100644 (file)
@@ -162,6 +162,11 @@ class ExtensionProcessor implements Processor {
         */
        protected $credits = [];
 
+       /**
+        * @var array
+        */
+       protected $config = [];
+
        /**
         * Any thing else in the $info that hasn't
         * already been processed
@@ -186,12 +191,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 +215,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 );
                }
@@ -287,6 +295,7 @@ class ExtensionProcessor implements Processor {
 
                return [
                        'globals' => $this->globals,
+                       'config' => $this->config,
                        'defines' => $this->defines,
                        'callbacks' => $this->callbacks,
                        'credits' => $this->credits,
@@ -295,7 +304,7 @@ class ExtensionProcessor implements Processor {
        }
 
        public function getRequirements( array $info ) {
-               return isset( $info['requires'] ) ? $info['requires'] : [];
+               return $info['requires'] ?? [];
        }
 
        protected function extractHooks( array $info ) {
@@ -356,9 +365,7 @@ class ExtensionProcessor implements Processor {
        }
 
        protected function extractResourceLoaderModules( $dir, array $info ) {
-               $defaultPaths = isset( $info['ResourceFileModulePaths'] )
-                       ? $info['ResourceFileModulePaths']
-                       : false;
+               $defaultPaths = $info['ResourceFileModulePaths'] ?? false;
                if ( isset( $defaultPaths['localBasePath'] ) ) {
                        if ( $defaultPaths['localBasePath'] === '' ) {
                                // Avoid double slashes (e.g. /extensions/Example//path)
@@ -423,7 +430,7 @@ class ExtensionProcessor implements Processor {
        protected function extractCredits( $path, array $info ) {
                $credits = [
                        'path' => $path,
-                       'type' => isset( $info['type'] ) ? $info['type'] : 'other',
+                       'type' => $info['type'] ?? 'other',
                ];
                foreach ( self::$creditsAttributes as $attr ) {
                        if ( isset( $info[$attr] ) ) {
@@ -463,7 +470,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 +498,12 @@ 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'] );
+                               $data['providedby'] = $info['name'];
+                               if ( isset( $info['ConfigRegistry'][0] ) ) {
+                                       $data['configregistry'] = array_keys( $info['ConfigRegistry'] )[0];
+                               }
+                               $this->config[$key] = $data;
                        }
                }
        }
@@ -501,12 +513,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;
        }