Merge "EditPage: Make input and button widgets infusable"
[mediawiki.git] / includes / revisiondelete / RevDelFileList.php
blob77cf97676206e288f52b42c41f4a19e732669a4d
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 Wikimedia\Rdbms\IDatabase;
24 /**
25 * List for oldimage table items
27 class RevDelFileList extends RevDelList {
28 /** @var array */
29 public $storeBatch;
31 /** @var array */
32 public $deleteBatch;
34 /** @var array */
35 public $cleanupBatch;
37 public function getType() {
38 return 'oldimage';
41 public static function getRelationType() {
42 return 'oi_archive_name';
45 public static function getRestriction() {
46 return 'deleterevision';
49 public static function getRevdelConstant() {
50 return File::DELETED_FILE;
53 /**
54 * @param IDatabase $db
55 * @return mixed
57 public function doQuery( $db ) {
58 $archiveNames = [];
59 foreach ( $this->ids as $timestamp ) {
60 $archiveNames[] = $timestamp . '!' . $this->title->getDBkey();
63 return $db->select(
64 'oldimage',
65 OldLocalFile::selectFields(),
67 'oi_name' => $this->title->getDBkey(),
68 'oi_archive_name' => $archiveNames
70 __METHOD__,
71 [ 'ORDER BY' => 'oi_timestamp DESC' ]
75 public function newItem( $row ) {
76 return new RevDelFileItem( $this, $row );
79 public function clearFileOps() {
80 $this->deleteBatch = [];
81 $this->storeBatch = [];
82 $this->cleanupBatch = [];
85 public function doPreCommitUpdates() {
86 $status = Status::newGood();
87 $repo = RepoGroup::singleton()->getLocalRepo();
88 if ( $this->storeBatch ) {
89 $status->merge( $repo->storeBatch( $this->storeBatch, FileRepo::OVERWRITE_SAME ) );
91 if ( !$status->isOK() ) {
92 return $status;
94 if ( $this->deleteBatch ) {
95 $status->merge( $repo->deleteBatch( $this->deleteBatch ) );
97 if ( !$status->isOK() ) {
98 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
99 // modified (but destined for rollback) causes data loss
100 return $status;
102 if ( $this->cleanupBatch ) {
103 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) );
106 return $status;
109 public function doPostCommitUpdates( array $visibilityChangeMap ) {
110 $file = wfLocalFile( $this->title );
111 $file->purgeCache();
112 $file->purgeDescription();
114 // Purge full images from cache
115 $purgeUrls = [];
116 foreach ( $this->ids as $timestamp ) {
117 $archiveName = $timestamp . '!' . $this->title->getDBkey();
118 $file->purgeOldThumbnails( $archiveName );
119 $purgeUrls[] = $file->getArchiveUrl( $archiveName );
121 DeferredUpdates::addUpdate(
122 new CdnCacheUpdate( $purgeUrls ),
123 DeferredUpdates::PRESEND
126 return Status::newGood();
129 public function getSuppressBit() {
130 return File::DELETED_RESTRICTED;