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)
1  2 
includes/Setup.php
includes/context/RequestContext.php

diff --combined includes/Setup.php
@@@ -421,9 -421,11 +421,9 @@@ if ( is_array( $wgExtraNamespaces ) ) 
  // To determine the user language, use $wgLang->getCode()
  $wgContLanguageCode = $wgLanguageCode;
  
 -// Easy to forget to falsify $wgShowIPinHeader for static caches.
 -// If file cache or squid cache is on, just disable this (DWIMD).
 -// Do the same for $wgDebugToolbar.
 +// Easy to forget to falsify $wgDebugToolbar for static caches.
 +// If file cache or CDN cache is on, just disable this (DWIMD).
  if ( $wgUseFileCache || $wgUseSquid ) {
 -      $wgShowIPinHeader = false;
        $wgDebugToolbar = false;
  }
  
@@@ -472,6 -474,11 +472,6 @@@ if ( $wgCookieSecure === 'detect' ) 
        $wgCookieSecure = ( WebRequest::detectProtocol() === 'https' );
  }
  
 -// Back compatibility for $wgRateLimitLog deprecated with 1.23
 -if ( $wgRateLimitLog && !array_key_exists( 'ratelimit', $wgDebugLogGroups ) ) {
 -      $wgDebugLogGroups['ratelimit'] = $wgRateLimitLog;
 -}
 -
  if ( $wgProfileOnly ) {
        $wgDebugLogGroups['profileoutput'] = $wgDebugLogFile;
        $wgDebugLogFile = '';
@@@ -509,6 -516,7 +509,6 @@@ MWExceptionHandler::installHandler()
  
  require_once "$IP/includes/compat/normal/UtfNormalUtil.php";
  
 -
  $ps_validation = Profiler::instance()->scopedProfileIn( $fname . '-validation' );
  
  // T48998: Bail out early if $wgArticlePath is non-absolute
@@@ -606,15 -614,13 +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 ) {
@@@ -733,3 -739,4 +731,3 @@@ $wgFullyInitialised = true
  
  Profiler::instance()->scopedProfileOut( $ps_extensions );
  Profiler::instance()->scopedProfileOut( $ps_setup );
 -
@@@ -22,8 -22,6 +22,8 @@@
   * @file
   */
  
 +use MediaWiki\Logger\LoggerFactory;
 +
  /**
   * Group all the pieces relevant to the context of a request into one instance
   */
@@@ -123,8 -121,13 +123,13 @@@ class RequestContext implements IContex
         */
        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;
         */
        public function getStats() {
                if ( $this->stats === null ) {
 -                      $config = $this->getConfig();
 -                      $prefix = $config->get( 'StatsdMetricPrefix' )
 -                              ? rtrim( $config->get( 'StatsdMetricPrefix' ), '.' )
 -                              : 'MediaWiki';
 +                      $prefix = rtrim( $this->getConfig()->get( 'StatsdMetricPrefix' ), '.' );
                        $this->stats = new BufferingStatsdDataFactory( $prefix );
                }
                return $this->stats;
         */
        public function getTiming() {
                if ( $this->timing === null ) {
 -                      $this->timing = new Timing();
 +                      $this->timing = new Timing( array(
 +                              'logger' => LoggerFactory::getInstance( 'Timing' )
 +                      ) );
                }
                return $this->timing;
        }