From 4555d1b482816730b25e6956444ca6a3155dd2cd Mon Sep 17 00:00:00 2001 From: Florian Date: Tue, 17 Nov 2015 19:43:47 +0100 Subject: [PATCH] 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 --- includes/Setup.php | 8 +++----- includes/context/RequestContext.php | 9 +++++++-- 2 files changed, 10 insertions(+), 7 deletions(-) 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; -- 2.20.1