Merge "API: Finish killing "raw mode""
[lhc/web/wiklou.git] / maintenance / convertExtensionToRegistration.php
index e6523d0..3e86d8a 100644 (file)
@@ -31,7 +31,7 @@ class ConvertExtensionToRegistration extends Maintenance {
         * @var array
         */
        protected $noLongerSupportedGlobals = array(
-               'SpecialPageGroups' => 'deprecated',
+               'SpecialPageGroups' => 'deprecated', // Deprecated 1.21, removed in 1.26
        );
 
        /**
@@ -56,7 +56,8 @@ class ConvertExtensionToRegistration extends Maintenance {
        public function __construct() {
                parent::__construct();
                $this->mDescription = 'Converts extension entry points to the new JSON registration format';
-               $this->addArg( 'path', 'Location to the PHP entry point you wish to convert', /* $required = */ true );
+               $this->addArg( 'path', 'Location to the PHP entry point you wish to convert',
+                       /* $required = */ true );
                $this->addOption( 'skin', 'Whether to write to skin.json', false, false );
        }
 
@@ -70,7 +71,10 @@ class ConvertExtensionToRegistration extends Maintenance {
        public function execute() {
                // Extensions will do stuff like $wgResourceModules += array(...) which is a
                // fatal unless an array is already set. So set an empty value.
-               foreach ( array_merge( $this->getAllGlobals(), array_keys( $this->custom ) ) as $var ) {
+               // And use the weird $__settings name to avoid any conflicts
+               // with real poorly named settings.
+               $__settings = array_merge( $this->getAllGlobals(), array_keys( $this->custom ) );
+               foreach ( $__settings as $var ) {
                        $var = 'wg' . $var;
                        $$var = array();
                }
@@ -79,17 +83,21 @@ class ConvertExtensionToRegistration extends Maintenance {
                // Try not to create any local variables before this line
                $vars = get_defined_vars();
                unset( $vars['this'] );
+               unset( $vars['__settings'] );
                $this->dir = dirname( realpath( $this->getArg( 0 ) ) );
                $this->json = array();
                $globalSettings = $this->getAllGlobals();
                foreach ( $vars as $name => $value ) {
-                       // If an empty array, assume it's the default we set, so skip it
-                       if ( is_array( $value ) && count( $value ) === 0 ) {
+                       $realName = substr( $name, 2 ); // Strip 'wg'
+
+                       // If it's an empty array that we likely set, skip it
+                       if ( is_array( $value ) && count( $value ) === 0 && in_array( $realName, $__settings ) ) {
                                continue;
                        }
-                       $realName = substr( $name, 2 ); // Strip 'wg'
+
                        if ( isset( $this->custom[$realName] ) ) {
-                               call_user_func_array( array( $this, $this->custom[$realName] ), array( $realName, $value, $vars ) );
+                               call_user_func_array( array( $this, $this->custom[$realName] ),
+                                       array( $realName, $value, $vars ) );
                        } elseif ( in_array( $realName, $globalSettings ) ) {
                                $this->json[$realName] = $value;
                        } elseif ( array_key_exists( $realName, $this->noLongerSupportedGlobals ) ) {
@@ -112,7 +120,8 @@ class ConvertExtensionToRegistration extends Maintenance {
                        }
                }
                $out += $this->json;
-
+               // Put this at the bottom
+               $out['manifest_version'] = ExtensionRegistry::MANIFEST_VERSION;
                $type = $this->hasOption( 'skin' ) ? 'skin' : 'extension';
                $fname = "{$this->dir}/$type.json";
                $prettyJSON = FormatJson::encode( $out, "\t", FormatJson::ALL_OK );
@@ -126,7 +135,9 @@ class ConvertExtensionToRegistration extends Maintenance {
        protected function handleExtensionFunctions( $realName, $value ) {
                foreach ( $value as $func ) {
                        if ( $func instanceof Closure ) {
-                               $this->error( "Error: Closures cannot be converted to JSON. Please move your extension function somewhere else.", 1 );
+                               $this->error( "Error: Closures cannot be converted to JSON. " .
+                                       "Please move your extension function somewhere else.", 1
+                               );
                        }
                }
 
@@ -175,7 +186,7 @@ class ConvertExtensionToRegistration extends Maintenance {
                $this->json[$realName] = $out;
        }
 
-       protected function handleCredits( $realName, $value) {
+       protected function handleCredits( $realName, $value ) {
                $keys = array_keys( $value );
                $this->json['type'] = $keys[0];
                $values = array_values( $value );
@@ -190,7 +201,9 @@ class ConvertExtensionToRegistration extends Maintenance {
                foreach ( $value as $hookName => $handlers ) {
                        foreach ( $handlers as $func ) {
                                if ( $func instanceof Closure ) {
-                                       $this->error( "Error: Closures cannot be converted to JSON. Please move the handler for $hookName somewhere else.", 1 );
+                                       $this->error( "Error: Closures cannot be converted to JSON. " .
+                                               "Please move the handler for $hookName somewhere else.", 1
+                                       );
                                }
                        }
                }
@@ -222,7 +235,6 @@ class ConvertExtensionToRegistration extends Maintenance {
                                }
                        }
 
-
                        $this->json[$realName][$name] = $data;
                }
                if ( $defaults ) {