I've gone and done something naughty. I've just bumped $wgVersion
[lhc/web/wiklou.git] / includes / FileDeleteForm.php
index dad1952..be11821 100644 (file)
@@ -102,6 +102,8 @@ 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 ) {
@@ -113,23 +115,33 @@ class FileDeleteForm {
                                        $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( 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() )