Merge "Only load gallery styling rules when galleries are on the page"
[lhc/web/wiklou.git] / includes / registration / ExtensionProcessor.php
index b0398eb..68e5a17 100644 (file)
@@ -46,6 +46,27 @@ class ExtensionProcessor implements Processor {
                'ValidSkinNames',
        );
 
+       /**
+        * Mapping of global settings to their specific merge strategies.
+        *
+        * @see ExtensionRegistry::exportExtractedData
+        * @see getExtractedInfo
+        * @var array
+        */
+       protected static $mergeStrategies = array(
+               'wgGroupPermissions' => 'array_plus_2d',
+               'wgRevokePermissions' => 'array_plus_2d',
+               'wgHooks' => 'array_merge_recursive',
+               // credits are handled in the ExtensionRegistry
+               //'wgExtensionCredits' => 'array_merge_recursive',
+               'wgExtraNamespaces' => 'array_plus',
+               'wgExtraGenderNamespaces' => 'array_plus',
+               'wgNamespacesWithSubpages' => 'array_plus',
+               'wgNamespaceContentModels' => 'array_plus',
+               'wgNamespaceProtection' => 'array_plus',
+               'wgCapitalLinkOverrides' => 'array_plus',
+       );
+
        /**
         * Keys that are part of the extension credits
         *
@@ -81,6 +102,7 @@ class ExtensionProcessor implements Processor {
                'config',
                'ParserTestFiles',
                'AutoloadClasses',
+               'manifest_version',
        );
 
        /**
@@ -125,9 +147,10 @@ class ExtensionProcessor implements Processor {
        /**
         * @param string $path
         * @param array $info
+        * @param int $version manifest_version for info
         * @return array
         */
-       public function extractInfo( $path, array $info ) {
+       public function extractInfo( $path, array $info, $version ) {
                $this->extractConfig( $info );
                $this->extractHooks( $info );
                $dir = dirname( $path );
@@ -154,6 +177,13 @@ class ExtensionProcessor implements Processor {
        }
 
        public function getExtractedInfo() {
+               // Make sure the merge strategies are set
+               foreach ( $this->globals as $key => $val ) {
+                       if ( isset( self::$mergeStrategies[$key] ) ) {
+                               $this->globals[$key][ExtensionRegistry::MERGE_STRATEGY] = self::$mergeStrategies[$key];
+                       }
+               }
+
                return array(
                        'globals' => $this->globals,
                        'defines' => $this->defines,
@@ -196,6 +226,12 @@ class ExtensionProcessor implements Processor {
                                if ( isset( $ns['defaultcontentmodel'] ) ) {
                                        $this->globals['wgNamespaceContentModels'][$id] = $ns['defaultcontentmodel'];
                                }
+                               if ( isset( $ns['protection'] ) ) {
+                                       $this->globals['wgNamespaceProtection'][$id] = $ns['protection'];
+                               }
+                               if ( isset( $ns['capitallinkoverride'] ) ) {
+                                       $this->globals['wgCapitalLinkOverrides'][$id] = $ns['capitallinkoverride'];
+                               }
                        }
                }
        }
@@ -288,10 +324,14 @@ class ExtensionProcessor implements Processor {
 
        /**
         * @param string $name
-        * @param mixed $value
+        * @param array $value
         * @param array &$array
+        * @throws InvalidArgumentException
         */
        protected function storeToArray( $name, $value, &$array ) {
+               if ( !is_array( $value ) ) {
+                       throw new InvalidArgumentException( "The value for '$name' should be an array" );
+               }
                if ( isset( $array[$name] ) ) {
                        $array[$name] = array_merge_recursive( $array[$name], $value );
                } else {