From 7935bd4c8012c96f368fda7a520b1a24a378a847 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Wed, 1 Apr 2015 00:07:44 -0700 Subject: [PATCH] installer: Use wfLoadExtension/Skin in LocalSettingsGenerator Bug: T87791 Change-Id: I37cede7396d9677466ec68289702a3a73f1a1f8a --- includes/installer/Installer.php | 5 +++- includes/installer/LocalSettingsGenerator.php | 28 ++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 4c31387ac8..b40b3f1473 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -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; } } diff --git a/includes/installer/LocalSettingsGenerator.php b/includes/installer/LocalSettingsGenerator.php index 3ba5e37aab..737c9969bd 100644 --- a/includes/installer/LocalSettingsGenerator.php +++ b/includes/installer/LocalSettingsGenerator.php @@ -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"; + } } /** -- 2.20.1