From b598cf35ae5a3c1bd72c2fea9ac31e8af57e2599 Mon Sep 17 00:00:00 2001 From: Florian Schmidt Date: Mon, 17 Apr 2017 16:55:55 +0200 Subject: [PATCH] Remve usage of RequestContext::getStats() Bug: T156810 Change-Id: I571aa4afed577e10be8b417cf1a3bf134a130739 --- common/Hooks.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/common/Hooks.php b/common/Hooks.php index 83ee3ca4..31a9feda 100644 --- a/common/Hooks.php +++ b/common/Hooks.php @@ -218,7 +218,16 @@ class ScribuntoHooks { static $stats; if ( !$stats ) { - $stats = RequestContext::getMain()->getStats(); + // check, if MediaWikiServices exists and has a StatsdDataFactory service for + // backward-compatibility with MediaWiki 1.25+ + if ( + class_exists( 'MediaWiki\\MediaWikiServices' ) && + \MediaWiki\MediaWikiServices::getInstance()->hasService( 'StatsdDataFactory' ) + ) { + $stats = \MediaWiki\MediaWikiServices::getInstance()->getStatsdDataFactory(); + } else { + $stats = RequestContext::getMain()->getStats(); + } } $metricKey = sprintf( 'scribunto.traces.%s__%s__%s', wfWikiId(), $moduleName, $functionName );