Merge "maintenance: Script to rename titles for Unicode uppercasing changes"
[lhc/web/wiklou.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 MediaWiki\MediaWikiServices;
23 use Wikimedia\Rdbms\IDatabase;
24
25 /**
26 * List for oldimage table items
27 */
28 class RevDelFileList extends RevDelList {
29 /** @var array */
30 public $storeBatch;
31
32 /** @var array */
33 public $deleteBatch;
34
35 /** @var array */
36 public $cleanupBatch;
37
38 public function getType() {
39 return 'oldimage';
40 }
41
42 public static function getRelationType() {
43 return 'oi_archive_name';
44 }
45
46 public static function getRestriction() {
47 return 'deleterevision';
48 }
49
50 public static function getRevdelConstant() {
51 return File::DELETED_FILE;
52 }
53
54 /**
55 * @param IDatabase $db
56 * @return mixed
57 */
58 public function doQuery( $db ) {
59 $archiveNames = [];
60 foreach ( $this->ids as $timestamp ) {
61 $archiveNames[] = $timestamp . '!' . $this->title->getDBkey();
62 }
63
64 $oiQuery = OldLocalFile::getQueryInfo();
65 return $db->select(
66 $oiQuery['tables'],
67 $oiQuery['fields'],
68 [
69 'oi_name' => $this->title->getDBkey(),
70 'oi_archive_name' => $archiveNames
71 ],
72 __METHOD__,
73 [ 'ORDER BY' => 'oi_timestamp DESC' ],
74 $oiQuery['joins']
75 );
76 }
77
78 public function newItem( $row ) {
79 return new RevDelFileItem( $this, $row );
80 }
81
82 public function clearFileOps() {
83 $this->deleteBatch = [];
84 $this->storeBatch = [];
85 $this->cleanupBatch = [];
86 }
87
88 public function doPreCommitUpdates() {
89 $status = Status::newGood();
90 $repo = RepoGroup::singleton()->getLocalRepo();
91 if ( $this->storeBatch ) {
92 $status->merge( $repo->storeBatch( $this->storeBatch, FileRepo::OVERWRITE_SAME ) );
93 }
94 if ( !$status->isOK() ) {
95 return $status;
96 }
97 if ( $this->deleteBatch ) {
98 $status->merge( $repo->deleteBatch( $this->deleteBatch ) );
99 }
100 if ( !$status->isOK() ) {
101 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
102 // modified (but destined for rollback) causes data loss
103 return $status;
104 }
105 if ( $this->cleanupBatch ) {
106 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) );
107 }
108
109 return $status;
110 }
111
112 public function doPostCommitUpdates( array $visibilityChangeMap ) {
113 $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
114 ->newFile( $this->title );
115 $file->purgeCache();
116 $file->purgeDescription();
117
118 // Purge full images from cache
119 $purgeUrls = [];
120 foreach ( $this->ids as $timestamp ) {
121 $archiveName = $timestamp . '!' . $this->title->getDBkey();
122 $file->purgeOldThumbnails( $archiveName );
123 $purgeUrls[] = $file->getArchiveUrl( $archiveName );
124 }
125 DeferredUpdates::addUpdate(
126 new CdnCacheUpdate( $purgeUrls ),
127 DeferredUpdates::PRESEND
128 );
129
130 return Status::newGood();
131 }
132
133 public function getSuppressBit() {
134 return File::DELETED_RESTRICTED;
135 }
136 }