]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blobdiff - includes/FileDeleteForm.php
MediaWiki 1.17.0
[autoinstalls/mediawiki.git] / includes / FileDeleteForm.php
index dad19524c3b39d2dc71586d72909883a0c885a46..030330bbeb10c285ba8beb038879b90d2d79a94c 100644 (file)
@@ -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',