Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 49 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
| RevDelFileList | |
0.00% |
0 / 48 |
|
0.00% |
0 / 10 |
342 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getRelationType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getRestriction | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getRevdelConstant | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| doQuery | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| newItem | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| clearFileOps | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| doPreCommitUpdates | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
42 | |||
| doPostCommitUpdates | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | * @ingroup RevisionDelete |
| 6 | */ |
| 7 | |
| 8 | namespace MediaWiki\RevisionDelete; |
| 9 | |
| 10 | use MediaWiki\Cache\HTMLCacheUpdater; |
| 11 | use MediaWiki\Context\IContextSource; |
| 12 | use MediaWiki\FileRepo\File\File; |
| 13 | use MediaWiki\FileRepo\File\FileSelectQueryBuilder; |
| 14 | use MediaWiki\FileRepo\FileRepo; |
| 15 | use MediaWiki\FileRepo\RepoGroup; |
| 16 | use MediaWiki\Page\PageIdentity; |
| 17 | use MediaWiki\Status\Status; |
| 18 | use Wikimedia\Rdbms\IReadableDatabase; |
| 19 | use Wikimedia\Rdbms\IResultWrapper; |
| 20 | use Wikimedia\Rdbms\LBFactory; |
| 21 | use Wikimedia\Rdbms\SelectQueryBuilder; |
| 22 | |
| 23 | /** |
| 24 | * List for oldimage table items |
| 25 | */ |
| 26 | class RevDelFileList extends RevDelList { |
| 27 | |
| 28 | protected const SUPPRESS_BIT = File::DELETED_RESTRICTED; |
| 29 | |
| 30 | /** @var HTMLCacheUpdater */ |
| 31 | private $htmlCacheUpdater; |
| 32 | |
| 33 | /** @var RepoGroup */ |
| 34 | private $repoGroup; |
| 35 | |
| 36 | /** @var array */ |
| 37 | public $storeBatch; |
| 38 | |
| 39 | /** @var array */ |
| 40 | public $deleteBatch; |
| 41 | |
| 42 | /** @var array */ |
| 43 | public $cleanupBatch; |
| 44 | |
| 45 | /** |
| 46 | * @param IContextSource $context |
| 47 | * @param PageIdentity $page |
| 48 | * @param array $ids |
| 49 | * @param LBFactory $lbFactory |
| 50 | * @param HTMLCacheUpdater $htmlCacheUpdater |
| 51 | * @param RepoGroup $repoGroup |
| 52 | */ |
| 53 | public function __construct( |
| 54 | IContextSource $context, |
| 55 | PageIdentity $page, |
| 56 | array $ids, |
| 57 | LBFactory $lbFactory, |
| 58 | HTMLCacheUpdater $htmlCacheUpdater, |
| 59 | RepoGroup $repoGroup |
| 60 | ) { |
| 61 | parent::__construct( $context, $page, $ids, $lbFactory ); |
| 62 | $this->htmlCacheUpdater = $htmlCacheUpdater; |
| 63 | $this->repoGroup = $repoGroup; |
| 64 | } |
| 65 | |
| 66 | /** @inheritDoc */ |
| 67 | public function getType() { |
| 68 | return 'oldimage'; |
| 69 | } |
| 70 | |
| 71 | /** @inheritDoc */ |
| 72 | public static function getRelationType() { |
| 73 | return 'oi_archive_name'; |
| 74 | } |
| 75 | |
| 76 | /** @inheritDoc */ |
| 77 | public static function getRestriction() { |
| 78 | return 'deleterevision'; |
| 79 | } |
| 80 | |
| 81 | /** @inheritDoc */ |
| 82 | public static function getRevdelConstant() { |
| 83 | return File::DELETED_FILE; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * @param IReadableDatabase $db |
| 88 | * @return IResultWrapper |
| 89 | */ |
| 90 | public function doQuery( $db ) { |
| 91 | $archiveNames = []; |
| 92 | foreach ( $this->ids as $timestamp ) { |
| 93 | $archiveNames[] = $timestamp . '!' . $this->page->getDBkey(); |
| 94 | } |
| 95 | |
| 96 | $queryBuilder = FileSelectQueryBuilder::newForOldFile( $db ); |
| 97 | $queryBuilder |
| 98 | ->where( [ 'oi_name' => $this->page->getDBkey(), 'oi_archive_name' => $archiveNames ] ) |
| 99 | ->orderBy( 'oi_timestamp', SelectQueryBuilder::SORT_DESC ); |
| 100 | return $queryBuilder->caller( __METHOD__ )->fetchResultSet(); |
| 101 | } |
| 102 | |
| 103 | /** @inheritDoc */ |
| 104 | public function newItem( $row ) { |
| 105 | return new RevDelFileItem( $this, $row ); |
| 106 | } |
| 107 | |
| 108 | public function clearFileOps() { |
| 109 | $this->deleteBatch = []; |
| 110 | $this->storeBatch = []; |
| 111 | $this->cleanupBatch = []; |
| 112 | } |
| 113 | |
| 114 | /** @inheritDoc */ |
| 115 | public function doPreCommitUpdates() { |
| 116 | $status = Status::newGood(); |
| 117 | $repo = $this->repoGroup->getLocalRepo(); |
| 118 | if ( $this->storeBatch ) { |
| 119 | $status->merge( $repo->storeBatch( $this->storeBatch, FileRepo::OVERWRITE_SAME ) ); |
| 120 | } |
| 121 | if ( !$status->isOK() ) { |
| 122 | return $status; |
| 123 | } |
| 124 | if ( $this->deleteBatch ) { |
| 125 | $status->merge( $repo->deleteBatch( $this->deleteBatch ) ); |
| 126 | } |
| 127 | if ( !$status->isOK() ) { |
| 128 | // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already |
| 129 | // modified (but destined for rollback) causes data loss |
| 130 | return $status; |
| 131 | } |
| 132 | if ( $this->cleanupBatch ) { |
| 133 | $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) ); |
| 134 | } |
| 135 | |
| 136 | return $status; |
| 137 | } |
| 138 | |
| 139 | /** @inheritDoc */ |
| 140 | public function doPostCommitUpdates( array $visibilityChangeMap ) { |
| 141 | $status = Status::newGood(); |
| 142 | |
| 143 | $file = $this->repoGroup->getLocalRepo()->newFile( $this->page ); |
| 144 | if ( !$file ) { |
| 145 | return $status; |
| 146 | } |
| 147 | |
| 148 | $file->purgeCache(); |
| 149 | $file->purgeDescription(); |
| 150 | |
| 151 | // Purge full images from cache |
| 152 | $purgeUrls = []; |
| 153 | foreach ( $this->ids as $timestamp ) { |
| 154 | $archiveName = $timestamp . '!' . $this->page->getDBkey(); |
| 155 | $file->purgeOldThumbnails( $archiveName ); |
| 156 | $purgeUrls[] = $file->getArchiveUrl( $archiveName ); |
| 157 | } |
| 158 | |
| 159 | $this->htmlCacheUpdater->purgeUrls( |
| 160 | $purgeUrls, |
| 161 | HTMLCacheUpdater::PURGE_INTENT_TXROUND_REFLECTED |
| 162 | ); |
| 163 | |
| 164 | return $status; |
| 165 | } |
| 166 | |
| 167 | } |
| 168 | |
| 169 | /** @deprecated class alias since 1.46 */ |
| 170 | class_alias( RevDelFileList::class, 'RevDelFileList' ); |