On lighttpd 1.4.28, the SERVER_NAME CGI variable is truncated at the first
colon. This makes it return an incorrect value for SERVER_NAME when the user
make the request to an IPv6, it outputs something like [2001.
This patch make sure we have either both opening and closing brackets or no
brackets at all (hence the 'xor' boolean check).
+ipv6
$wgServer = '';
/** @cond file_level_code */
-if( isset( $_SERVER['SERVER_NAME'] ) ) {
+if( isset( $_SERVER['SERVER_NAME'] )
+ # additionially, for requests made directly to an IPv6 address we have
+ # to make sure the server enclose it in either [] or nothing at all
+ && (strpos($_SERVER['SERVER_NAME'], '[')
+ xor strpos( $_SERVER['SERVER_NAME'], ']'))
+ ) {
$serverName = $_SERVER['SERVER_NAME'];
} elseif( isset( $_SERVER['HOSTNAME'] ) ) {
$serverName = $_SERVER['HOSTNAME'];