Merge "Decolonize 'viewsourcetext' and 'viewyourtext' messages"
[lhc/web/wiklou.git] / includes / registration / ExtensionRegistry.php
index ac39699..858f3bf 100644 (file)
  */
 class ExtensionRegistry {
 
+       /**
+        * Version of the highest supported manifest version
+        */
+       const MANIFEST_VERSION = 1;
+
+       /**
+        * Version of the oldest supported manifest version
+        */
+       const OLDEST_MANIFEST_VERSION = 1;
+
        /**
         * @var BagOStuff
         */
@@ -108,6 +118,24 @@ class ExtensionRegistry {
                $this->queued = array();
        }
 
+       /**
+        * Get the current load queue. Not intended to be used
+        * outside of the installer.
+        *
+        * @return array
+        */
+       public function getQueue() {
+               return $this->queued;
+       }
+
+       /**
+        * Clear the current load queue. Not intended to be used
+        * outside of the installer.
+        */
+       public function clearQueue() {
+               $this->queued = array();
+       }
+
        /**
         * Process a queue of extensions and return their extracted data
         *
@@ -116,7 +144,6 @@ class ExtensionRegistry {
         * @throws Exception
         */
        public function readFromQueue( array $queue ) {
-               $data = array( 'globals' => array( 'wgAutoloadClasses' => array() ) );
                $autoloadClasses = array();
                $processor = new ExtensionProcessor();
                foreach ( $queue as $path => $mtime ) {
@@ -128,11 +155,19 @@ class ExtensionRegistry {
                        if ( !is_array( $info ) ) {
                                throw new Exception( "$path is not a valid JSON file." );
                        }
+                       if ( !isset( $info['manifest_version'] ) ) {
+                               // For backwards-compatability, assume a version of 1
+                               $info['manifest_version'] = 1;
+                       }
+                       $version = $info['manifest_version'];
+                       if ( $version < self::OLDEST_MANIFEST_VERSION || $version > self::MANIFEST_VERSION ) {
+                               throw new Exception( "$path: unsupported manifest_version: {$version}" );
+                       }
                        $autoload = $this->processAutoLoader( dirname( $path ), $info );
                        // Set up the autoloader now so custom processors will work
                        $GLOBALS['wgAutoloadClasses'] += $autoload;
                        $autoloadClasses += $autoload;
-                       $processor->extractInfo( $path, $info );
+                       $processor->extractInfo( $path, $info, $version );
                }
                $data = $processor->getExtractedInfo();
                // Need to set this so we can += to it later
@@ -146,7 +181,7 @@ class ExtensionRegistry {
 
        protected function exportExtractedData( array $info ) {
                foreach ( $info['globals'] as $key => $val ) {
-                       if ( !isset( $GLOBALS[$key] ) || !$GLOBALS[$key] ) {
+                       if ( !isset( $GLOBALS[$key] ) || ( is_array( $GLOBALS[$key] ) && !$GLOBALS[$key] ) ) {
                                $GLOBALS[$key] = $val;
                        } elseif ( $key === 'wgHooks' || $key === 'wgExtensionCredits' ) {
                                // Special case $wgHooks and $wgExtensionCredits, which require a recursive merge.