Merge "RequestContext: Load the request object for getRequest on first call"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 6 Jan 2016 19:10:15 +0000 (19:10 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 6 Jan 2016 19:10:15 +0000 (19:10 +0000)
includes/Setup.php
includes/context/RequestContext.php

index c863722..f6c546f 100644 (file)
@@ -606,15 +606,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 9b6e1f3..36c644a 100644 (file)
@@ -123,8 +123,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;