X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FFileDeleteForm.php;h=be11821c2125718b33bd86d04fc8181fae8ed47f;hb=44a950288a78c7cb89286271c068c2578865e0b3;hp=b2620c3ba13a721aebc3b6577db5baddb5992289;hpb=ce47c67697f01041ee08ed3d7632ff27d59b780a;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/FileDeleteForm.php b/includes/FileDeleteForm.php index b2620c3ba1..be11821c21 100644 --- a/includes/FileDeleteForm.php +++ b/includes/FileDeleteForm.php @@ -17,7 +17,7 @@ class FileDeleteForm { /** * Constructor * - * @param File $file File we're deleting + * @param $file File object we're deleting */ public function __construct( $file ) { $this->title = $file->getTitle(); @@ -90,8 +90,20 @@ class FileDeleteForm { $this->showLogEntries(); } + /** + * Really delete the file + * + * @param $title Title object + * @param $file File object + * @param $oldimage String: archive name + * @param $reason String: reason of the deletion + * @param $suppress Boolean: whether to mark all deleted versions as restricted + */ 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 ) { @@ -103,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' ) ) { + 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() ) @@ -173,14 +195,18 @@ class FileDeleteForm { array( 'type' => 'text', 'maxlength' => '255', 'tabindex' => '2', 'id' => 'wpReason' ) ) . " - {$suppress} + {$suppress}"; + if( $wgUser->isLoggedIn() ) { + $form .= " " . Xml::checkLabel( wfMsg( 'watchthis' ), 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) . " - + "; + } + $form .= " " . @@ -221,8 +247,8 @@ class FileDeleteForm { * showing an appropriate message depending upon whether * it's a current file or an old version * - * @param string $message Message base - * @return string + * @param $message String: message base + * @return String */ private function prepareMessage( $message ) { global $wgLang;