51 $suppress,
UserIdentity $user, $tags = [],
bool $deleteTalk =
false
55 $status =
$file->deleteOldFile( $oldimage, $reason, $user, $suppress );
56 if ( $status->isOK() ) {
58 $logComment =
wfMessage(
'deletedrevision', $oldimage )->inContentLanguage()->text();
59 if ( trim( $reason ) !==
'' ) {
60 $logComment .=
wfMessage(
'colon-separator' )
61 ->inContentLanguage()->text() . $reason;
64 $logtype = $suppress ?
'suppress' :
'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 );
74 $status->value = $logid;
77 $status = Status::newFatal(
'cannotdelete',
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 );
86 $checkStatus = $deletePage->canProbablyDeleteAssociatedTalk();
87 if ( !$checkStatus->isGood() ) {
88 return Status::wrap( $checkStatus );
90 $deletePage->setDeleteAssociatedTalk(
true );
93 $dbw->startAtomic( __METHOD__, $dbw::ATOMIC_CANCELABLE );
95 $deleteStatus = $deletePage
96 ->setSuppress( $suppress )
97 ->setTags( $tags ?: [] )
98 ->deleteIfAllowed( $reason );
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;
108 $deletedID = $deletePage->getSuccessfulDeletionsIDs()[DeletePage::PAGE_BASE];
109 if ( $deletedID !==
null ) {
110 $status->value = $deletedID;
113 $logtype = $suppress ?
'suppress' :
'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 );
126 $status->value = $logid;
129 $dbw->endAtomic( __METHOD__ );
132 $dbw->cancelAtomic( __METHOD__ );
135 $dbw->endAtomic( __METHOD__ );
139 if ( $status->isOK() ) {
140 $legacyUser = MediaWikiServices::getInstance()
142 ->newFromUserIdentity( $user );
143 Hooks::runner()->onFileDeleteComplete(
$file, $oldimage, $page, $legacyUser, $reason );