From 513a7198e88b60b4a740109218fa60fcd79db99e Mon Sep 17 00:00:00 2001 From: YuviPanda Date: Mon, 7 Oct 2013 01:11:18 +0530 Subject: [PATCH] Do not set wgServer in cli install unless explicitly passed 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 | 2 +- includes/installer/Installer.php | 8 ++++---- includes/installer/LocalSettingsGenerator.php | 13 ++++++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/includes/installer/CliInstaller.php b/includes/installer/CliInstaller.php index 1e6e8c844e..f944fbed4a 100644 --- a/includes/installer/CliInstaller.php +++ b/includes/installer/CliInstaller.php @@ -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 ) { diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 53ecdb9cdb..5eaacf85cc 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -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; } diff --git a/includes/installer/LocalSettingsGenerator.php b/includes/installer/LocalSettingsGenerator.php index dec855e9ce..858fbeef8e 100644 --- a/includes/installer/LocalSettingsGenerator.php +++ b/includes/installer/LocalSettingsGenerator.php @@ -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\"; -- 2.20.1