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