setting servername with an IPv6 request must ensure we have both brackets
authorAntoine Musso <hashar@users.mediawiki.org>
Sun, 13 Mar 2011 18:31:00 +0000 (18:31 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Sun, 13 Mar 2011 18:31:00 +0000 (18:31 +0000)
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

includes/DefaultSettings.php

index 64f770d..a7abbaa 100644 (file)
@@ -54,7 +54,12 @@ $wgSitename         = 'MediaWiki';
 $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'];