phpdoc @return MediaWikiTitleCodec in Title::getTitleParser
[lhc/web/wiklou.git] / maintenance / convertExtensionToRegistration.php
index 608605c..eeb2e6d 100644 (file)
@@ -55,7 +55,7 @@ class ConvertExtensionToRegistration extends Maintenance {
 
        public function __construct() {
                parent::__construct();
-               $this->mDescription = 'Converts extension entry points to the new JSON registration format';
+               $this->addDescription( '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 );
@@ -116,6 +116,13 @@ class ConvertExtensionToRegistration extends Maintenance {
                        }
                }
 
+               // check, if the extension requires composer libraries
+               if ( $this->needsComposerAutoloader( dirname( $this->getArg( 0 ) ) ) ) {
+                       // set the load composer autoloader automatically property
+                       $this->output( "Detected composer dependencies, setting 'load_composer_autoloader' to true.\n" );
+                       $this->json['load_composer_autoloader'] = true;
+               }
+
                // Move some keys to the top
                $out = array();
                foreach ( $this->promote as $key ) {
@@ -144,6 +151,12 @@ class ConvertExtensionToRegistration extends Maintenance {
                                        "Please move your extension function somewhere else.", 1
                                );
                        }
+                       // check if $func exists in the global scope
+                       if ( function_exists( $func ) ) {
+                               $this->error( "Error: Global functions cannot be converted to JSON. " .
+                                       "Please move your extension function ($func) into a class.", 1
+                               );
+                       }
                }
 
                $this->json[$realName] = $value;
@@ -210,6 +223,12 @@ class ConvertExtensionToRegistration extends Maintenance {
                                                "Please move the handler for $hookName somewhere else.", 1
                                        );
                                }
+                               // Check if $func exists in the global scope
+                               if ( function_exists( $func ) ) {
+                                       $this->error( "Error: Global functions cannot be converted to JSON. " .
+                                               "Please move the handler for $hookName inside a class.", 1
+                                       );
+                               }
                        }
                }
                $this->json[$realName] = $value;
@@ -246,6 +265,19 @@ class ConvertExtensionToRegistration extends Maintenance {
                        $this->json['ResourceFileModulePaths'] = $defaults;
                }
        }
+
+       protected function needsComposerAutoloader( $path ) {
+               $path .= '/composer.json';
+               if ( file_exists( $path ) ) {
+                       // assume, that the composer.json file is in the root of the extension path
+                       $composerJson = new ComposerJson( $path );
+                       // check, if there are some dependencies in the require section
+                       if ( $composerJson->getRequiredDependencies() ) {
+                               return true;
+                       }
+               }
+               return false;
+       }
 }
 
 $maintClass = 'ConvertExtensionToRegistration';