]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/revisiondelete/RevDelFileList.php
MediaWiki 1.30.2
[autoinstalls/mediawiki.git] / includes / revisiondelete / RevDelFileList.php
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.
7  *
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.
12  *
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
17  *
18  * @file
19  * @ingroup RevisionDelete
20  */
21
22 use Wikimedia\Rdbms\IDatabase;
23
24 /**
25  * List for oldimage table items
26  */
27 class RevDelFileList extends RevDelList {
28         /** @var array */
29         public $storeBatch;
30
31         /** @var array */
32         public $deleteBatch;
33
34         /** @var array */
35         public $cleanupBatch;
36
37         public function getType() {
38                 return 'oldimage';
39         }
40
41         public static function getRelationType() {
42                 return 'oi_archive_name';
43         }
44
45         public static function getRestriction() {
46                 return 'deleterevision';
47         }
48
49         public static function getRevdelConstant() {
50                 return File::DELETED_FILE;
51         }
52
53         /**
54          * @param IDatabase $db
55          * @return mixed
56          */
57         public function doQuery( $db ) {
58                 $archiveNames = [];
59                 foreach ( $this->ids as $timestamp ) {
60                         $archiveNames[] = $timestamp . '!' . $this->title->getDBkey();
61                 }
62
63                 return $db->select(
64                         'oldimage',
65                         OldLocalFile::selectFields(),
66                         [
67                                 'oi_name' => $this->title->getDBkey(),
68                                 'oi_archive_name' => $archiveNames
69                         ],
70                         __METHOD__,
71                         [ 'ORDER BY' => 'oi_timestamp DESC' ]
72                 );
73         }
74
75         public function newItem( $row ) {
76                 return new RevDelFileItem( $this, $row );
77         }
78
79         public function clearFileOps() {
80                 $this->deleteBatch = [];
81                 $this->storeBatch = [];
82                 $this->cleanupBatch = [];
83         }
84
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 ) );
90                 }
91                 if ( !$status->isOK() ) {
92                         return $status;
93                 }
94                 if ( $this->deleteBatch ) {
95                         $status->merge( $repo->deleteBatch( $this->deleteBatch ) );
96                 }
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;
101                 }
102                 if ( $this->cleanupBatch ) {
103                         $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) );
104                 }
105
106                 return $status;
107         }
108
109         public function doPostCommitUpdates( array $visibilityChangeMap ) {
110                 $file = wfLocalFile( $this->title );
111                 $file->purgeCache();
112                 $file->purgeDescription();
113
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 );
120                 }
121                 DeferredUpdates::addUpdate(
122                         new CdnCacheUpdate( $purgeUrls ),
123                         DeferredUpdates::PRESEND
124                 );
125
126                 return Status::newGood();
127         }
128
129         public function getSuppressBit() {
130                 return File::DELETED_RESTRICTED;
131         }
132 }