http://www.mediawiki.org/wiki/Special:Code/MediaWiki/84638
Revision: 84638
Author: laner
Date: 2011-03-23 21:54:59 +0000 (Wed, 23 Mar 2011)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/phase3/includes/Article.php
trunk/phase3/includes/FileDeleteForm.php
trunk/phase3/includes/api/ApiDelete.php
Modified: trunk/phase3/includes/Article.php
===================================================================
--- trunk/phase3/includes/Article.php 2011-03-23 21:52:41 UTC (rev 84637)
+++ trunk/phase3/includes/Article.php 2011-03-23 21:54:59 UTC (rev 84638)
@@ -3052,19 +3052,16 @@
$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 @@
* @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 @@
$dbw->commit();
}
+ wfRunHooks( 'ArticleDeleteComplete', array( &$this, &$wgUser,
$reason, $id ) );
return true;
}
Modified: trunk/phase3/includes/FileDeleteForm.php
===================================================================
--- trunk/phase3/includes/FileDeleteForm.php 2011-03-23 21:52:41 UTC (rev
84637)
+++ trunk/phase3/includes/FileDeleteForm.php 2011-03-23 21:54:59 UTC (rev
84638)
@@ -121,23 +121,21 @@
$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 ) {
// rollback before returning to prevent UI from
displaying incorrect "View or restore N deleted edits?"
Modified: trunk/phase3/includes/api/ApiDelete.php
===================================================================
--- trunk/phase3/includes/api/ApiDelete.php 2011-03-23 21:52:41 UTC (rev
84637)
+++ trunk/phase3/includes/api/ApiDelete.php 2011-03-23 21:54:59 UTC (rev
84638)
@@ -146,16 +146,12 @@
}
$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 @@
public function getVersion() {
return __CLASS__ . ': $Id$';
}
-}
\ No newline at end of file
+}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs