Replace deprecated Context::getStats() with MWServices::getStatsdDataFactory()
authorWMDE-Fisch <christoph.jauera@wikimedia.de>
Fri, 17 Mar 2017 10:57:37 +0000 (11:57 +0100)
committerWMDE-Fisch <christoph.jauera@wikimedia.de>
Fri, 17 Mar 2017 11:07:03 +0000 (12:07 +0100)
Change-Id: I1756f69ca2ebd301a5049bf758d1a87c37771fe6

includes/api/ApiMain.php
includes/context/ContextSource.php
includes/deferred/SiteStatsUpdate.php
includes/diff/DifferenceEngine.php
includes/filerepo/file/File.php
includes/jobqueue/JobQueue.php
includes/page/Article.php
includes/profiler/output/ProfilerOutputStats.php
includes/resourceloader/ResourceLoader.php
includes/resourceloader/ResourceLoaderModule.php
thumb.php

index 604fdf9..a1fac0c 100644 (file)
@@ -26,6 +26,7 @@
  */
 
 use MediaWiki\Logger\LoggerFactory;
+use MediaWiki\MediaWikiServices;
 use Wikimedia\Timestamp\TimestampException;
 
 /**
@@ -544,7 +545,7 @@ class ApiMain extends ApiBase {
                        $runTime = microtime( true ) - $t;
                        $this->logRequest( $runTime );
                        if ( $this->mModule->isWriteMode() && $this->getRequest()->wasPosted() ) {
-                               $this->getStats()->timing(
+                               MediaWikiServices::getInstance()->getStatsdDataFactory()->timing(
                                        'api.' . $this->mModule->getModuleName() . '.executeTiming', 1000 * $runTime
                                );
                        }
index ea5278f..135c9b2 100644 (file)
@@ -19,6 +19,7 @@
  * @file
  */
 use Liuggio\StatsdClient\Factory\StatsdDataFactory;
+use MediaWiki\MediaWikiServices;
 
 /**
  * The simplest way of implementing IContextSource is to hold a RequestContext as a
@@ -172,7 +173,7 @@ abstract class ContextSource implements IContextSource {
         * @return StatsdDataFactory
         */
        public function getStats() {
-               return $this->getContext()->getStats();
+               return MediaWikiServices::getInstance()->getStatsdDataFactory();
        }
 
        /**
index ab4a609..7426624 100644 (file)
@@ -17,6 +17,7 @@
  *
  * @file
  */
+use MediaWiki\MediaWikiServices;
 use Wikimedia\Assert\Assert;
 
 /**
@@ -169,7 +170,7 @@ class SiteStatsUpdate implements DeferrableUpdate, MergeableUpdate {
        }
 
        protected function doUpdateContextStats() {
-               $stats = RequestContext::getMain()->getStats();
+               $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
                foreach ( [ 'edits', 'articles', 'pages', 'users', 'images' ] as $type ) {
                        $delta = $this->$type;
                        if ( $delta !== 0 ) {
index 148e50c..b0ab244 100644 (file)
@@ -20,6 +20,7 @@
  * @file
  * @ingroup DifferenceEngine
  */
+use MediaWiki\MediaWikiServices;
 
 /** @deprecated use class constant instead */
 define( 'MW_DIFF_VERSION', '1.11a' );
@@ -852,7 +853,7 @@ class DifferenceEngine extends ContextSource {
                        $result = $this->textDiff( $otext, $ntext );
 
                        $time = intval( ( microtime( true ) - $time ) * 1000 );
-                       $this->getStats()->timing( 'diff_time', $time );
+                       MediaWikiServices::getInstance()->getStatsdDataFactory()->timing( 'diff_time', $time );
                        // Log requests slower than 99th percentile
                        if ( $time > 100 && $this->mOldPage && $this->mNewPage ) {
                                wfDebugLog( 'diff',
index f7e85a8..e367812 100644 (file)
@@ -5,6 +5,7 @@
  *
  * Represents files in a repository.
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * Base code for files.
@@ -436,7 +437,7 @@ abstract class File implements IDBAccessObject {
                        $this->fsFile = $this->repo->getLocalReference( $this->getPath() );
 
                        $statTiming = microtime( true ) - $starttime;
-                       RequestContext::getMain()->getStats()->timing(
+                       MediaWikiServices::getInstance()->getStatsdDataFactory()->timing(
                                'media.thumbnail.generate.fetchoriginal', 1000 * $statTiming );
 
                        if ( !$this->fsFile ) {
@@ -1117,7 +1118,7 @@ abstract class File implements IDBAccessObject {
        public function generateAndSaveThumb( $tmpFile, $transformParams, $flags ) {
                global $wgIgnoreImageErrors;
 
-               $stats = RequestContext::getMain()->getStats();
+               $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
 
                $handler = $this->getHandler();
 
@@ -1227,7 +1228,7 @@ abstract class File implements IDBAccessObject {
                // this object exists
                $tmpFile->bind( $this );
 
-               RequestContext::getMain()->getStats()->timing(
+               MediaWikiServices::getInstance()->getStatsdDataFactory()->timing(
                        'media.thumbnail.generate.bucket', 1000 * $buckettime );
 
                return true;
index 020a684..9701dd9 100644 (file)
@@ -21,6 +21,7 @@
  * @defgroup JobQueue JobQueue
  * @author Aaron Schulz
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * Class to handle enqueueing and running of background jobs
@@ -709,7 +710,7 @@ abstract class JobQueue {
        public static function incrStats( $key, $type, $delta = 1 ) {
                static $stats;
                if ( !$stats ) {
-                       $stats = RequestContext::getMain()->getStats();
+                       $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
                }
                $stats->updateCount( "jobqueue.{$key}.all", $delta );
                $stats->updateCount( "jobqueue.{$key}.{$type}", $delta );
index e7a906d..cb97126 100644 (file)
@@ -19,6 +19,7 @@
  *
  * @file
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * Class for viewing MediaWiki article and history.
@@ -494,7 +495,7 @@ class Article implements Page {
                $useParserCache = $this->mPage->shouldCheckParserCache( $parserOptions, $oldid );
                wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
                if ( $user->getStubThreshold() ) {
-                       $this->getContext()->getStats()->increment( 'pcache_miss_stub' );
+                       MediaWikiServices::getInstance()->getStatsdDataFactory()->increment( 'pcache_miss_stub' );
                }
 
                $this->showRedirectedFromHeader();
index 52aa54a..bb86551 100644 (file)
@@ -21,6 +21,7 @@
  * @file
  * @ingroup Profiler
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * ProfilerOutput class that flushes profiling data to the profiling
@@ -38,7 +39,7 @@ class ProfilerOutputStats extends ProfilerOutput {
         */
        public function log( array $stats ) {
                $prefix = isset( $this->params['prefix'] ) ? $this->params['prefix'] : '';
-               $contextStats = $this->collector->getContext()->getStats();
+               $contextStats = MediaWikiServices::getInstance()->getStatsdDataFactory();
 
                foreach ( $stats as $stat ) {
                        $key = "{$prefix}.{$stat['name']}";
index 717fb45..e72eaf2 100644 (file)
@@ -185,7 +185,7 @@ class ResourceLoader implements LoggerAwareInterface {
                        return self::applyFilter( $filter, $data );
                }
 
-               $stats = RequestContext::getMain()->getStats();
+               $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
                $cache = ObjectCache::getLocalServerInstance( CACHE_ANYTHING );
 
                $key = $cache->makeGlobalKey(
index a2b4b1d..b122fe2 100644 (file)
@@ -624,7 +624,7 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
         */
        final protected function buildContent( ResourceLoaderContext $context ) {
                $rl = $context->getResourceLoader();
-               $stats = RequestContext::getMain()->getStats();
+               $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
                $statStart = microtime( true );
 
                // Only include properties that are relevant to this context (e.g. only=scripts)
index de201b9..d97f8e8 100644 (file)
--- a/thumb.php
+++ b/thumb.php
@@ -22,6 +22,7 @@
  */
 
 use MediaWiki\Logger\LoggerFactory;
+use MediaWiki\MediaWikiServices;
 
 define( 'MW_NO_OUTPUT_COMPRESSION', 1 );
 require __DIR__ . '/includes/WebStart.php';
@@ -317,7 +318,9 @@ function wfStreamThumb( array $params ) {
                $streamtime = microtime( true ) - $starttime;
 
                if ( $status->isOK() ) {
-                       RequestContext::getMain()->getStats()->timing( 'media.thumbnail.stream', $streamtime );
+                       MediaWikiServices::getInstance()->getStatsdDataFactory()->timing(
+                               'media.thumbnail.stream', $streamtime
+                       );
                } else {
                        wfThumbError( 500, 'Could not stream the file', null, [ 'file' => $thumbName,
                                'path' => $thumbPath, 'error' => $status->getWikiText( false, false, 'en' ) ] );