MediaWiki REL1_39
FileDeleteForm.php
Go to the documentation of this file.
1<?php
28
50 public static function doDelete( Title $title, LocalFile $file, ?string $oldimage, $reason,
51 $suppress, UserIdentity $user, $tags = [], bool $deleteTalk = false
52 ): Status {
53 if ( $oldimage ) {
54 $page = null;
55 $status = $file->deleteOldFile( $oldimage, $reason, $user, $suppress );
56 if ( $status->isOK() ) {
57 // Need to do a log item
58 $logComment = wfMessage( 'deletedrevision', $oldimage )->inContentLanguage()->text();
59 if ( trim( $reason ) !== '' ) {
60 $logComment .= wfMessage( 'colon-separator' )
61 ->inContentLanguage()->text() . $reason;
62 }
63
64 $logtype = $suppress ? 'suppress' : 'delete';
65
66 $logEntry = new ManualLogEntry( $logtype, 'delete' );
67 $logEntry->setPerformer( $user );
68 $logEntry->setTarget( $title );
69 $logEntry->setComment( $logComment );
70 $logEntry->addTags( $tags );
71 $logid = $logEntry->insert();
72 $logEntry->publish( $logid );
73
74 $status->value = $logid;
75 }
76 } else {
77 $status = Status::newFatal( 'cannotdelete',
78 wfEscapeWikiText( $title->getPrefixedText() )
79 );
80 $services = MediaWikiServices::getInstance();
81 $page = $services->getWikiPageFactory()->newFromTitle( $title );
82 '@phan-var WikiFilePage $page';
83 $deleter = $services->getUserFactory()->newFromUserIdentity( $user );
84 $deletePage = $services->getDeletePageFactory()->newDeletePage( $page, $deleter );
85 if ( $deleteTalk ) {
86 $checkStatus = $deletePage->canProbablyDeleteAssociatedTalk();
87 if ( !$checkStatus->isGood() ) {
88 return Status::wrap( $checkStatus );
89 }
90 $deletePage->setDeleteAssociatedTalk( true );
91 }
92 $dbw = wfGetDB( DB_PRIMARY );
93 $dbw->startAtomic( __METHOD__, $dbw::ATOMIC_CANCELABLE );
94 // delete the associated article first
95 $deleteStatus = $deletePage
96 ->setSuppress( $suppress )
97 ->setTags( $tags ?: [] )
98 ->deleteIfAllowed( $reason );
99
100 // DeletePage returns a non-fatal error status if the page
101 // or revision is missing, so check for isOK() rather than isGood().
102 if ( $deleteStatus->isOK() ) {
103 $status = $file->deleteFile( $reason, $user, $suppress );
104 if ( $status->isOK() ) {
105 if ( $deletePage->deletionsWereScheduled()[DeletePage::PAGE_BASE] ) {
106 $status->value = false;
107 } else {
108 $deletedID = $deletePage->getSuccessfulDeletionsIDs()[DeletePage::PAGE_BASE];
109 if ( $deletedID !== null ) {
110 $status->value = $deletedID;
111 } else {
112 // Means that the page/revision didn't exist, so create a log entry here.
113 $logtype = $suppress ? 'suppress' : 'delete';
114 $logEntry = new ManualLogEntry( $logtype, 'delete' );
115 $logEntry->setPerformer( $user );
116 $logEntry->setTarget( $title );
117 $logEntry->setComment( $reason );
118 $logEntry->addTags( $tags );
119 $logid = $logEntry->insert();
120 $dbw->onTransactionPreCommitOrIdle(
121 static function () use ( $logEntry, $logid ) {
122 $logEntry->publish( $logid );
123 },
124 __METHOD__
125 );
126 $status->value = $logid;
127 }
128 }
129 $dbw->endAtomic( __METHOD__ );
130 } else {
131 // Page deleted but file still there? rollback page delete
132 $dbw->cancelAtomic( __METHOD__ );
133 }
134 } else {
135 $dbw->endAtomic( __METHOD__ );
136 }
137 }
138
139 if ( $status->isOK() ) {
140 $legacyUser = MediaWikiServices::getInstance()
141 ->getUserFactory()
142 ->newFromUserIdentity( $user );
143 Hooks::runner()->onFileDeleteComplete( $file, $oldimage, $page, $legacyUser, $reason );
144 }
145
146 return $status;
147 }
148
155 public static function isValidOldSpec( $oldimage ) {
156 return strlen( $oldimage ) >= 16
157 && strpos( $oldimage, '/' ) === false
158 && strpos( $oldimage, '\\' ) === false;
159 }
160}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
Definition WebStart.php:82
File deletion user interface.
static doDelete(Title $title, LocalFile $file, ?string $oldimage, $reason, $suppress, UserIdentity $user, $tags=[], bool $deleteTalk=false)
Really delete the file.
static isValidOldSpec( $oldimage)
Is the provided oldimage value valid?
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
Definition Hooks.php:173
Local file in the wiki's own database.
Definition LocalFile.php:60
Class for creating new log entries and inserting them into the database.
Service locator for MediaWiki core services.
Backend logic for performing a page delete action.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:44
Represents a title within MediaWiki.
Definition Title.php:49
Interface for objects representing user identity.
const DB_PRIMARY
Definition defines.php:28
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42