Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / revisiondelete / RevDelFileList.php
blob8b3d445e178b68f16e767a6d3f3a83893d4e4bfd
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
19 * @ingroup RevisionDelete
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;
32 /**
33 * List for oldimage table items
35 class RevDelFileList extends RevDelList {
37 protected const SUPPRESS_BIT = File::DELETED_RESTRICTED;
39 /** @var HTMLCacheUpdater */
40 private $htmlCacheUpdater;
42 /** @var RepoGroup */
43 private $repoGroup;
45 /** @var array */
46 public $storeBatch;
48 /** @var array */
49 public $deleteBatch;
51 /** @var array */
52 public $cleanupBatch;
54 /**
55 * @param IContextSource $context
56 * @param PageIdentity $page
57 * @param array $ids
58 * @param LBFactory $lbFactory
59 * @param HTMLCacheUpdater $htmlCacheUpdater
60 * @param RepoGroup $repoGroup
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;
75 public function getType() {
76 return 'oldimage';
79 public static function getRelationType() {
80 return 'oi_archive_name';
83 public static function getRestriction() {
84 return 'deleterevision';
87 public static function getRevdelConstant() {
88 return File::DELETED_FILE;
91 /**
92 * @param IReadableDatabase $db
93 * @return IResultWrapper
95 public function doQuery( $db ) {
96 $archiveNames = [];
97 foreach ( $this->ids as $timestamp ) {
98 $archiveNames[] = $timestamp . '!' . $this->page->getDBkey();
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();
108 public function newItem( $row ) {
109 return new RevDelFileItem( $this, $row );
112 public function clearFileOps() {
113 $this->deleteBatch = [];
114 $this->storeBatch = [];
115 $this->cleanupBatch = [];
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 ) );
124 if ( !$status->isOK() ) {
125 return $status;
127 if ( $this->deleteBatch ) {
128 $status->merge( $repo->deleteBatch( $this->deleteBatch ) );
130 if ( !$status->isOK() ) {
131 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
132 // modified (but destined for rollback) causes data loss
133 return $status;
135 if ( $this->cleanupBatch ) {
136 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) );
139 return $status;
142 public function doPostCommitUpdates( array $visibilityChangeMap ) {
143 $file = $this->repoGroup->getLocalRepo()->newFile( $this->page );
144 $file->purgeCache();
145 $file->purgeDescription();
147 // Purge full images from cache
148 $purgeUrls = [];
149 foreach ( $this->ids as $timestamp ) {
150 $archiveName = $timestamp . '!' . $this->page->getDBkey();
151 $file->purgeOldThumbnails( $archiveName );
152 $purgeUrls[] = $file->getArchiveUrl( $archiveName );
155 $this->htmlCacheUpdater->purgeUrls(
156 $purgeUrls,
157 HTMLCacheUpdater::PURGE_INTENT_TXROUND_REFLECTED
160 return Status::newGood();