Add a way for packagers to override some installation details
authorMax Semenik <maxsem.wiki@gmail.com>
Tue, 12 Jun 2012 16:18:44 +0000 (20:18 +0400)
committerMax Semenik <maxsem.wiki@gmail.com>
Tue, 12 Jun 2012 16:18:44 +0000 (20:18 +0400)
...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
includes/AutoLoader.php
includes/installer/CliInstaller.php
includes/installer/LocalSettingsGenerator.php
includes/installer/WebInstaller.php
maintenance/install.php
mw-config/index.php
mw-config/overrides.php [new file with mode: 0644]

index d298229..4a65431 100644 (file)
@@ -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.
index 78ed450..d29c4e3 100644 (file)
@@ -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',
index 0c3876c..752e214 100644 (file)
@@ -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" );
        }
 
index 9ed486c..bbc6b64 100644 (file)
  */
 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 = '#';
index 5bbe642..4f31195 100644 (file)
@@ -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 );
index 96a65fc..65d6a70 100644 (file)
@@ -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() ) {
index edfae92..3f993f0 100644 (file)
@@ -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 (file)
index 0000000..ae98295
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+/**
+ * MediaWiki installer overrides.
+ * Modify this file if you are a packager who needs to modify the behavior of the MediaWiki installer.
+ * Altering it is preferred over changing anything in /includes.
+ *
+ * Note: this file doesn't gets included from a global scope, don't use globals directly.
+ */
+
+/*
+
+Example of modifications:
+
+       public static function getLocalSettingsGenerator( Installer $installer ) {
+               return new MyLocalSettingsGenerator( $installer );
+       }
+
+Then add the following to the bottom of this file:
+
+class MyLocalSettingsGenerator extends LocalSettingsGenerator {
+       function getText() {
+               // Modify an existing setting
+               $this->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 );
+       }
+}