Do not allow setting deprecated $wgSpecialPageGroups over extension.json
[lhc/web/wiklou.git] / maintenance / convertExtensionToRegistration.php
index 76bc982..e6523d0 100644 (file)
@@ -6,12 +6,32 @@ class ConvertExtensionToRegistration extends Maintenance {
 
        protected $custom = array(
                'MessagesDirs' => 'handleMessagesDirs',
-               'ExtensionMessagesFiles' => 'removeAbsolutePath',
+               'ExtensionMessagesFiles' => 'handleExtensionMessagesFiles',
                'AutoloadClasses' => 'removeAbsolutePath',
                'ExtensionCredits' => 'handleCredits',
                'ResourceModules' => 'handleResourceModules',
+               'ResourceModuleSkinStyles' => 'handleResourceModules',
                'Hooks' => 'handleHooks',
                'ExtensionFunctions' => 'handleExtensionFunctions',
+               'ParserTestFiles' => 'removeAbsolutePath',
+       );
+
+       /**
+        * Things that were formerly globals and should still be converted
+        *
+        * @var array
+        */
+       protected $formerGlobals = array(
+               'TrackingCategories',
+       );
+
+       /**
+        * No longer supported globals (with reason) should not be converted and emit a warning
+        *
+        * @var array
+        */
+       protected $noLongerSupportedGlobals = array(
+               'SpecialPageGroups' => 'deprecated',
        );
 
        /**
@@ -31,7 +51,7 @@ class ConvertExtensionToRegistration extends Maintenance {
                'type',
        );
 
-       private $json, $dir;
+       private $json, $dir, $hasWarning = false;
 
        public function __construct() {
                parent::__construct();
@@ -44,7 +64,7 @@ class ConvertExtensionToRegistration extends Maintenance {
                $processor = new ReflectionClass( 'ExtensionProcessor' );
                $settings = $processor->getProperty( 'globalSettings' );
                $settings->setAccessible( true );
-               return $settings->getValue();
+               return $settings->getValue() + $this->formerGlobals;
        }
 
        public function execute() {
@@ -69,9 +89,14 @@ class ConvertExtensionToRegistration extends Maintenance {
                        }
                        $realName = substr( $name, 2 ); // Strip 'wg'
                        if ( isset( $this->custom[$realName] ) ) {
-                               call_user_func_array( array( $this, $this->custom[$realName] ), array( $realName, $value ) );
+                               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;
@@ -93,6 +118,9 @@ class ConvertExtensionToRegistration extends Maintenance {
                $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 ) {
@@ -113,6 +141,21 @@ class ConvertExtensionToRegistration extends Maintenance {
                }
        }
 
+       protected function handleExtensionMessagesFiles( $realName, $value, $vars ) {
+               foreach ( $value as $key => $file ) {
+                       $strippedFile = $this->stripPath( $file, $this->dir );
+                       if ( isset( $vars['wgMessagesDirs'][$key] ) ) {
+                               $this->output(
+                                       "Note: Ignoring PHP shim $strippedFile. " .
+                                       "If your extension no longer supports versions of MediaWiki " .
+                                       "older than 1.23.0, you can safely delete it.\n"
+                               );
+                       } else {
+                               $this->json[$realName][$key] = $strippedFile;
+                       }
+               }
+       }
+
        private function stripPath( $val, $dir ) {
                if ( $val === $dir ) {
                        $val = '';