Moving deletion hooks into doArticleDelete so that other code can sanely delete artic...
authorRyan Lane <laner@users.mediawiki.org>
Wed, 23 Mar 2011 21:54:59 +0000 (21:54 +0000)
committerRyan Lane <laner@users.mediawiki.org>
Wed, 23 Mar 2011 21:54:59 +0000 (21:54 +0000)
includes/Article.php
includes/FileDeleteForm.php
includes/api/ApiDelete.php

index 560a261..3ce95b6 100644 (file)
@@ -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;
        }
 
index 030330b..f77d697 100644 (file)
@@ -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 ) {
index 2f6ed2d..d05723e 100644 (file)
@@ -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
+}