X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/bilan.php?a=blobdiff_plain;f=includes%2Fcontext%2FRequestContext.php;h=36c644aa082b9696b31af76054fc6382e70b1e92;hb=174f34a86de3162bc673fd3bc6bed815cccf0edc;hp=42a2aee6423b3a55ba40919b2ce74fe7cfe1cd75;hpb=c6f066b88c2ab775f2ecccc7555bfc7a5445bd7c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/context/RequestContext.php b/includes/context/RequestContext.php index 42a2aee642..36c644aa08 100644 --- a/includes/context/RequestContext.php +++ b/includes/context/RequestContext.php @@ -22,6 +22,8 @@ * @file */ +use MediaWiki\Logger\LoggerFactory; + /** * Group all the pieces relevant to the context of a request into one instance */ @@ -66,6 +68,11 @@ class RequestContext implements IContextSource, MutableContext { */ private $stats; + /** + * @var Timing + */ + private $timing; + /** * @var Config */ @@ -116,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; @@ -130,15 +142,26 @@ class RequestContext implements IContextSource, MutableContext { */ 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; } + /** + * Get the timing object + * + * @return Timing + */ + public function getTiming() { + if ( $this->timing === null ) { + $this->timing = new Timing( array( + 'logger' => LoggerFactory::getInstance( 'Timing' ) + ) ); + } + return $this->timing; + } + /** * Set the Title object *