http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73950
Revision: 73950
Author: platonides
Date: 2010-09-29 15:47:56 +0000 (Wed, 29 Sep 2010)
Log Message:
-----------
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 )).
Modified Paths:
--------------
trunk/phase3/docs/distributors.txt
trunk/phase3/includes/DefaultSettings.php
trunk/phase3/includes/parser/Parser.php
trunk/phase3/maintenance/tests/parser/parserTest.inc
trunk/phase3/maintenance/tests/parser/parserTests.txt
trunk/phase3/maintenance/tests/phpunit/includes/api/ApiTest.php
Modified: trunk/phase3/docs/distributors.txt
===================================================================
--- trunk/phase3/docs/distributors.txt 2010-09-29 15:22:47 UTC (rev 73949)
+++ trunk/phase3/docs/distributors.txt 2010-09-29 15:47:56 UTC (rev 73950)
@@ -96,9 +96,10 @@
intelligently:
* $wgEmergencyContact: An e-mail address that can be used to contact the wiki
- administrator. By default, "wikiad...@$wgservername".
+ administrator. By default, "wikiad...@servername".
* $wgPasswordSender: The e-mail address to use when sending password e-mails.
- By default, "MediaWiki Mail <apa...@$wgservername>".
+ By default, "MediaWiki Mail <apa...@servername>".
+ (with ServerName guessed from the http request)
* $wgSMTP: Can be configured to use SMTP for mail sending instead of PHP
mail().
Modified: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php 2010-09-29 15:22:47 UTC (rev
73949)
+++ trunk/phase3/includes/DefaultSettings.php 2010-09-29 15:47:56 UTC (rev
73950)
@@ -56,23 +56,23 @@
/** @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,15 +968,17 @@
/**
* 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 <apache@' . $wgServerName . '>';
+$wgPasswordSender = 'MediaWiki Mail <apache@' . $serverName . '>';
+unset($serverName); # Don't leak local variables to global scope
+
/**
* Dummy address which should be accepted during mail send action.
* It might be necessary to adapt the address or to set it equal
Modified: trunk/phase3/includes/parser/Parser.php
===================================================================
--- trunk/phase3/includes/parser/Parser.php 2010-09-29 15:22:47 UTC (rev
73949)
+++ trunk/phase3/includes/parser/Parser.php 2010-09-29 15:47:56 UTC (rev
73950)
@@ -2495,7 +2495,7 @@
* @private
*/
function getVariableValue( $index, $frame=false ) {
- global $wgContLang, $wgSitename, $wgServer, $wgServerName;
+ global $wgContLang, $wgSitename, $wgServer;
global $wgArticlePath, $wgScriptPath, $wgStylePath;
/**
@@ -2777,7 +2777,10 @@
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':
Modified: trunk/phase3/maintenance/tests/parser/parserTest.inc
===================================================================
--- trunk/phase3/maintenance/tests/parser/parserTest.inc 2010-09-29
15:22:47 UTC (rev 73949)
+++ trunk/phase3/maintenance/tests/parser/parserTest.inc 2010-09-29
15:47:56 UTC (rev 73950)
@@ -532,7 +532,7 @@
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 @@
'wgStylePath' => '/skins',
'wgStyleSheetPath' => '/skins',
'wgSitename' => 'MediaWiki',
- 'wgServerName' => 'Britney-Spears',
'wgLanguageCode' => $lang,
'wgDBprefix' => $wgDBtype != 'oracle' ? 'parsertest_' :
'pt_',
'wgRawHtml' => isset( $opts['rawhtml'] ),
Modified: trunk/phase3/maintenance/tests/parser/parserTests.txt
===================================================================
--- trunk/phase3/maintenance/tests/parser/parserTests.txt 2010-09-29
15:22:47 UTC (rev 73949)
+++ trunk/phase3/maintenance/tests/parser/parserTests.txt 2010-09-29
15:47:56 UTC (rev 73950)
@@ -2090,7 +2090,7 @@
!! input
{{SERVER}}
!! result
-<p><a href="http://localhost" class="external free"
rel="nofollow">http://localhost</a>
+<p><a href="http://Britney-Spears" class="external free"
rel="nofollow">http://Britney-Spears</a>
</p>
!! end
Modified: trunk/phase3/maintenance/tests/phpunit/includes/api/ApiTest.php
===================================================================
--- trunk/phase3/maintenance/tests/phpunit/includes/api/ApiTest.php
2010-09-29 15:22:47 UTC (rev 73949)
+++ trunk/phase3/maintenance/tests/phpunit/includes/api/ApiTest.php
2010-09-29 15:47:56 UTC (rev 73950)
@@ -54,11 +54,10 @@
}
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 @@
}
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 @@
}
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 @@
}
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 @@
}
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 @@
$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 @@
*/
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" );
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs