Add support for HD versions of the wiki logo in MonoBook-like skins.
[lhc/web/wiklou.git] / maintenance / convertExtensionToRegistration.php
index 75500c2..76bc982 100644 (file)
@@ -14,11 +14,30 @@ class ConvertExtensionToRegistration extends Maintenance {
                'ExtensionFunctions' => 'handleExtensionFunctions',
        );
 
+       /**
+        * Keys that should be put at the top of the generated JSON file (T86608)
+        *
+        * @var array
+        */
+       protected $promote = array(
+               'name',
+               'version',
+               'author',
+               'url',
+               'description',
+               'descriptionmsg',
+               'namemsg',
+               'license-name',
+               'type',
+       );
+
        private $json, $dir;
 
        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->addOption( 'skin', 'Whether to write to skin.json', false, false );
        }
 
        protected function getAllGlobals() {
@@ -59,8 +78,19 @@ class ConvertExtensionToRegistration extends Maintenance {
                        }
                }
 
-               $fname = "{$this->dir}/extension.json";
-               $prettyJSON = FormatJson::encode( $this->json, "\t", FormatJson::ALL_OK );
+               // Move some keys to the top
+               $out = array();
+               foreach ( $this->promote as $key ) {
+                       if ( isset( $this->json[$key] ) ) {
+                               $out[$key] = $this->json[$key];
+                               unset( $this->json[$key] );
+                       }
+               }
+               $out += $this->json;
+
+               $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" );
        }
@@ -125,12 +155,36 @@ class ConvertExtensionToRegistration extends Maintenance {
        }
 
        protected function handleResourceModules( $realName, $value ) {
+               $defaults = array();
+               $remote = $this->hasOption( 'skin' ) ? 'remoteSkinPath' : 'remoteExtPath';
                foreach ( $value as $name => $data ) {
                        if ( isset( $data['localBasePath'] ) ) {
                                $data['localBasePath'] = $this->stripPath( $data['localBasePath'], $this->dir );
+                               if ( !$defaults ) {
+                                       $defaults['localBasePath'] = $data['localBasePath'];
+                                       unset( $data['localBasePath'] );
+                                       if ( isset( $data[$remote] ) ) {
+                                               $defaults[$remote] = $data[$remote];
+                                               unset( $data[$remote] );
+                                       }
+                               } else {
+                                       if ( $data['localBasePath'] === $defaults['localBasePath'] ) {
+                                               unset( $data['localBasePath'] );
+                                       }
+                                       if ( isset( $data[$remote] ) && isset( $defaults[$remote] )
+                                               && $data[$remote] === $defaults[$remote]
+                                       ) {
+                                               unset( $data[$remote] );
+                                       }
+                               }
                        }
+
+
                        $this->json[$realName][$name] = $data;
                }
+               if ( $defaults ) {
+                       $this->json['ResourceFileModulePaths'] = $defaults;
+               }
        }
 }