From 63fb18bd4e2c0e9a54662c1084487ff1cc59cd73 Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Tue, 12 Jun 2012 20:18:44 +0400 Subject: [PATCH] Add a way for packagers to override some installation details ...after a discussion with Debian packagers. They can now override installer classes and change LocalSettings.php the installer generates. The file intended for such overrides, mw-config/overrides.php, has intentionally been placed outside of includes to underline the "don't change includes" paradigm. Change-Id: Id82b90f6740307609bc6c6f4fb8765bc3484dbe7 --- docs/distributors.txt | 6 +- includes/AutoLoader.php | 3 + includes/installer/CliInstaller.php | 2 +- includes/installer/LocalSettingsGenerator.php | 16 ++--- includes/installer/WebInstaller.php | 2 +- maintenance/install.php | 2 +- mw-config/index.php | 2 +- mw-config/overrides.php | 63 +++++++++++++++++++ 8 files changed, 81 insertions(+), 15 deletions(-) create mode 100644 mw-config/overrides.php diff --git a/docs/distributors.txt b/docs/distributors.txt index d29822993c..4a65431533 100644 --- a/docs/distributors.txt +++ b/docs/distributors.txt @@ -87,9 +87,9 @@ which the user can edit by hand thereafter. It's just a plain old PHP file, and can contain any PHP statements. It usually sets global variables that are used for configuration, and includes files used by any extensions. -Distributors cannot easily add extra statements to the autogenerated -LocalSettings.php at the present time -- although hacking mw-config/index.php -would work. It would be nice if this situation could be improved. +Distributors can easily add extra statements to the autogenerated +LocalSettings.php by changing mw-config/overrides.php (see that file for details +and examples). There's a new maintenance/install.php script which could be used for performing an install through the command line. diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 78ed45083f..d29c4e35b6 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -992,6 +992,9 @@ $wgAutoloadLocalClasses = array( 'AnsiTermColorer' => 'maintenance/term/MWTerm.php', 'DummyTermColorer' => 'maintenance/term/MWTerm.php', + # mw-config + 'InstallerOverrides' => 'mw-config/overrides.php', + # tests 'DbTestPreviewer' => 'tests/testHelpers.inc', 'DbTestRecorder' => 'tests/testHelpers.inc', diff --git a/includes/installer/CliInstaller.php b/includes/installer/CliInstaller.php index 0c3876c79d..752e2149ba 100644 --- a/includes/installer/CliInstaller.php +++ b/includes/installer/CliInstaller.php @@ -132,7 +132,7 @@ class CliInstaller extends Installer { * @param $path String Full path to write LocalSettings.php to */ public function writeConfigurationFile( $path ) { - $ls = new LocalSettingsGenerator( $this ); + $ls = InstallerOverrides::getLocalSettingsGenerator( $this ); $ls->writeFile( "$path/LocalSettings.php" ); } diff --git a/includes/installer/LocalSettingsGenerator.php b/includes/installer/LocalSettingsGenerator.php index 9ed486cab8..bbc6b64efa 100644 --- a/includes/installer/LocalSettingsGenerator.php +++ b/includes/installer/LocalSettingsGenerator.php @@ -29,16 +29,16 @@ */ class LocalSettingsGenerator { - private $extensions = array(); - private $values = array(); - private $groupPermissions = array(); - private $dbSettings = ''; - private $safeMode = false; + protected $extensions = array(); + protected $values = array(); + protected $groupPermissions = array(); + protected $dbSettings = ''; + protected $safeMode = false; /** * @var Installer */ - private $installer; + protected $installer; /** * Constructor. @@ -166,7 +166,7 @@ class LocalSettingsGenerator { /** * @return String */ - private function buildMemcachedServerList() { + protected function buildMemcachedServerList() { $servers = $this->values['_MemCachedServers']; if( !$servers ) { @@ -187,7 +187,7 @@ class LocalSettingsGenerator { /** * @return String */ - private function getDefaultText() { + protected function getDefaultText() { if( !$this->values['wgImageMagickConvertCommand'] ) { $this->values['wgImageMagickConvertCommand'] = '/usr/bin/convert'; $magic = '#'; diff --git a/includes/installer/WebInstaller.php b/includes/installer/WebInstaller.php index 5bbe642999..4f31195e84 100644 --- a/includes/installer/WebInstaller.php +++ b/includes/installer/WebInstaller.php @@ -161,7 +161,7 @@ class WebInstaller extends Installer { 'Content-Disposition: attachment; filename="LocalSettings.php"' ); - $ls = new LocalSettingsGenerator( $this ); + $ls = InstallerOverrides::getLocalSettingsGenerator( $this ); $rightsProfile = $this->rightsProfiles[$this->getVar( '_RightsProfile' )]; foreach( $rightsProfile as $group => $rightsArr ) { $ls->setGroupRights( $group, $rightsArr ); diff --git a/maintenance/install.php b/maintenance/install.php index 96a65fcee9..65d6a706f2 100644 --- a/maintenance/install.php +++ b/maintenance/install.php @@ -81,7 +81,7 @@ class CommandLineInstaller extends Maintenance { } $installer = - new CliInstaller( $siteName, $adminName, $this->mOptions ); + InstallerOverrides::getCliInstaller( $siteName, $adminName, $this->mOptions ); $status = $installer->doEnvironmentChecks(); if( $status->isGood() ) { diff --git a/mw-config/index.php b/mw-config/index.php index edfae92828..3f993f0279 100644 --- a/mw-config/index.php +++ b/mw-config/index.php @@ -20,7 +20,7 @@ wfInstallerMain(); function wfInstallerMain() { global $wgRequest, $wgLang, $wgMetaNamespace, $wgCanonicalNamespaceNames; - $installer = new WebInstaller( $wgRequest ); + $installer = InstallerOverrides::getWebInstaller( $wgRequest ); if ( !$installer->startSession() ) { $installer->finish(); diff --git a/mw-config/overrides.php b/mw-config/overrides.php new file mode 100644 index 0000000000..ae98295122 --- /dev/null +++ b/mw-config/overrides.php @@ -0,0 +1,63 @@ +values['wgResourceLoaderMaxQueryLength'] = 512; + // add a new setting + $ls = parent::getText(); + return $ls . "\n\$wgUseTex = true;\n"; + } +} +*/ + +/** + * @since 1.20 + */ +class InstallerOverrides { + /** + * Instantiates and returns an instance of LocalSettingsGenerator or its descendant classes + * @param Installer $installer + * @return LocalSettingsGenerator + */ + public static function getLocalSettingsGenerator( Installer $installer ) { + return new LocalSettingsGenerator( $installer ); + } + + /** + * Instantiates and returns an instance of WebInstaller or its descendant classes + * @param WebRequest $request + * @return WebInstaller + */ + public static function getWebInstaller( WebRequest $request ) { + return new WebInstaller( $request ); + } + + /** + * Instantiates and returns an instance of CliInstaller or its descendant classes + * @param string $siteName + * @param string|null $admin + * @param array $options + * @return CliInstaller + */ + public static function getCliInstaller( $siteName, $admin = null, array $options = array() ) { + return new CliInstaller( $siteName, $admin, $options ); + } +} -- 2.20.1