- $status = $file->delete( $reason, $suppress );
- if( $status->ok ) {
- $id = $title->getArticleID( GAID_FOR_UPDATE );
- // Need to delete the associated article
- $article = new Article( $title );
- if( wfRunHooks('ArticleDelete', array(&$article, &$wgUser, &$reason)) ) {
- if( $article->doDeleteArticle( $reason, $suppress, $id ) )
- wfRunHooks('ArticleDeleteComplete', array(&$article, &$wgUser, $reason, $id));
+ $id = $title->getArticleID( Title::GAID_FOR_UPDATE );
+ $article = new Article( $title );
+ $dbw = wfGetDB( DB_MASTER );
+ try {
+ // delete the associated article first
+ if( $article->doDeleteArticle( $reason, $suppress, $id, false ) ) {
+ global $wgRequest;
+ if ( $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn() ) {
+ WatchAction::doWatch( $title, $wgUser );
+ } elseif ( $title->userIsWatching() ) {
+ WatchAction::doUnwatch( $title, $wgUser );
+ }
+ $status = $file->delete( $reason, $suppress );
+ if( $status->ok ) {
+ $dbw->commit();
+ } else {
+ $dbw->rollback();
+ }