Do not set wgServer in cli install unless explicitly passed
authorYuviPanda <yuvipanda@gmail.com>
Sun, 6 Oct 2013 19:41:18 +0000 (01:11 +0530)
committerYuviPanda <yuvipanda@gmail.com>
Thu, 10 Oct 2013 08:31:22 +0000 (14:01 +0530)
Currently, if we do not pass a wgServer value (via --server),
the CLI installer sets the value to the default value
specified in DefaultSettings.php - which is to 'guess' by
calling into WebRequest::detectServer. This yields terrible
results, since WebRequest::detectServer expects to be working
in the context of a Web Request - and hence with HTTP Host
header information. Since calling from the CLI does not give
it host header information, it falls back to 'localhost',
which is not the value you usually want.

If we just do not set wgServer when it is not specified,
it is automatically calculated on every request by
WebRequest::detectServer, which does a splendid job.

Bug: 55376
Change-Id: I5436dd8c340604cbb59406a507188e11c8f86e86

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

index 1e6e8c8..f944fbe 100644 (file)
@@ -203,7 +203,7 @@ class CliInstaller extends Installer {
        }
 
        protected function envGetDefaultServer() {
-               return $this->getVar( 'wgServer' );
+               return null; // Do not guess if installing from CLI
        }
 
        public function dirIsExecutable( $dir, $url ) {
index 53ecdb9..5eaacf8 100644 (file)
@@ -158,7 +158,6 @@ abstract class Installer {
                'wgImageMagickConvertCommand',
                'wgGitBin',
                'IP',
-               'wgServer',
                'wgScriptPath',
                'wgScriptExtension',
                'wgMetaNamespace',
@@ -980,9 +979,10 @@ abstract class Installer {
         */
        protected function envCheckServer() {
                $server = $this->envGetDefaultServer();
-               $this->showMessage( 'config-using-server', $server );
-               $this->setVar( 'wgServer', $server );
-
+               if ( $server !== null ) {
+                       $this->showMessage( 'config-using-server', $server );
+                       $this->setVar( 'wgServer', $server );
+               }
                return true;
        }
 
index dec855e..858fbee 100644 (file)
@@ -80,7 +80,7 @@ class LocalSettingsGenerator {
                                $val = wfBoolToStr( $val );
                        }
 
-                       if ( !in_array( $c, $unescaped ) ) {
+                       if ( !in_array( $c, $unescaped ) && $val !== null ) {
                                $val = self::escapePhpString( $val );
                        }
 
@@ -222,6 +222,12 @@ class LocalSettingsGenerator {
                        }
                }
 
+               $wgServerSetting = "";
+               if ( array_key_exists( 'wgServer', $this->values ) && $this->values['wgServer'] !== null ) {
+                       $wgServerSetting = "\n## The protocol and server name to use in fully-qualified URLs\n";
+                       $wgServerSetting .= "\$wgServer = \"{$this->values['wgServer']}\";\n";
+               }
+
                switch ( $this->values['wgMainCacheType'] ) {
                        case 'anything':
                        case 'db':
@@ -265,10 +271,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 ## http://www.mediawiki.org/wiki/Manual:Short_URL
 \$wgScriptPath = \"{$this->values['wgScriptPath']}\";
 \$wgScriptExtension = \"{$this->values['wgScriptExtension']}\";
-
-## The protocol and server name to use in fully-qualified URLs
-\$wgServer = \"{$this->values['wgServer']}\";
-
+${wgServerSetting}
 ## The relative URL path to the skins directory
 \$wgStylePath = \"\$wgScriptPath/skins\";