RequestContext: Load the request object for getRequest on first call
authorFlorian <florian.schmidt.stargatewissen@gmail.com>
Tue, 17 Nov 2015 18:43:47 +0000 (19:43 +0100)
committerLegoktm <legoktm.wikipedia@gmail.com>
Wed, 6 Jan 2016 19:02:04 +0000 (19:02 +0000)
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
includes/context/RequestContext.php

index bd20ac3..f72f5ca 100644 (file)
@@ -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 ) {
index 4f8e65d..8c13e97 100644 (file)
@@ -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;