From: Florian Date: Tue, 17 Nov 2015 18:43:47 +0000 (+0100) Subject: RequestContext: Load the request object for getRequest on first call X-Git-Tag: 1.31.0-rc.0~8429^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22sites_tous%22%29%20.%20%22?a=commitdiff_plain;h=4555d1b482816730b25e6956444ca6a3155dd2cd;p=lhc%2Fweb%2Fwiklou.git RequestContext: Load the request object for getRequest on first call Instead of relying on the global $wgRequest, which probably isn't initialized so far, create the request object when RequestContext::getRequest() is called the first time. Change-Id: I6115ba44e474619d02d456a103758fe73ed298e0 --- diff --git a/includes/Setup.php b/includes/Setup.php index bd20ac3579..f72f5ca8db 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -614,15 +614,13 @@ if ( !$wgDBerrorLogTZ ) { $wgDBerrorLogTZ = $wgLocaltimezone; } +// initialize the request object in $wgRequest +$wgRequest = RequestContext::getMain()->getRequest(); // BackCompat + // Useful debug output if ( $wgCommandLineMode ) { - $wgRequest = new FauxRequest( array() ); - wfDebug( "\n\nStart command line script $self\n" ); } else { - // Can't stub this one, it sets up $_GET and $_REQUEST in its constructor - $wgRequest = new WebRequest; - $debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n"; if ( $wgDebugPrintHttpHeaders ) { diff --git a/includes/context/RequestContext.php b/includes/context/RequestContext.php index 4f8e65d01b..8c13e97c71 100644 --- a/includes/context/RequestContext.php +++ b/includes/context/RequestContext.php @@ -121,8 +121,13 @@ class RequestContext implements IContextSource, MutableContext { */ public function getRequest() { if ( $this->request === null ) { - global $wgRequest; # fallback to $wg till we can improve this - $this->request = $wgRequest; + global $wgCommandLineMode; + // create the WebRequest object on the fly + if ( $wgCommandLineMode ) { + $this->request = new FauxRequest( array() ); + } else { + $this->request = new WebRequest(); + } } return $this->request;