From: Platonides Date: Wed, 29 Sep 2010 15:47:56 +0000 (+0000) Subject: Remove $wgServerName. Its only usage was for {{servername}}, and needed to be kept... X-Git-Tag: 1.31.0-rc.0~34750 X-Git-Url: http://git.cyclocoop.org/%22%2C%20generer_url_ecrire%28?a=commitdiff_plain;h=3d408e8d5b660a1e3173c2122d22d1682f723d73;p=lhc%2Fweb%2Fwiklou.git Remove $wgServerName. Its only usage was for {{servername}}, and needed to be kept in sync with $wgServer in LocalSettings. None of the 3 globals based on it changed if you set it in LocalSettings. Note that all those !isset( $wgServerName ) in ApiTests were useless, since if not in LocalSettings it would be 'localhost', not null (as still are those !isset( $wgServer )). --- diff --git a/docs/distributors.txt b/docs/distributors.txt index 69dad93558..2a953a5ab8 100644 --- a/docs/distributors.txt +++ b/docs/distributors.txt @@ -96,9 +96,10 @@ Some configuration options that distributors might be in a position to set intelligently: * $wgEmergencyContact: An e-mail address that can be used to contact the wiki - administrator. By default, "wikiadmin@$wgServerName". + administrator. By default, "wikiadmin@ServerName". * $wgPasswordSender: The e-mail address to use when sending password e-mails. - By default, "MediaWiki Mail ". + By default, "MediaWiki Mail ". + (with ServerName guessed from the http request) * $wgSMTP: Can be configured to use SMTP for mail sending instead of PHP mail(). diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 60bc8918dc..07f8025d4d 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -56,23 +56,23 @@ $wgServer = ''; /** @cond file_level_code */ if( isset( $_SERVER['SERVER_NAME'] ) ) { - $wgServerName = $_SERVER['SERVER_NAME']; + $serverName = $_SERVER['SERVER_NAME']; } elseif( isset( $_SERVER['HOSTNAME'] ) ) { - $wgServerName = $_SERVER['HOSTNAME']; + $serverName = $_SERVER['HOSTNAME']; } elseif( isset( $_SERVER['HTTP_HOST'] ) ) { - $wgServerName = $_SERVER['HTTP_HOST']; + $serverName = $_SERVER['HTTP_HOST']; } elseif( isset( $_SERVER['SERVER_ADDR'] ) ) { - $wgServerName = $_SERVER['SERVER_ADDR']; + $serverName = $_SERVER['SERVER_ADDR']; } else { - $wgServerName = 'localhost'; + $serverName = 'localhost'; } $wgProto = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http'; -$wgServer = $wgProto.'://' . $wgServerName; +$wgServer = $wgProto.'://' . $serverName; # If the port is a non-standard one, add it to the URL if( isset( $_SERVER['SERVER_PORT'] ) - && !strpos( $wgServerName, ':' ) + && !strpos( $serverName, ':' ) && ( ( $wgProto == 'http' && $_SERVER['SERVER_PORT'] != 80 ) || ( $wgProto == 'https' && $_SERVER['SERVER_PORT'] != 443 ) ) ) { @@ -968,14 +968,16 @@ $wgDjvuOutputExtension = 'jpg'; /** * Site admin email address. */ -$wgEmergencyContact = 'wikiadmin@' . $wgServerName; +$wgEmergencyContact = 'wikiadmin@' . $serverName; /** * Password reminder email address. * * The address we should use as sender when a user is requesting his password. */ -$wgPasswordSender = 'MediaWiki Mail '; +$wgPasswordSender = 'MediaWiki Mail '; + +unset($serverName); # Don't leak local variables to global scope /** * Dummy address which should be accepted during mail send action. diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 8dc091ad95..5e8a5c2d7b 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -2495,7 +2495,7 @@ class Parser { * @private */ function getVariableValue( $index, $frame=false ) { - global $wgContLang, $wgSitename, $wgServer, $wgServerName; + global $wgContLang, $wgSitename, $wgServer; global $wgArticlePath, $wgScriptPath, $wgStylePath; /** @@ -2777,7 +2777,10 @@ class Parser { case 'server': return $wgServer; case 'servername': - return $wgServerName; + wfSuppressWarnings(); # May give an E_WARNING in PHP < 5.3.3 + $serverName = parse_url( $wgServer, PHP_URL_HOST ); + wfRestoreWarnings(); + return $serverName ? $serverName : $wgServer; case 'scriptpath': return $wgScriptPath; case 'stylepath': diff --git a/maintenance/tests/parser/parserTest.inc b/maintenance/tests/parser/parserTest.inc index 6e86375c96..8c580331c4 100644 --- a/maintenance/tests/parser/parserTest.inc +++ b/maintenance/tests/parser/parserTest.inc @@ -532,7 +532,7 @@ class ParserTest { self::getOptionValue( 'wgLinkHolderBatchSize', $opts, 1000 ); $settings = array( - 'wgServer' => 'http://localhost', + 'wgServer' => 'http://Britney-Spears', 'wgScript' => '/index.php', 'wgScriptPath' => '/', 'wgArticlePath' => '/wiki/$1', @@ -549,7 +549,6 @@ class ParserTest { 'wgStylePath' => '/skins', 'wgStyleSheetPath' => '/skins', 'wgSitename' => 'MediaWiki', - 'wgServerName' => 'Britney-Spears', 'wgLanguageCode' => $lang, 'wgDBprefix' => $wgDBtype != 'oracle' ? 'parsertest_' : 'pt_', 'wgRawHtml' => isset( $opts['rawhtml'] ), diff --git a/maintenance/tests/parser/parserTests.txt b/maintenance/tests/parser/parserTests.txt index 43ac4bfc8d..b69b95c747 100644 --- a/maintenance/tests/parser/parserTests.txt +++ b/maintenance/tests/parser/parserTests.txt @@ -2090,7 +2090,7 @@ Magic Word: {{SERVER}} !! input {{SERVER}} !! result -

http://localhost +

http://Britney-Spears

!! end diff --git a/maintenance/tests/phpunit/includes/api/ApiTest.php b/maintenance/tests/phpunit/includes/api/ApiTest.php index ee77c86985..9ee931f9cb 100644 --- a/maintenance/tests/phpunit/includes/api/ApiTest.php +++ b/maintenance/tests/phpunit/includes/api/ApiTest.php @@ -54,11 +54,10 @@ class ApiTest extends ApiTestSetup { } function testApi() { - global $wgServerName, $wgServer; + global $wgServer; - if ( !isset( $wgServerName ) || !isset( $wgServer ) ) { - $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' . - 'be set in LocalSettings.php' ); + if ( !isset( $wgServer ) ) { + $this->markTestIncomplete( 'This test needs $wgServer to be set in LocalSettings.php' ); } /* Haven't thought about test ordering yet -- but this depends on HttpTest.php */ $resp = Http::get( self::$apiUrl . "?format=xml" ); @@ -70,11 +69,10 @@ class ApiTest extends ApiTestSetup { } function testApiLoginNoName() { - global $wgServerName, $wgServer; + global $wgServer; - if ( !isset( $wgServerName ) || !isset( $wgServer ) ) { - $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' . - 'be set in LocalSettings.php' ); + if ( !isset( $wgServer ) ) { + $this->markTestIncomplete( 'This test needs $wgServer to be set in LocalSettings.php' ); } $resp = Http::post( self::$apiUrl . "?action=login&format=xml", array( "postData" => array( @@ -89,11 +87,10 @@ class ApiTest extends ApiTestSetup { } function testApiLoginBadPass() { - global $wgServerName, $wgServer; + global $wgServer; - if ( !isset( $wgServerName ) || !isset( $wgServer ) ) { - $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' . - 'be set in LocalSettings.php' ); + if ( !isset( $wgServer ) ) { + $this->markTestIncomplete( 'This test needs $wgServer to be set in LocalSettings.php' ); } $resp = Http::post( self::$apiUrl . "?action=login&format=xml", array( "postData" => array( @@ -124,11 +121,10 @@ class ApiTest extends ApiTestSetup { } function testApiLoginGoodPass() { - global $wgServerName, $wgServer; + global $wgServer; - if ( !isset( $wgServerName ) || !isset( $wgServer ) ) { - $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' . - 'be set in LocalSettings.php' ); + if ( !isset( $wgServer ) ) { + $this->markTestIncomplete( 'This test needs $wgServer to be set in LocalSettings.php' ); } $req = HttpRequest::factory( self::$apiUrl . "?action=login&format=xml", array( "method" => "POST", @@ -163,11 +159,10 @@ class ApiTest extends ApiTestSetup { } function testApiGotCookie() { - global $wgServerName, $wgServer, $wgScriptPath; + global $wgServer, $wgScriptPath; - if ( !isset( $wgServerName ) || !isset( $wgServer ) ) { - $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' . - 'be set in LocalSettings.php' ); + if ( !isset( $wgServer ) ) { + $this->markTestIncomplete( 'This test needs $wgServer to be set in LocalSettings.php' ); } $req = HttpRequest::factory( self::$apiUrl . "?action=login&format=xml", array( "method" => "POST", @@ -193,7 +188,9 @@ class ApiTest extends ApiTestSetup { $req->execute(); $cj = $req->getCookieJar(); - $serializedCookie = $cj->serializeToHttpRequest( $wgScriptPath, $wgServerName ); + $serverName = parse_url( $wgServer, PHP_URL_HOST ); + $this->assertNotEquals( false, $serverName ); + $serializedCookie = $cj->serializeToHttpRequest( $wgScriptPath, $serverName ); $this->assertNotEquals( '', $serializedCookie ); $this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . self::$userName . '; .*Token=/', $serializedCookie ); @@ -206,11 +203,10 @@ class ApiTest extends ApiTestSetup { */ function testApiListPages( CookieJar $cj ) { $this->markTestIncomplete( "Not done with this yet" ); - global $wgServerName, $wgServer; + global $wgServer; - if ( $wgServerName == "localhost" || $wgServer == "http://localhost" ) { - $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' . - 'be set in LocalSettings.php' ); + if ( $wgServer == "http://localhost" ) { + $this->markTestIncomplete( 'This test needs $wgServer to be set in LocalSettings.php' ); } $req = HttpRequest::factory( self::$apiUrl . "?action=query&format=xml&prop=revisions&" . "titles=Main%20Page&rvprop=timestamp|user|comment|content" );