Add $wgServerName
authorOri Livneh <ori@wikimedia.org>
Tue, 6 May 2014 09:31:24 +0000 (02:31 -0700)
committerTimo Tijhof <krinklemail@gmail.com>
Fri, 9 May 2014 09:53:56 +0000 (11:53 +0200)
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

RELEASE-NOTES-1.24
includes/DefaultSettings.php
includes/Setup.php
includes/api/ApiQuerySiteinfo.php
includes/parser/Parser.php
includes/resourceloader/ResourceLoaderStartUpModule.php
tests/parser/parserTest.inc
tests/phpunit/includes/parser/NewParserTest.php

index 5185517..536e6e6 100644 (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
index 2b8aec3..c6f48a7 100644 (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
index b155f90..18d1e33 100644 (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 ) {
index b0e9bd2..d3d61a4 100644 (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() );
 
index 7423006..29b14de 100644 (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':
index d0f0541..f9c5057 100644 (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,
index b4e903d..1875ac5 100644 (file)
@@ -763,6 +763,7 @@ class ParserTest {
 
                $settings = array(
                        'wgServer' => 'http://example.org',
+                       'wgServerName' => 'example.org',
                        'wgScript' => '/index.php',
                        'wgScriptPath' => '/',
                        'wgArticlePath' => '/wiki/$1',
index 66ed020..14bcac0 100644 (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';