Replace deprecated ObjectCache and CommentStore calls in filerepo
authorWMDE-Fisch <christoph.jauera@wikimedia.de>
Fri, 4 May 2018 13:39:33 +0000 (15:39 +0200)
committerWMDE-Fisch <christoph.jauera@wikimedia.de>
Mon, 7 May 2018 09:00:23 +0000 (11:00 +0200)
Change-Id: I0e863dc8e4bc6dac938a2ed437c2691aace19690

includes/filerepo/ForeignAPIRepo.php
includes/filerepo/LocalRepo.php
includes/filerepo/file/ArchivedFile.php
includes/filerepo/file/File.php
includes/filerepo/file/ForeignAPIFile.php
includes/filerepo/file/ForeignDBFile.php
includes/filerepo/file/LocalFile.php
includes/filerepo/file/OldLocalFile.php

index 06b21a8..cba21c8 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 use MediaWiki\Logger\LoggerFactory;
+use MediaWiki\MediaWikiServices;
 
 /**
  * A foreign repository with a remote MediaWiki with an API thingy
@@ -332,7 +333,7 @@ class ForeignAPIRepo extends FileRepo {
         * @return bool|string
         */
        function getThumbUrlFromCache( $name, $width, $height, $params = "" ) {
-               $cache = ObjectCache::getMainWANInstance();
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                // We can't check the local cache using FileRepo functions because
                // we override fileExistsBatch(). We have to use the FileBackend directly.
                $backend = $this->getBackend(); // convenience
@@ -569,7 +570,7 @@ class ForeignAPIRepo extends FileRepo {
                        $url = $this->makeUrl( $query, 'api' );
                }
 
-               $cache = ObjectCache::getMainWANInstance();
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                return $cache->getWithSetCallback(
                        $this->getLocalCacheKey( static::class, $target, md5( $url ) ),
                        $cacheTTL,
index 76043d5..03a9d44 100644 (file)
@@ -22,6 +22,7 @@
  * @ingroup FileRepo
  */
 
+use MediaWiki\MediaWikiServices;
 use Wikimedia\Rdbms\ResultWrapper;
 use Wikimedia\Rdbms\Database;
 use Wikimedia\Rdbms\IDatabase;
@@ -200,7 +201,7 @@ class LocalRepo extends FileRepo {
                }
 
                $method = __METHOD__;
-               $redirDbKey = ObjectCache::getMainWANInstance()->getWithSetCallback(
+               $redirDbKey = MediaWikiServices::getInstance()->getMainWANObjectCache()->getWithSetCallback(
                        $memcKey,
                        $expiry,
                        function ( $oldValue, &$ttl, array &$setOpts ) use ( $method, $title ) {
@@ -520,7 +521,7 @@ class LocalRepo extends FileRepo {
                if ( $key ) {
                        $this->getMasterDB()->onTransactionPreCommitOrIdle(
                                function () use ( $key ) {
-                                       ObjectCache::getMainWANInstance()->delete( $key );
+                                       MediaWikiServices::getInstance()->getMainWANObjectCache()->delete( $key );
                                },
                                __METHOD__
                        );
index d9763c6..65e4345 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup FileAbstraction
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Class representing a row of the 'filearchive' table
  *
@@ -251,7 +253,7 @@ class ArchivedFile {
                        'fa_deleted',
                        'fa_deleted_timestamp', /* Used by LocalFileRestoreBatch */
                        'fa_sha1',
-               ] + CommentStore::getStore()->getFields( 'fa_description' );
+               ] + MediaWikiServices::getInstance()->getCommentStore()->getFields( 'fa_description' );
        }
 
        /**
@@ -264,7 +266,7 @@ class ArchivedFile {
         *   - joins: (array) to include in the `$join_conds` to `IDatabase->select()`
         */
        public static function getQueryInfo() {
-               $commentQuery = CommentStore::getStore()->getJoin( 'fa_description' );
+               $commentQuery = MediaWikiServices::getInstance()->getCommentStore()->getJoin( 'fa_description' );
                $actorQuery = ActorMigration::newMigration()->getJoin( 'fa_user' );
                return [
                        'tables' => [ 'filearchive' ] + $commentQuery['tables'] + $actorQuery['tables'],
@@ -310,7 +312,7 @@ class ArchivedFile {
                $this->metadata = $row->fa_metadata;
                $this->mime = "$row->fa_major_mime/$row->fa_minor_mime";
                $this->media_type = $row->fa_media_type;
-               $this->description = CommentStore::getStore()
+               $this->description = MediaWikiServices::getInstance()->getCommentStore()
                        // Legacy because $row may have come from self::selectFields()
                        ->getCommentLegacy( wfGetDB( DB_REPLICA ), 'fa_description', $row )->text;
                $this->user = User::newFromAnyId( $row->fa_user, $row->fa_user_text, $row->fa_actor );
index cfd1cf2..7c87af3 100644 (file)
@@ -2065,7 +2065,7 @@ abstract class File implements IDBAccessObject {
 
                $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
                if ( $renderUrl ) {
-                       $cache = ObjectCache::getMainWANInstance();
+                       $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                        $key = $this->repo->getLocalCacheKey(
                                'RemoteFileDescription',
                                'url',
index be88b49..e05119c 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup FileAbstraction
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Foreign file accessible through api.php requests.
  * Very hacky and inefficient, do not use :D
@@ -360,7 +362,7 @@ class ForeignAPIFile extends File {
                $url = $this->repo->getDescriptionRenderUrl( $this->getName(), $wgContLang->getCode() );
                $key = $this->repo->getLocalCacheKey( 'RemoteFileDescription', 'url', md5( $url ) );
 
-               ObjectCache::getMainWANInstance()->delete( $key );
+               MediaWikiServices::getInstance()->getMainWANObjectCache()->delete( $key );
        }
 
        /**
@@ -368,7 +370,7 @@ class ForeignAPIFile extends File {
         */
        function purgeThumbnails( $options = [] ) {
                $key = $this->repo->getLocalCacheKey( 'ForeignAPIRepo', 'ThumbUrl', $this->getName() );
-               ObjectCache::getMainWANInstance()->delete( $key );
+               MediaWikiServices::getInstance()->getMainWANObjectCache()->delete( $key );
 
                $files = $this->getThumbnails();
                // Give media handler a chance to filter the purge list
index 388e950..05df45b 100644 (file)
@@ -21,6 +21,7 @@
  * @ingroup FileAbstraction
  */
 
+use MediaWiki\MediaWikiServices;
 use Wikimedia\Rdbms\DBUnexpectedError;
 
 /**
@@ -150,7 +151,7 @@ class ForeignDBFile extends LocalFile {
                        return false; // no description page
                }
 
-               $cache = ObjectCache::getMainWANInstance();
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
 
                return $cache->getWithSetCallback(
                        $this->repo->getLocalCacheKey(
index cff1044..c078e90 100644 (file)
@@ -226,7 +226,7 @@ class LocalFile extends File {
                        'img_actor' => $wgActorTableSchemaMigrationStage > MIGRATION_OLD ? 'img_actor' : null,
                        'img_timestamp',
                        'img_sha1',
-               ] + CommentStore::getStore()->getFields( 'img_description' );
+               ] + MediaWikiServices::getInstance()->getCommentStore()->getFields( 'img_description' );
        }
 
        /**
@@ -241,7 +241,7 @@ class LocalFile extends File {
         *   - joins: (array) to include in the `$join_conds` to `IDatabase->select()`
         */
        public static function getQueryInfo( array $options = [] ) {
-               $commentQuery = CommentStore::getStore()->getJoin( 'img_description' );
+               $commentQuery = MediaWikiServices::getInstance()->getCommentStore()->getJoin( 'img_description' );
                $actorQuery = ActorMigration::newMigration()->getJoin( 'img_user' );
                $ret = [
                        'tables' => [ 'image' ] + $commentQuery['tables'] + $actorQuery['tables'],
@@ -323,7 +323,7 @@ class LocalFile extends File {
                        return;
                }
 
-               $cache = ObjectCache::getMainWANInstance();
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                $cachedValues = $cache->getWithSetCallback(
                        $key,
                        $cache::TTL_WEEK,
@@ -388,7 +388,7 @@ class LocalFile extends File {
 
                $this->repo->getMasterDB()->onTransactionPreCommitOrIdle(
                        function () use ( $key ) {
-                               ObjectCache::getMainWANInstance()->delete( $key );
+                               MediaWikiServices::getInstance()->getMainWANObjectCache()->delete( $key );
                        },
                        __METHOD__
                );
@@ -579,7 +579,7 @@ class LocalFile extends File {
        function decodeRow( $row, $prefix = 'img_' ) {
                $decoded = $this->unprefixRow( $row, $prefix );
 
-               $decoded['description'] = CommentStore::getStore()
+               $decoded['description'] = MediaWikiServices::getInstance()->getCommentStore()
                        ->getComment( 'description', (object)$decoded )->text;
 
                $decoded['user'] = User::newFromAnyId(
@@ -1321,7 +1321,7 @@ class LocalFile extends File {
                        ) {
                                $props = $this->repo->getFileProps( $srcPath );
                        } else {
-                               $mwProps = new MWFileProps( MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer() );
+                               $mwProps = new MWFileProps( MediaWikiServices::getInstance()->getMimeAnalyzer() );
                                $props = $mwProps->getPropsFromPath( $srcPath, true );
                        }
                }
@@ -1462,7 +1462,7 @@ class LocalFile extends File {
                # Test to see if the row exists using INSERT IGNORE
                # This avoids race conditions by locking the row until the commit, and also
                # doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
-               $commentStore = CommentStore::getStore();
+               $commentStore = MediaWikiServices::getInstance()->getCommentStore();
                list( $commentFields, $commentCallback ) =
                        $commentStore->insertWithTempTable( $dbw, 'img_description', $comment );
                $actorMigration = ActorMigration::newMigration();
@@ -2470,7 +2470,7 @@ class LocalFileDeleteBatch {
                $now = time();
                $dbw = $this->file->repo->getMasterDB();
 
-               $commentStore = CommentStore::getStore();
+               $commentStore = MediaWikiServices::getInstance()->getCommentStore();
                $actorMigration = ActorMigration::newMigration();
 
                $encTimestamp = $dbw->addQuotes( $dbw->timestamp( $now ) );
@@ -2830,7 +2830,7 @@ class LocalFileRestoreBatch {
 
                $dbw = $this->file->repo->getMasterDB();
 
-               $commentStore = CommentStore::getStore();
+               $commentStore = MediaWikiServices::getInstance()->getCommentStore();
                $actorMigration = ActorMigration::newMigration();
 
                $status = $this->file->repo->newGood();
index 3a6b879..aa434d0 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup FileAbstraction
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Class to represent a file in the oldimage table
  *
@@ -140,7 +142,7 @@ class OldLocalFile extends LocalFile {
                        'oi_timestamp',
                        'oi_deleted',
                        'oi_sha1',
-               ] + CommentStore::getStore()->getFields( 'oi_description' );
+               ] + MediaWikiServices::getInstance()->getCommentStore()->getFields( 'oi_description' );
        }
 
        /**
@@ -155,7 +157,7 @@ class OldLocalFile extends LocalFile {
         *   - joins: (array) to include in the `$join_conds` to `IDatabase->select()`
         */
        public static function getQueryInfo( array $options = [] ) {
-               $commentQuery = CommentStore::getStore()->getJoin( 'oi_description' );
+               $commentQuery = MediaWikiServices::getInstance()->getCommentStore()->getJoin( 'oi_description' );
                $actorQuery = ActorMigration::newMigration()->getJoin( 'oi_user' );
                $ret = [
                        'tables' => [ 'oldimage' ] + $commentQuery['tables'] + $actorQuery['tables'],
@@ -446,7 +448,8 @@ class OldLocalFile extends LocalFile {
                        return false;
                }
 
-               $commentFields = CommentStore::getStore()->insert( $dbw, 'oi_description', $comment );
+               $commentFields = MediaWikiServices::getInstance()->getCommentStore()
+                       ->insert( $dbw, 'oi_description', $comment );
                $actorFields = ActorMigration::newMigration()->getInsertValues( $dbw, 'oi_user', $user );
                $dbw->insert( 'oldimage',
                        [