X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/bilan.php?a=blobdiff_plain;f=includes%2Fcontext%2FRequestContext.php;h=93adde1fee87cbea5c9a2179465eef4a0387df30;hb=174f34a86de3162bc673fd3bc6bed815cccf0edc;hp=99c1a062a6c28c3009e10f2bbfea3fdd97a2a910;hpb=8b703a7fa00a388cdee36bdfd2f444c72a6b6e50;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/context/RequestContext.php b/includes/context/RequestContext.php index 99c1a062a6..36c644aa08 100644 --- a/includes/context/RequestContext.php +++ b/includes/context/RequestContext.php @@ -22,10 +22,12 @@ * @file */ +use MediaWiki\Logger\LoggerFactory; + /** * Group all the pieces relevant to the context of a request into one instance */ -class RequestContext implements IContextSource { +class RequestContext implements IContextSource, MutableContext { /** * @var WebRequest */ @@ -62,10 +64,15 @@ class RequestContext implements IContextSource { private $skin; /** - * @var StatsdDataFactory + * @var \Liuggio\StatsdClient\Factory\StatsdDataFactory */ private $stats; + /** + * @var Timing + */ + private $timing; + /** * @var Config */ @@ -116,8 +123,13 @@ class RequestContext implements IContextSource { */ 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 { */ 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 * @@ -159,7 +182,10 @@ class RequestContext implements IContextSource { if ( $this->title === null ) { global $wgTitle; # fallback to $wg till we can improve this $this->title = $wgTitle; - wfDebugLog( 'GlobalTitleFail', __METHOD__ . ' called by ' . wfGetAllCallers( 5 ) . ' with no title set.' ); + wfDebugLog( + 'GlobalTitleFail', + __METHOD__ . ' called by ' . wfGetAllCallers( 5 ) . ' with no title set.' + ); } return $this->title; @@ -427,6 +453,7 @@ class RequestContext implements IContextSource { * Get a Message object with context set * Parameters are the same as wfMessage() * + * @param mixed ... * @return Message */ public function msg() {