installer: Use wfLoadExtension/Skin in LocalSettingsGenerator
authorKunal Mehta <legoktm@gmail.com>
Wed, 1 Apr 2015 07:07:44 +0000 (00:07 -0700)
committerKunal Mehta <legoktm@gmail.com>
Wed, 1 Apr 2015 07:16:17 +0000 (00:16 -0700)
Bug: T87791
Change-Id: I37cede7396d9677466ec68289702a3a73f1a1f8a

includes/installer/Installer.php
includes/installer/LocalSettingsGenerator.php

index 4c31387..b40b3f1 100644 (file)
@@ -1436,13 +1436,16 @@ abstract class Installer {
                        return array();
                }
 
+               // extensions -> extension.json, skins -> skin.json
+               $jsonFile = substr( $directory, 0, strlen( $directory ) -1 ) . '.json';
+
                $dh = opendir( $extDir );
                $exts = array();
                while ( ( $file = readdir( $dh ) ) !== false ) {
                        if ( !is_dir( "$extDir/$file" ) ) {
                                continue;
                        }
-                       if ( file_exists( "$extDir/$file/$file.php" ) ) {
+                       if ( file_exists( "$extDir/$file/$jsonFile" ) || file_exists( "$extDir/$file/$file.php" ) ) {
                                $exts[] = $file;
                        }
                }
index 3ba5e37..737c996 100644 (file)
@@ -34,6 +34,7 @@ class LocalSettingsGenerator {
        protected $groupPermissions = array();
        protected $dbSettings = '';
        protected $safeMode = false;
+       protected $IP;
 
        /**
         * @var Installer
@@ -50,6 +51,7 @@ class LocalSettingsGenerator {
 
                $this->extensions = $installer->getVar( '_Extensions' );
                $this->skins = $installer->getVar( '_Skins' );
+               $this->IP = $installer->getVar( 'IP' );
 
                $db = $installer->getDBInstaller( $installer->getVar( 'wgDBtype' ) );
 
@@ -143,7 +145,7 @@ class LocalSettingsGenerator {
 # The following skins were automatically enabled:\n";
 
                        foreach ( $this->skins as $skinName ) {
-                               $localSettings .= $this->generateRequireOnceLine( 'skins', $skinName );
+                               $localSettings .= $this->generateExtEnableLine( 'skins', $skinName );
                        }
 
                        $localSettings .= "\n";
@@ -156,7 +158,7 @@ class LocalSettingsGenerator {
 # The following extensions were automatically enabled:\n";
 
                        foreach ( $this->extensions as $extName ) {
-                               $localSettings .= $this->generateRequireOnceLine( 'extensions', $extName );
+                               $localSettings .= $this->generateExtEnableLine( 'extensions', $extName );
                        }
 
                        $localSettings .= "\n";
@@ -170,13 +172,31 @@ class LocalSettingsGenerator {
        }
 
        /**
+        * Generate the appropriate line to enable the given extension or skin
+        *
         * @param string $dir Either "extensions" or "skins"
         * @param string $name Name of extension/skin
+        * @throws InvalidArgumentException
         * @return string
         */
-       private function generateRequireOnceLine( $dir, $name ) {
+       private function generateExtEnableLine( $dir, $name ) {
+               if ( $dir === 'extensions' ) {
+                       $jsonFile = 'extension.json';
+                       $function = 'wfLoadExtension';
+               } elseif ( $dir === 'skins' ) {
+                       $jsonFile = 'skin.json';
+                       $function = 'wfLoadSkin';
+               } else {
+                       throw new InvalidArgumentException( '$dir was not "extensions" or "skins' );
+               }
+
                $encName = self::escapePhpString( $name );
-               return "require_once \"\$IP/$dir/$encName/$encName.php\";\n";
+
+               if ( file_exists( "{$this->IP}/$dir/$encName/$jsonFile" ) ) {
+                       return "$function( '$encName' );\n";
+               } else {
+                       return "require_once \"\$IP/$dir/$encName/$encName.php\";\n";
+               }
        }
 
        /**