67 $this->user =
$user ?: $wgUser;
68 $this->status =
$file->repo->newGood();
72 $this->srcRels[
'.'] = $this->file->getRel();
79 $this->srcRels[$oldName] = $this->file->getArchiveRel( $oldName );
80 $this->archiveUrls[] = $this->file->getArchiveUrl( $oldName );
90 $dbw = $this->file->repo->getMasterDB();
91 $result = $dbw->select(
'oldimage',
92 [
'oi_archive_name' ],
93 [
'oi_name' => $this->file->getName() ],
97 foreach ( $result as $row ) {
98 $this->
addOld( $row->oi_archive_name );
99 $archiveNames[] = $row->oi_archive_name;
102 return $archiveNames;
109 if ( !isset( $this->srcRels[
'.'] ) ) {
111 $deleteCurrent =
false;
114 unset( $oldRels[
'.'] );
115 $deleteCurrent =
true;
118 return [ $oldRels, $deleteCurrent ];
126 list( $oldRels, $deleteCurrent ) = $this->
getOldRels();
128 if ( $deleteCurrent ) {
129 $hashes[
'.'] = $this->file->getSha1();
132 if ( count( $oldRels ) ) {
133 $dbw = $this->file->repo->getMasterDB();
136 [
'oi_archive_name',
'oi_sha1' ],
137 [
'oi_archive_name' => array_keys( $oldRels ),
138 'oi_name' => $this->file->getName() ],
142 foreach (
$res as $row ) {
143 if ( rtrim( $row->oi_sha1,
"\0" ) ===
'' ) {
145 $oldUrl = $this->file->getArchiveVirtualUrl( $row->oi_archive_name );
146 $props = $this->file->repo->getFileProps( $oldUrl );
148 if ( $props[
'fileExists'] ) {
150 $dbw->update(
'oldimage',
151 [
'oi_sha1' => $props[
'sha1'] ],
152 [
'oi_name' => $this->file->getName(),
'oi_archive_name' => $row->oi_archive_name ],
154 $hashes[$row->oi_archive_name] = $props[
'sha1'];
156 $hashes[$row->oi_archive_name] =
false;
159 $hashes[$row->oi_archive_name] = $row->oi_sha1;
164 $missing = array_diff_key( $this->srcRels,
$hashes );
166 foreach ( $missing as $name => $rel ) {
167 $this->status->error(
'filedelete-old-unregistered', $name );
170 foreach (
$hashes as $name => $hash ) {
172 $this->status->error(
'filedelete-missing', $this->srcRels[$name] );
182 $dbw = $this->file->repo->getMasterDB();
184 $commentStore = MediaWikiServices::getInstance()->getCommentStore();
187 $encTimestamp = $dbw->addQuotes( $dbw->timestamp( $now ) );
188 $encUserId = $dbw->addQuotes( $this->user->getId() );
189 $encGroup = $dbw->addQuotes(
'deleted' );
190 $ext = $this->file->getExtension();
191 $dotExt =
$ext ===
'' ?
'' :
".$ext";
192 $encExt = $dbw->addQuotes( $dotExt );
193 list( $oldRels, $deleteCurrent ) = $this->
getOldRels();
196 if ( $this->suppress ) {
197 $bitfield = RevisionRecord::SUPPRESSED_ALL;
199 $bitfield =
'oi_deleted';
202 if ( $deleteCurrent ) {
203 $tables = [
'image' ];
205 'fa_storage_group' => $encGroup,
206 'fa_storage_key' => $dbw->conditional(
207 [
'img_sha1' =>
'' ],
208 $dbw->addQuotes(
'' ),
209 $dbw->buildConcat( [
"img_sha1", $encExt ] )
211 'fa_deleted_user' => $encUserId,
212 'fa_deleted_timestamp' => $encTimestamp,
213 'fa_deleted' => $this->suppress ? $bitfield : 0,
214 'fa_name' =>
'img_name',
215 'fa_archive_name' =>
'NULL',
216 'fa_size' =>
'img_size',
217 'fa_width' =>
'img_width',
218 'fa_height' =>
'img_height',
219 'fa_metadata' =>
'img_metadata',
220 'fa_bits' =>
'img_bits',
221 'fa_media_type' =>
'img_media_type',
222 'fa_major_mime' =>
'img_major_mime',
223 'fa_minor_mime' =>
'img_minor_mime',
224 'fa_description_id' =>
'img_description_id',
225 'fa_timestamp' =>
'img_timestamp',
226 'fa_sha1' =>
'img_sha1',
227 'fa_actor' =>
'img_actor',
231 $fields += array_map(
232 [ $dbw,
'addQuotes' ],
233 $commentStore->insert( $dbw,
'fa_deleted_reason', $this->reason )
236 $dbw->insertSelect(
'filearchive', $tables, $fields,
237 [
'img_name' => $this->file->getName() ], __METHOD__, [], [], $joins );
240 if ( count( $oldRels ) ) {
243 $fileQuery[
'tables'],
244 $fileQuery[
'fields'],
246 'oi_name' => $this->file->getName(),
247 'oi_archive_name' => array_keys( $oldRels )
254 if (
$res->numRows() ) {
255 $reason = $commentStore->createComment( $dbw, $this->reason );
256 foreach (
$res as $row ) {
257 $comment = $commentStore->getComment(
'oi_description', $row );
261 'fa_storage_group' =>
'deleted',
262 'fa_storage_key' => ( $row->oi_sha1 ===
'' )
264 :
"{$row->oi_sha1}{$dotExt}",
265 'fa_deleted_user' => $this->user->getId(),
266 'fa_deleted_timestamp' => $dbw->timestamp( $now ),
268 'fa_deleted' => $this->suppress ? $bitfield : $row->oi_deleted,
269 'fa_name' => $row->oi_name,
270 'fa_archive_name' => $row->oi_archive_name,
271 'fa_size' => $row->oi_size,
272 'fa_width' => $row->oi_width,
273 'fa_height' => $row->oi_height,
274 'fa_metadata' => $row->oi_metadata,
275 'fa_bits' => $row->oi_bits,
276 'fa_media_type' => $row->oi_media_type,
277 'fa_major_mime' => $row->oi_major_mime,
278 'fa_minor_mime' => $row->oi_minor_mime,
279 'fa_timestamp' => $row->oi_timestamp,
280 'fa_sha1' => $row->oi_sha1
281 ] + $commentStore->insert( $dbw,
'fa_deleted_reason',
$reason )
282 + $commentStore->insert( $dbw,
'fa_description', $comment )
283 + $actorMigration->getInsertValues( $dbw,
'fa_user',
$user );
287 $dbw->insert(
'filearchive', $rowsInsert, __METHOD__ );
292 $dbw = $this->file->repo->getMasterDB();
293 list( $oldRels, $deleteCurrent ) = $this->
getOldRels();
295 if ( count( $oldRels ) ) {
296 $dbw->delete(
'oldimage',
298 'oi_name' => $this->file->getName(),
299 'oi_archive_name' => array_keys( $oldRels )
303 if ( $deleteCurrent ) {
304 $dbw->delete(
'image', [
'img_name' => $this->file->getName() ], __METHOD__ );
313 $repo = $this->file->getRepo();
318 $this->deletionBatch = [];
319 $ext = $this->file->getExtension();
320 $dotExt =
$ext ===
'' ?
'' :
".$ext";
322 foreach ( $this->srcRels as $name => $srcRel ) {
324 if ( isset(
$hashes[$name] ) ) {
326 $key = $hash . $dotExt;
327 $dstRel = $repo->getDeletedHashPath( $key ) . $key;
328 $this->deletionBatch[$name] = [ $srcRel, $dstRel ];
332 if ( !$repo->hasSha1Storage() ) {
336 if ( !$checkStatus->isGood() ) {
337 $this->status->merge( $checkStatus );
340 $this->deletionBatch = $checkStatus->value;
343 $status = $this->file->repo->deleteBatch( $this->deletionBatch );
349 if ( !$this->status->isOK() ) {
351 $this->file->unlock();
362 $this->file->unlock();
373 $files = $newBatch = [];
375 foreach ( $batch as $batchItem ) {
376 list( $src, ) = $batchItem;
377 $files[$src] = $this->file->repo->getVirtualUrl(
'public' ) .
'/' . rawurlencode( $src );
380 $result = $this->file->repo->fileExistsBatch( $files );
381 if ( in_array(
null, $result,
true ) ) {
383 $this->file->repo->getBackend()->getName() );
386 foreach ( $batch as $batchItem ) {
387 if ( $result[$batchItem[0]] ) {
388 $newBatch[] = $batchItem;