summaryrefslogtreecommitdiff
path: root/includes/FileDeleteForm.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/FileDeleteForm.php')
-rw-r--r--includes/FileDeleteForm.php38
1 files changed, 25 insertions, 13 deletions
diff --git a/includes/FileDeleteForm.php b/includes/FileDeleteForm.php
index dad19524..030330bb 100644
--- a/includes/FileDeleteForm.php
+++ b/includes/FileDeleteForm.php
@@ -102,34 +102,47 @@ class FileDeleteForm {
public static function doDelete( &$title, &$file, &$oldimage, $reason, $suppress ) {
global $wgUser;
$article = null;
+ $status = Status::newFatal( 'error' );
+
if( $oldimage ) {
$status = $file->deleteOld( $oldimage, $reason, $suppress );
if( $status->ok ) {
// Need to do a log item
$log = new LogPage( 'delete' );
$logComment = wfMsgForContent( 'deletedrevision', $oldimage );
- if( trim( $reason ) != '' )
+ if( trim( $reason ) != '' ) {
$logComment .= wfMsgForContent( 'colon-separator' ) . $reason;
- $log->addEntry( 'delete', $title, $logComment );
+ }
+ $log->addEntry( 'delete', $title, $logComment );
}
} else {
- $status = $file->delete( $reason, $suppress );
- if( $status->ok ) {
- $id = $title->getArticleID( GAID_FOR_UPDATE );
- // Need to delete the associated article
- $article = new Article( $title );
- $error = '';
- if( wfRunHooks('ArticleDelete', array(&$article, &$wgUser, &$reason, &$error)) ) {
- if( $article->doDeleteArticle( $reason, $suppress, $id ) ) {
+ $id = $title->getArticleID( Title::GAID_FOR_UPDATE );
+ $article = new Article( $title );
+ $error = '';
+ $dbw = wfGetDB( DB_MASTER );
+ try {
+ if( wfRunHooks( 'ArticleDelete', array( &$article, &$wgUser, &$reason, &$error ) ) ) {
+ // delete the associated article first
+ if( $article->doDeleteArticle( $reason, $suppress, $id, false ) ) {
global $wgRequest;
if( $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn() ) {
$article->doWatch();
} elseif( $title->userIsWatching() ) {
$article->doUnwatch();
}
- wfRunHooks('ArticleDeleteComplete', array(&$article, &$wgUser, $reason, $id));
+ $status = $file->delete( $reason, $suppress );
+ if( $status->ok ) {
+ $dbw->commit();
+ wfRunHooks( 'ArticleDeleteComplete', array( &$article, &$wgUser, $reason, $id ) );
+ } else {
+ $dbw->rollback();
+ }
}
}
+ } catch ( MWException $e ) {
+ // rollback before returning to prevent UI from displaying incorrect "View or restore N deleted edits?"
+ $dbw->rollback();
+ throw $e;
}
}
if( $status->isGood() )
@@ -161,7 +174,7 @@ class FileDeleteForm {
'id' => 'mw-img-deleteconfirm' ) ) .
Xml::openElement( 'fieldset' ) .
Xml::element( 'legend', null, wfMsg( 'filedelete-legend' ) ) .
- Xml::hidden( 'wpEditToken', $wgUser->editToken( $this->oldimage ) ) .
+ Html::hidden( 'wpEditToken', $wgUser->editToken( $this->oldimage ) ) .
$this->prepareMessage( 'filedelete-intro' ) .
Xml::openElement( 'table', array( 'id' => 'mw-img-deleteconfirm-table' ) ) .
"<tr>
@@ -241,7 +254,6 @@ class FileDeleteForm {
private function prepareMessage( $message ) {
global $wgLang;
if( $this->oldimage ) {
- $url = $this->file->getArchiveUrl( $this->oldimage );
return wfMsgExt(
"{$message}-old", # To ensure grep will find them: 'filedelete-intro-old', 'filedelete-nofile-old', 'filedelete-success-old'
'parse',