Add $wgServerName

This partially reverts r73950 which removed $wgServerName on the ground that it
was only used for {{SERVERNAME}}. When it was pointed out that $wgServerName was
also used by several extensions, the response was not to restore the variable, but
to proceed to remove it from extensions as well.

It is a useful variable to have, as the discussion on Id819246a9 makes clear
(see Tim's comment on PS12 and Timo's reply). So let's reintroduce it, and expose
it in mw.config and ApiQuerySiteInfo as well.

Change-Id: I40a6fd427d38c64c628f70a2f407b145443ea204
This commit is contained in:
Ori Livneh 2014-05-06 02:31:24 -07:00 committed by Timo Tijhof
parent 678b4d5547
commit 72c0ce43a8
8 changed files with 47 additions and 14 deletions

View file

@ -9,6 +9,8 @@ MediaWiki 1.24 is an alpha-quality branch and is not recommended for use in
production.
=== Configuration changes in 1.24 ===
* The server's canonical hostname is available as $wgServerName, which is
exposed in both mw.config and ApiQuerySiteInfo.
=== New features in 1.24 ===
* Added a new hook, "WhatLinksHereProps", to allow extensions to annotate

View file

@ -104,6 +104,13 @@ $wgServer = WebRequest::detectServer();
*/
$wgCanonicalServer = false;
/**
* Server name. This is automatically computed by parsing the bare
* hostname out of $wgCanonicalServer. It should not be customized.
* @since 1.24
*/
$wgServerName = false;
/************************************************************************//**
* @name Script path settings
* @{
@ -1304,21 +1311,22 @@ $wgDjvuOutputExtension = 'jpg';
* @{
*/
$serverName = substr( $wgServer, strrpos( $wgServer, '/' ) + 1 );
/**
* Site admin email address.
*
* Defaults to "wikiadmin@{$wgServerName}".
*/
$wgEmergencyContact = 'wikiadmin@' . $serverName;
$wgEmergencyContact = false;
/**
* Password reminder email address.
*
* The address we should use as sender when a user is requesting his password.
*
* Defaults to "apache@{$wgServerName}".
*/
$wgPasswordSender = 'apache@' . $serverName;
unset( $serverName ); # Don't leak local variables to global scope
$wgPasswordSender = false;
/**
* Password reminder name

View file

@ -43,6 +43,7 @@ if ( !isset( $wgVersion ) ) {
}
// Set various default paths sensibly...
if ( $wgScript === false ) {
$wgScript = "$wgScriptPath/index$wgScriptExtension";
}
@ -420,6 +421,29 @@ require_once "$IP/includes/normal/UtfNormalDefines.php";
wfProfileOut( $fname . '-includes' );
wfProfileIn( $fname . '-defaults2' );
if ( $wgCanonicalServer === false ) {
$wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP );
}
// Set server name
$serverParts = wfParseUrl( $wgCanonicalServer );
if ( $wgServerName !== false ) {
wfWarn( '$wgServerName should be derived from $wgCanonicalServer, not customized. Overwriting $wgServerName.' );
}
$wgServerName = $serverParts['host'];
unset( $serverParts );
// Set defaults for configuration variables
// that are derived from the server name by default
if ( $wgEmergencyContact === false ) {
$wgEmergencyContact = 'wikiadmin@' . $wgServerName;
}
if ( $wgPasswordSender === false ) {
$wgPasswordSender = 'apache@' . $wgServerName;
}
if ( $wgSecureLogin && substr( $wgServer, 0, 2 ) !== '//' ) {
$wgSecureLogin = false;
wfWarn( 'Secure login was enabled on a server that only supports HTTP or HTTPS. Disabling secure login.' );
@ -433,10 +457,6 @@ if ( $wgTmpDirectory === false ) {
wfProfileOut( $fname . '-tempDir' );
}
if ( $wgCanonicalServer === false ) {
$wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP );
}
// $wgHTCPMulticastRouting got renamed to $wgHTCPRouting in MediaWiki 1.22
// ensure back compatibility.
if ( !$wgHTCPRouting && $wgHTCPMulticastRouting ) {

View file

@ -239,6 +239,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
$data['script'] = $GLOBALS['wgScript'];
$data['variantarticlepath'] = $GLOBALS['wgVariantArticlePath'];
$data['server'] = $GLOBALS['wgServer'];
$data['servername'] = $GLOBALS['wgServerName'];
$data['wikiid'] = wfWikiID();
$data['time'] = wfTimestamp( TS_ISO_8601, time() );

View file

@ -2731,7 +2731,7 @@ class Parser {
* @return string
*/
function getVariableValue( $index, $frame = false ) {
global $wgContLang, $wgSitename, $wgServer;
global $wgContLang, $wgSitename, $wgServer, $wgServerName;
global $wgArticlePath, $wgScriptPath, $wgStylePath;
if ( is_null( $this->mTitle ) ) {
@ -3032,8 +3032,7 @@ class Parser {
case 'server':
return $wgServer;
case 'servername':
$serverParts = wfParseUrl( $wgServer );
return $serverParts && isset( $serverParts['host'] ) ? $serverParts['host'] : $wgServer;
return $wgServerName;
case 'scriptpath':
return $wgScriptPath;
case 'stylepath':

View file

@ -44,8 +44,8 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
}
global $wgLoadScript, $wgScript, $wgStylePath, $wgScriptExtension,
$wgArticlePath, $wgScriptPath, $wgServer, $wgContLang,
$wgVariantArticlePath, $wgActionPaths, $wgVersion,
$wgArticlePath, $wgScriptPath, $wgServer, $wgServerName,
$wgContLang, $wgVariantArticlePath, $wgActionPaths, $wgVersion,
$wgEnableAPI, $wgEnableWriteAPI, $wgDBname,
$wgSitename, $wgFileExtensions, $wgExtensionAssetsPath,
$wgCookiePrefix, $wgResourceLoaderMaxQueryLength,
@ -85,6 +85,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
// becoming [] instead of {} in JS (bug 34604)
'wgActionPaths' => (object)$wgActionPaths,
'wgServer' => $wgServer,
'wgServerName' => $wgServerName,
'wgUserLanguage' => $context->getLanguage(),
'wgContentLanguage' => $wgContLang->getCode(),
'wgVersion' => $wgVersion,

View file

@ -763,6 +763,7 @@ class ParserTest {
$settings = array(
'wgServer' => 'http://example.org',
'wgServerName' => 'example.org',
'wgScript' => '/index.php',
'wgScriptPath' => '/',
'wgArticlePath' => '/wiki/$1',

View file

@ -65,6 +65,7 @@ class NewParserTest extends MediaWikiTestCase {
$tmpGlobals['wgContLang'] = Language::factory( 'en' );
$tmpGlobals['wgSitename'] = 'MediaWiki';
$tmpGlobals['wgServer'] = 'http://example.org';
$tmpGlobals['wgServerName'] = 'example.org';
$tmpGlobals['wgScript'] = '/index.php';
$tmpGlobals['wgScriptPath'] = '/';
$tmpGlobals['wgArticlePath'] = '/wiki/$1';