X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fcontext%2FRequestContext.php;h=ecd274b0dbb18afe6505c09fd2fafd6b655d9ace;hb=8dfae8aecebbce32861aaf74133baeaee24e56e0;hp=8056b4d163d057c189882b26aa73e66e2f5ca862;hpb=f132746d2882a8383cb6288325aae048b2b996e3;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/context/RequestContext.php b/includes/context/RequestContext.php index 8056b4d163..ecd274b0db 100644 --- a/includes/context/RequestContext.php +++ b/includes/context/RequestContext.php @@ -22,7 +22,10 @@ * @file */ +use Liuggio\StatsdClient\Factory\StatsdDataFactory; use MediaWiki\Logger\LoggerFactory; +use MediaWiki\MediaWikiServices; +use Wikimedia\ScopedCallback; /** * Group all the pieces relevant to the context of a request into one instance @@ -63,11 +66,6 @@ class RequestContext implements IContextSource, MutableContext { */ private $skin; - /** - * @var \Liuggio\StatsdClient\Factory\StatsdDataFactory - */ - private $stats; - /** * @var Timing */ @@ -101,7 +99,7 @@ class RequestContext implements IContextSource, MutableContext { if ( $this->config === null ) { // @todo In the future, we could move this to WebStart.php so // the Config object is ready for when initialization happens - $this->config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' ); + $this->config = MediaWikiServices::getInstance()->getMainConfig(); } return $this->config; @@ -126,7 +124,7 @@ class RequestContext implements IContextSource, MutableContext { global $wgCommandLineMode; // create the WebRequest object on the fly if ( $wgCommandLineMode ) { - $this->request = new FauxRequest( array() ); + $this->request = new FauxRequest( [] ); } else { $this->request = new WebRequest(); } @@ -138,14 +136,12 @@ class RequestContext implements IContextSource, MutableContext { /** * Get the Stats object * - * @return BufferingStatsdDataFactory + * @deprecated since 1.27 use a StatsdDataFactory from MediaWikiServices (preferably injected) + * + * @return StatsdDataFactory */ public function getStats() { - if ( $this->stats === null ) { - $prefix = rtrim( $this->getConfig()->get( 'StatsdMetricPrefix' ), '.' ); - $this->stats = new BufferingStatsdDataFactory( $prefix ); - } - return $this->stats; + return MediaWikiServices::getInstance()->getStatsdDataFactory(); } /** @@ -155,9 +151,9 @@ class RequestContext implements IContextSource, MutableContext { */ public function getTiming() { if ( $this->timing === null ) { - $this->timing = new Timing( array( + $this->timing = new Timing( [ 'logger' => LoggerFactory::getInstance( 'Timing' ) - ) ); + ] ); } return $this->timing; } @@ -165,9 +161,9 @@ class RequestContext implements IContextSource, MutableContext { /** * Set the Title object * - * @param Title $title + * @param Title|null $title */ - public function setTitle( Title $title ) { + public function setTitle( Title $title = null ) { $this->title = $title; // Erase the WikiPage so a new one with the new title gets created. $this->wikipage = null; @@ -369,7 +365,7 @@ class RequestContext implements IContextSource, MutableContext { } $code = self::sanitizeLangCode( $code ); - Hooks::run( 'UserGetLanguageObject', array( $user, &$code, $this ) ); + Hooks::run( 'UserGetLanguageObject', [ $user, &$code, $this ] ); if ( $code === $this->getConfig()->get( 'LanguageCode' ) ) { $this->lang = $wgContLang; @@ -407,7 +403,7 @@ class RequestContext implements IContextSource, MutableContext { public function getSkin() { if ( $this->skin === null ) { $skin = null; - Hooks::run( 'RequestContextCreateSkin', array( $this, &$skin ) ); + Hooks::run( 'RequestContextCreateSkin', [ $this, &$skin ] ); $factory = SkinFactory::getDefaultInstance(); // If the hook worked try to set a skin from it @@ -496,7 +492,7 @@ class RequestContext implements IContextSource, MutableContext { * Resets singleton returned by getMain(). Should be called only from unit tests. */ public static function resetMain() { - if ( !defined( 'MW_PHPUNIT_TEST' ) ) { + if ( !( defined( 'MW_PHPUNIT_TEST' ) || defined( 'MW_PARSER_TEST' ) ) ) { throw new MWException( __METHOD__ . '() should be called only from unit tests!' ); } self::$instance = null; @@ -511,12 +507,12 @@ class RequestContext implements IContextSource, MutableContext { */ public function exportSession() { $session = MediaWiki\Session\SessionManager::getGlobalSession(); - return array( + return [ 'ip' => $this->getRequest()->getIP(), 'headers' => $this->getRequest()->getAllHeaders(), 'sessionId' => $session->isPersistent() ? $session->getId() : '', 'userId' => $this->getUser()->getId() - ); + ]; } /** @@ -571,7 +567,7 @@ class RequestContext implements IContextSource, MutableContext { if ( MediaWiki\Session\PHPSessionHandler::isEnabled() ) { session_write_close(); // persist session_id( '' ); // detach - $_SESSION = array(); // clear in-memory array + $_SESSION = []; // clear in-memory array } // Get new session, if applicable @@ -584,7 +580,7 @@ class RequestContext implements IContextSource, MutableContext { // Remove any user IP or agent information, and attach the request // with the new session. - $context->setRequest( new FauxRequest( array(), false, $session ) ); + $context->setRequest( new FauxRequest( [], false, $session ) ); $wgRequest = $context->getRequest(); // b/c // Now that all private information is detached from the user, it should @@ -597,7 +593,7 @@ class RequestContext implements IContextSource, MutableContext { session_id( $session->getId() ); MediaWiki\quietCall( 'session_start' ); } - $request = new FauxRequest( array(), false, $session ); + $request = new FauxRequest( [], false, $session ); $request->setIP( $params['ip'] ); foreach ( $params['headers'] as $name => $value ) { $request->setHeader( $name, $value ); @@ -639,7 +635,7 @@ class RequestContext implements IContextSource, MutableContext { * @param WebRequest|array $request A WebRequest or data to use for a FauxRequest * @return RequestContext */ - public static function newExtraneousContext( Title $title, $request = array() ) { + public static function newExtraneousContext( Title $title, $request = [] ) { $context = new self; $context->setTitle( $title ); if ( $request instanceof WebRequest ) {