Last modified: 2013-10-23 18:17:33 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T34823, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 32823 - Undefined index notices when $wgServer is empty string (introduced with 1.18)
Undefined index notices when $wgServer is empty string (introduced with 1.18)
Status: RESOLVED WONTFIX
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
1.18.x
All All
: Normal normal (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-12-06 07:22 UTC by Ralf Krüdewagen
Modified: 2013-10-23 18:17 UTC (History)
4 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Ralf Krüdewagen 2011-12-06 07:22:03 UTC
I have set $wgServer = ''; in order to run my wiki behind an Apache reverse proxy and in order to support port forwarding when accessing the wiki via SSH on another port than 80 (e.g. local port 8000 forwarded to 80). This way I avoid sending an absolute URL back to the client for certain actions (like login/logout, search).
So far that works since years even though the Location header sent to the browser is relative (might violate the standard, but works with major browsers).

But since 1.18 I get PHP notices when $wgServer is set to such an empty string:

###########
PHP Notice:  Undefined index: scheme in /srv/www/htdocs/mediawiki-1.18.0/includes/GlobalFunctions.php on line 572, referer: http://xxx
PHP Notice:  Undefined index: scheme in /srv/www/htdocs/mediawiki-1.18.0/includes/GlobalFunctions.php on line 574, referer: http://xxx
###########

This is due to new code for handling the URL. Therefore, I would like to ask adding isset() checks to GlobalFunctions.php before $bits['scheme'] is accessed.
Comment 1 Brion Vibber 2011-12-06 18:08:17 UTC
MediaWiki really, really doesn't expect $wgServer to be empty... not sure what other problems might crop up.

This particular part looks like it might be fixed by merging r94352 (though whether that'd break other things after I don't know).
Comment 2 Ralf Krüdewagen 2011-12-07 07:52:33 UTC
Well, I understand that $wgServer to be empty is not typical and should hopefully never happen. But that was the only way to support my corporate wiki in a quite complex network scenario.

Maybe there is another solution by magic configuration, please let me explain:

1) My wiki must be accessed from two different interfaces. Access via interface 1 is via a reverse proxy (Apache). Interface 2 is via direct connected hosts on the same LAN (either by FQDN according to local hosts file or IP address). Some people also access the wiki on interface 2 by port forwarding using something like "ssh -L 8000:127.0.0.1:80".

2) Due to the reverse proxy I can't keep $wgServer auto-detected, since that results in sending a wrong (internal) URL back to the clients on interface 1. Therefore, I need to set $wgServer manually.

3) If I set $wgServer to either 'http://myproxydomain.de' or '//myproxydomain.de' I get the following results:

a) Access via reverse proxy on interface 1 works, since myproxydomain.de is fully routed from in front of the reverse proxy.

b) Access via interface 2 (LAN) works if I add myproxydomain.de to local hosts file (no DNS). Access on IP address (http://<IP>) doesn't work due to redirects (see c), but that's ok for me.

c) But if I access via interface 2 by SSH port forwarding, e.g. as http://myproxydomain.de:8000, I am often redirected to a "HTTP Location" that does NOT contain port 8000, so the client fails to load the page. This happens for example after login or when I just access http://myproxydomain.de:8000/wiki/index.php which redirects to http://myproxydomain.de/wiki/index.php/Main_Page. 

Strange is, that when I keep $wgServer auto-detected these redirects contain the port 8000. So, scenario 3c works if $wgServer is auto-detected, but then access via interface 1 (reverse proxy) doesn't work.

4) If I set $wgServer to be empty all above scenarios work (even access on pure IP address URL), since the HTTP Location is always relative.

Question: How can I set $wgServer (or other variables) to solve problem 3c ?
Comment 3 Antoine "hashar" Musso (WMF) 2011-12-07 11:45:17 UTC
Whenever the request comes from localhost (i.e. it comes from SSH), you could set wgServer to auto detect, that should detect the 8000 port.
Leave wgServer hardcoded in other cases (i.e. to 'http://myproxydomain.de/ ).
Comment 4 Ralf Krüdewagen 2011-12-07 11:53:47 UTC
(In reply to comment #3)
Yes, of course. But I need to support both scenarios at the same time. Or can $wgServer be set dynamically dependent on which interface the request comes in?
Comment 5 Antoine "hashar" Musso (WMF) 2011-12-07 13:54:40 UTC
You can look at the remote client address with $_SERVER['REMOTE_ADDR'] , something like:

if( preg_match( $_SERVER['REMOTE_ADDR'], '^192\.168\.0\.' ) {
 // local LAN clients

} else if ( $_SERVER['REMOTE_ADDR'] === '127.0.0.1' ) {
 // localhost!

} else {
  // external access?

}
Comment 6 Ralf Krüdewagen 2011-12-07 14:08:52 UTC
(In reply to comment #5)
> You can look at the remote client address with $_SERVER['REMOTE_ADDR'] ,
> something like:
> 
> if( preg_match( $_SERVER['REMOTE_ADDR'], '^192\.168\.0\.' ) {
>  // local LAN clients
> 
> } else if ( $_SERVER['REMOTE_ADDR'] === '127.0.0.1' ) {
>  // localhost!
> 
> } else {
>   // external access?
> 
> }

Ok. Good idea. Then I would need to put that kind of code to LocalSettings.php and set $wgServer for each case differently. I'll give that a try. Thank you.
Comment 7 Mark A. Hershberger 2011-12-07 16:07:46 UTC
WONTFIXING this, but please do not let that stop any additional questions you have.
Comment 8 Ralf Krüdewagen 2011-12-08 07:56:34 UTC
Based on the suggestion from "hashar" I have fixed my config issue with the following code in LocalSettings.php:

#################
if (preg_match('/^10\.2\.175\./',$_SERVER['REMOTE_ADDR']))
    $wgServer = 'http://myproxydomain.de';
#################

The reverse proxy source address is within 10.2.175 range. So, if the client comes from that network $wgServer is set to the "external" URL (with fixed port). In all other cases the default is used (auto-detection) which works fine for all other scenarios (incl. port forwarding).

Thanks again for that hint (which was quite obvious).
Comment 9 Antoine "hashar" Musso (WMF) 2011-12-08 09:06:29 UTC
Well done user66! Enjoy your MediaWiki installation.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links