Gergő Tisza has uploaded a new change for review. https://gerrit.wikimedia.org/r/193550
Change subject: Fix host detection for CLI scripts ...................................................................... Fix host detection for CLI scripts Bug: T90361 Change-Id: I67237e2a30bf29f08fd386b94eb22d69b8ffe911 --- M puppet/modules/mediawiki/manifests/multiwiki.pp M puppet/modules/mediawiki/templates/docroot/w/MWMultiVersion.php.erb M puppet/modules/mediawiki/templates/multiwiki/CommonSettings.php.erb 3 files changed, 38 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/vagrant refs/changes/50/193550/1 diff --git a/puppet/modules/mediawiki/manifests/multiwiki.pp b/puppet/modules/mediawiki/manifests/multiwiki.pp index 7e0d7e4..033a92d 100644 --- a/puppet/modules/mediawiki/manifests/multiwiki.pp +++ b/puppet/modules/mediawiki/manifests/multiwiki.pp @@ -93,6 +93,7 @@ content => template('mediawiki/docroot/w/missing.php.erb'), } + $default_hostname = $::role::mediawiki::hostname file { "${script_dir}/MWMultiVersion.php": ensure => present, mode => '0644', diff --git a/puppet/modules/mediawiki/templates/docroot/w/MWMultiVersion.php.erb b/puppet/modules/mediawiki/templates/docroot/w/MWMultiVersion.php.erb index 4edc555..aec27ca 100644 --- a/puppet/modules/mediawiki/templates/docroot/w/MWMultiVersion.php.erb +++ b/puppet/modules/mediawiki/templates/docroot/w/MWMultiVersion.php.erb @@ -11,6 +11,21 @@ */ class MWMultiVersion { /** + * @var string + */ + const BASE_DOMAIN = '<%= @base_domain %>'; + + /** + * @var string + */ + const DEFAULT_HOSTNAME = '<%= @default_hostname %>'; + + /** + * @var string + */ + const PORT_FRAGMENT = '<%= @port_fragment %>'; + + /** * @var MWMultiVersion */ private static $instance; @@ -91,7 +106,7 @@ private function setSiteInfoForWiki( $serverName ) { $lang = ''; $matches = array(); - $baseDomain = preg_quote( '<%= @base_domain %>' ); + $baseDomain = preg_quote( self::BASE_DOMAIN ); if ( preg_match( "/^(\w+){$baseDomain}\$/", $serverName, $matches ) ) { $lang = $matches[1]; } @@ -141,6 +156,21 @@ } /** + * Get the host name (as in the Host HTTP header) for this wiki. + * This is a Vagrant-specific hack to passs on puppet facts to + * to CLI scripts which otherwise could not figure out the right settings. + * @return string + */ + public function getHttpHost() { + if ( $this->db === 'wiki' ) { + $domain = self::DEFAULT_HOSTNAME; + } else { + $domain = substr( $this->db, 0, -4 ) . self::BASE_DOMAIN; + } + return $domain . self::PORT_FRAGMENT; + } + + /** * Check if this wiki is *not* specified in a cdb file * located at /usr/local/apache/common-local/wikiversions.cdb. * @return bool diff --git a/puppet/modules/mediawiki/templates/multiwiki/CommonSettings.php.erb b/puppet/modules/mediawiki/templates/multiwiki/CommonSettings.php.erb index 8f08d68..7317b90 100644 --- a/puppet/modules/mediawiki/templates/multiwiki/CommonSettings.php.erb +++ b/puppet/modules/mediawiki/templates/multiwiki/CommonSettings.php.erb @@ -17,6 +17,11 @@ $multiVersion = MWMultiVersion::initializeForWiki( '<%= scope['::mediawiki::db_name'] %>' ); } +if ( PHP_SAPI === 'cli' ) { + // make WebRequest::detectServer() work + $_SERVER['HTTP_HOST'] = $multiVersion->getHttpHost(); +} + // This must be set *after* the DefaultSettings.php inclusion $wgDBname = $multiVersion->getDatabase(); @@ -37,5 +42,5 @@ include_once $conffile; } -# Bug 66399: set wgServer from inbound request +# T68399: set wgServer from inbound request $wgServer = WebRequest::detectServer(); -- To view, visit https://gerrit.wikimedia.org/r/193550 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I67237e2a30bf29f08fd386b94eb22d69b8ffe911 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/vagrant Gerrit-Branch: master Gerrit-Owner: Gergő Tisza <gti...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits