From 308203304d044933f470eb77f2ff4e4ef9fb2d62 Mon Sep 17 00:00:00 2001 From: Ryan Lane Date: Wed, 23 Mar 2011 21:54:59 +0000 Subject: [PATCH] Moving deletion hooks into doArticleDelete so that other code can sanely delete articles. Fixed other core code that was wrapping the calls with hook calls. --- includes/Article.php | 23 ++++++++++++----------- includes/FileDeleteForm.php | 30 ++++++++++++++---------------- includes/api/ApiDelete.php | 12 ++++-------- 3 files changed, 30 insertions(+), 35 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 560a26125f..3ce95b6c4b 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -3052,19 +3052,16 @@ class Article { $id = $this->mTitle->getArticleID( Title::GAID_FOR_UPDATE ); $error = ''; - if ( wfRunHooks( 'ArticleDelete', array( &$this, &$wgUser, &$reason, &$error ) ) ) { - if ( $this->doDeleteArticle( $reason, $suppress, $id ) ) { - $deleted = $this->mTitle->getPrefixedText(); + if ( $this->doDeleteArticle( $reason, $suppress, $id, &$error ) ) { + $deleted = $this->mTitle->getPrefixedText(); - $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) ); - $wgOut->setRobotPolicy( 'noindex,nofollow' ); + $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) ); + $wgOut->setRobotPolicy( 'noindex,nofollow' ); - $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]'; + $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]'; - $wgOut->addWikiMsg( 'deletedtext', $deleted, $loglink ); - $wgOut->returnToMain( false ); - wfRunHooks( 'ArticleDeleteComplete', array( &$this, &$wgUser, $reason, $id ) ); - } + $wgOut->addWikiMsg( 'deletedtext', $deleted, $loglink ); + $wgOut->returnToMain( false ); } else { if ( $error == '' ) { $wgOut->showFatalError( @@ -3102,11 +3099,14 @@ class Article { * @param $commit boolean defaults to true, triggers transaction end * @return boolean true if successful */ - public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true ) { + public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, $error='' ) { global $wgDeferredUpdateList, $wgUseTrackbacks; wfDebug( __METHOD__ . "\n" ); + if ( ! wfRunHooks( 'ArticleDelete', array( &$this, &$wgUser, &$reason, &$error ) ) ) { + return false; + } $dbw = wfGetDB( DB_MASTER ); $t = $this->mTitle->getDBkey(); $id = $id ? $id : $this->mTitle->getArticleID( Title::GAID_FOR_UPDATE ); @@ -3232,6 +3232,7 @@ class Article { $dbw->commit(); } + wfRunHooks( 'ArticleDeleteComplete', array( &$this, &$wgUser, $reason, $id ) ); return true; } diff --git a/includes/FileDeleteForm.php b/includes/FileDeleteForm.php index 030330bbeb..f77d6978c1 100644 --- a/includes/FileDeleteForm.php +++ b/includes/FileDeleteForm.php @@ -121,22 +121,20 @@ class FileDeleteForm { $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(); - } - $status = $file->delete( $reason, $suppress ); - if( $status->ok ) { - $dbw->commit(); - wfRunHooks( 'ArticleDeleteComplete', array( &$article, &$wgUser, $reason, $id ) ); - } else { - $dbw->rollback(); - } + // 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(); + } + $status = $file->delete( $reason, $suppress ); + if( $status->ok ) { + $dbw->commit(); + wfRunHooks( 'ArticleDeleteComplete', array( &$article, &$wgUser, $reason, $id ) ); + } else { + $dbw->rollback(); } } } catch ( MWException $e ) { diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php index 2f6ed2d351..d05723e5e0 100644 --- a/includes/api/ApiDelete.php +++ b/includes/api/ApiDelete.php @@ -146,16 +146,12 @@ class ApiDelete extends ApiBase { } $error = ''; - if ( !wfRunHooks( 'ArticleDelete', array( &$article, &$wgUser, &$reason, &$error ) ) ) { - return array( array( 'hookaborted', $error ) ); - } - // Luckily, Article.php provides a reusable delete function that does the hard work for us - if ( $article->doDeleteArticle( $reason ) ) { - wfRunHooks( 'ArticleDeleteComplete', array( &$article, &$wgUser, $reason, $article->getId() ) ); + if ( $article->doDeleteArticle( $reason, false, 0, true, &$error ) ) { return array(); + } else { + return array( array( 'cannotdelete', $article->mTitle->getPrefixedText() ) ); } - return array( array( 'cannotdelete', $article->mTitle->getPrefixedText() ) ); } /** @@ -284,4 +280,4 @@ class ApiDelete extends ApiBase { public function getVersion() { return __CLASS__ . ': $Id$'; } -} \ No newline at end of file +} -- 2.20.1