setting to completely override server hostname
authorAntoine Musso <hashar@free.fr>
Fri, 11 May 2012 18:13:09 +0000 (11:13 -0700)
committerAntoine Musso <hashar@free.fr>
Tue, 26 Jun 2012 20:27:02 +0000 (22:27 +0200)
Labs has instances hostnames forged in sequences which make them not
that much useful for human readable output. Labs does publish a
meaningful instance name as an env variable though, so we could use it
to get better output.

This patch introduce $wgOverrideHostname (default false) which when
set will override the hostname returned by wfHostname().

Change-Id: Ibdba007cc4025fa0b0ebef39b5669c32852a95a7

includes/DefaultSettings.php
includes/GlobalFunctions.php

index 6e59a86..35ae6bd 100644 (file)
@@ -4186,6 +4186,13 @@ $wgLogExceptionBacktrace = true;
  */
 $wgShowHostnames = false;
 
+/**
+ * Override server hostname detection with a hardcoded value.
+ * Should be a string, default false.
+ * @since 1.20
+ */
+$wgOverrideHostname = false;
+
 /**
  * If set to true MediaWiki will throw notices for some possible error
  * conditions and for deprecated functions.
index ba9bf74..7e75958 100644 (file)
@@ -1758,6 +1758,15 @@ function wfDebugDieBacktrace( $msg = '' ) {
 function wfHostname() {
        static $host;
        if ( is_null( $host ) ) {
+
+               # Hostname overriding
+               global $wgOverrideHostname;
+               if( $wgOverrideHostname !== false ) {
+                       # Set static and skip any detection
+                       $host = $wgOverrideHostname;
+                       return $host;
+               }
+
                if ( function_exists( 'posix_uname' ) ) {
                        // This function not present on Windows
                        $uname = posix_uname();