Merge "Rename testBug25702() to testPrefixNormalizationSearchBug()"
[lhc/web/wiklou.git] / maintenance / convertExtensionToRegistration.php
index 06370e9..8adae2d 100644 (file)
@@ -25,6 +25,15 @@ class ConvertExtensionToRegistration extends Maintenance {
                'TrackingCategories',
        );
 
+       /**
+        * No longer supported globals (with reason) should not be converted and emit a warning
+        *
+        * @var array
+        */
+       protected $noLongerSupportedGlobals = array(
+               'SpecialPageGroups' => 'deprecated',
+       );
+
        /**
         * Keys that should be put at the top of the generated JSON file (T86608)
         *
@@ -42,7 +51,7 @@ class ConvertExtensionToRegistration extends Maintenance {
                'type',
        );
 
-       private $json, $dir;
+       private $json, $dir, $hasWarning = false;
 
        public function __construct() {
                parent::__construct();
@@ -61,7 +70,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();
                }
@@ -70,19 +82,27 @@ 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 ) );
                        } elseif ( in_array( $realName, $globalSettings ) ) {
                                $this->json[$realName] = $value;
+                       } elseif ( array_key_exists( $realName, $this->noLongerSupportedGlobals ) ) {
+                               $this->output( 'Warning: Skipped global "' . $name . '" (' .
+                                       $this->noLongerSupportedGlobals[$realName] . '). ' .
+                                       "Please update the entry point before convert to registration.\n" );
+                               $this->hasWarning = true;
                        } elseif ( strpos( $name, 'wg' ) === 0 ) {
                                // Most likely a config setting
                                $this->json['config'][$realName] = $value;
@@ -98,12 +118,16 @@ 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 );
                file_put_contents( $fname, $prettyJSON . "\n" );
                $this->output( "Wrote output to $fname.\n" );
+               if ( $this->hasWarning ) {
+                       $this->output( "Found warnings! Please resolve the warnings and rerun this script.\n" );
+               }
        }
 
        protected function handleExtensionFunctions( $realName, $value ) {