/** * Really delete the file * * @param Title $title * @param File $file * @param string $oldimage Archive name * @param string $reason Reason of the deletion * @param bool $suppress Whether to mark all deleted versions as restricted * @param User $user User object performing the request * @throws MWException * @return bool|Status */ public static function doDelete(&$title, &$file, &$oldimage, $reason, $suppress, User $user = null) { if ($user === null) { global $wgUser; $user = $wgUser; } if ($oldimage) { $page = null; $status = $file->deleteOld($oldimage, $reason, $suppress, $user); if ($status->ok) { // Need to do a log item $logComment = wfMessage('deletedrevision', $oldimage)->inContentLanguage()->text(); if (trim($reason) != '') { $logComment .= wfMessage('colon-separator')->inContentLanguage()->text() . $reason; } $logtype = $suppress ? 'suppress' : 'delete'; $logEntry = new ManualLogEntry($logtype, 'delete'); $logEntry->setPerformer($user); $logEntry->setTarget($title); $logEntry->setComment($logComment); $logid = $logEntry->insert(); $logEntry->publish($logid); $status->value = $logid; } } else { $status = Status::newFatal('cannotdelete', wfEscapeWikiText($title->getPrefixedText())); $page = WikiPage::factory($title); $dbw = wfGetDB(DB_MASTER); try { $dbw->startAtomic(__METHOD__); // delete the associated article first $error = ''; $deleteStatus = $page->doDeleteArticleReal($reason, $suppress, 0, false, $error, $user); // doDeleteArticleReal() returns a non-fatal error status if the page // or revision is missing, so check for isOK() rather than isGood() if ($deleteStatus->isOK()) { $status = $file->delete($reason, $suppress, $user); if ($status->isOK()) { $status->value = $deleteStatus->value; // log id $dbw->endAtomic(__METHOD__); } else { // Page deleted but file still there? rollback page delete $dbw->rollback(__METHOD__); } } else { // Done; nothing changed $dbw->endAtomic(__METHOD__); } } catch (Exception $e) { // Rollback before returning to prevent UI from displaying // incorrect "View or restore N deleted edits?" $dbw->rollback(__METHOD__); throw $e; } } if ($status->isOK()) { Hooks::run('FileDeleteComplete', [&$file, &$oldimage, &$page, &$user, &$reason]); } return $status; }