From 2330c9afaddb4379858297a9fc83d56ac40aeff3 Mon Sep 17 00:00:00 2001 From: WMDE-Fisch Date: Fri, 4 May 2018 15:39:33 +0200 Subject: [PATCH] Replace deprecated ObjectCache and CommentStore calls in filerepo Change-Id: I0e863dc8e4bc6dac938a2ed437c2691aace19690 --- includes/filerepo/ForeignAPIRepo.php | 5 +++-- includes/filerepo/LocalRepo.php | 5 +++-- includes/filerepo/file/ArchivedFile.php | 8 +++++--- includes/filerepo/file/File.php | 2 +- includes/filerepo/file/ForeignAPIFile.php | 6 ++++-- includes/filerepo/file/ForeignDBFile.php | 3 ++- includes/filerepo/file/LocalFile.php | 18 +++++++++--------- includes/filerepo/file/OldLocalFile.php | 9 ++++++--- 8 files changed, 33 insertions(+), 23 deletions(-) diff --git a/includes/filerepo/ForeignAPIRepo.php b/includes/filerepo/ForeignAPIRepo.php index 06b21a8fc6..cba21c8870 100644 --- a/includes/filerepo/ForeignAPIRepo.php +++ b/includes/filerepo/ForeignAPIRepo.php @@ -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, diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php index 76043d5544..03a9d44168 100644 --- a/includes/filerepo/LocalRepo.php +++ b/includes/filerepo/LocalRepo.php @@ -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__ ); diff --git a/includes/filerepo/file/ArchivedFile.php b/includes/filerepo/file/ArchivedFile.php index d9763c64b4..65e43459fe 100644 --- a/includes/filerepo/file/ArchivedFile.php +++ b/includes/filerepo/file/ArchivedFile.php @@ -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 ); diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index cfd1cf25cd..7c87af3974 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -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', diff --git a/includes/filerepo/file/ForeignAPIFile.php b/includes/filerepo/file/ForeignAPIFile.php index be88b49a60..e05119c720 100644 --- a/includes/filerepo/file/ForeignAPIFile.php +++ b/includes/filerepo/file/ForeignAPIFile.php @@ -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 diff --git a/includes/filerepo/file/ForeignDBFile.php b/includes/filerepo/file/ForeignDBFile.php index 388e9503eb..05df45b32f 100644 --- a/includes/filerepo/file/ForeignDBFile.php +++ b/includes/filerepo/file/ForeignDBFile.php @@ -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( diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index cff1044870..c078e90dfd 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -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(); diff --git a/includes/filerepo/file/OldLocalFile.php b/includes/filerepo/file/OldLocalFile.php index 3a6b8795af..aa434d0c8f 100644 --- a/includes/filerepo/file/OldLocalFile.php +++ b/includes/filerepo/file/OldLocalFile.php @@ -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', [ -- 2.20.1