r84638 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84637‎ | r84638 | r84639 >
Date:21:54, 23 March 2011
Author:laner
Status:resolved (Comments)
Tags:
Comment:
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 (modified) (history)
  • /trunk/phase3/includes/FileDeleteForm.php (modified) (history)
  • /trunk/phase3/includes/api/ApiDelete.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -3052,19 +3052,16 @@
30533053 $id = $this->mTitle->getArticleID( Title::GAID_FOR_UPDATE );
30543054
30553055 $error = '';
3056 - if ( wfRunHooks( 'ArticleDelete', array( &$this, &$wgUser, &$reason, &$error ) ) ) {
3057 - if ( $this->doDeleteArticle( $reason, $suppress, $id ) ) {
3058 - $deleted = $this->mTitle->getPrefixedText();
 3056+ if ( $this->doDeleteArticle( $reason, $suppress, $id, &$error ) ) {
 3057+ $deleted = $this->mTitle->getPrefixedText();
30593058
3060 - $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
3061 - $wgOut->setRobotPolicy( 'noindex,nofollow' );
 3059+ $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
 3060+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
30623061
3063 - $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
 3062+ $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
30643063
3065 - $wgOut->addWikiMsg( 'deletedtext', $deleted, $loglink );
3066 - $wgOut->returnToMain( false );
3067 - wfRunHooks( 'ArticleDeleteComplete', array( &$this, &$wgUser, $reason, $id ) );
3068 - }
 3064+ $wgOut->addWikiMsg( 'deletedtext', $deleted, $loglink );
 3065+ $wgOut->returnToMain( false );
30693066 } else {
30703067 if ( $error == '' ) {
30713068 $wgOut->showFatalError(
@@ -3102,11 +3099,14 @@
31033100 * @param $commit boolean defaults to true, triggers transaction end
31043101 * @return boolean true if successful
31053102 */
3106 - public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true ) {
 3103+ public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, $error='' ) {
31073104 global $wgDeferredUpdateList, $wgUseTrackbacks;
31083105
31093106 wfDebug( __METHOD__ . "\n" );
31103107
 3108+ if ( ! wfRunHooks( 'ArticleDelete', array( &$this, &$wgUser, &$reason, &$error ) ) ) {
 3109+ return false;
 3110+ }
31113111 $dbw = wfGetDB( DB_MASTER );
31123112 $t = $this->mTitle->getDBkey();
31133113 $id = $id ? $id : $this->mTitle->getArticleID( Title::GAID_FOR_UPDATE );
@@ -3232,6 +3232,7 @@
32333233 $dbw->commit();
32343234 }
32353235
 3236+ wfRunHooks( 'ArticleDeleteComplete', array( &$this, &$wgUser, $reason, $id ) );
32363237 return true;
32373238 }
32383239
Index: trunk/phase3/includes/api/ApiDelete.php
@@ -146,16 +146,12 @@
147147 }
148148
149149 $error = '';
150 - if ( !wfRunHooks( 'ArticleDelete', array( &$article, &$wgUser, &$reason, &$error ) ) ) {
151 - return array( array( 'hookaborted', $error ) );
152 - }
153 -
154150 // Luckily, Article.php provides a reusable delete function that does the hard work for us
155 - if ( $article->doDeleteArticle( $reason ) ) {
156 - wfRunHooks( 'ArticleDeleteComplete', array( &$article, &$wgUser, $reason, $article->getId() ) );
 151+ if ( $article->doDeleteArticle( $reason, false, 0, true, &$error ) ) {
157152 return array();
 153+ } else {
 154+ return array( array( 'cannotdelete', $article->mTitle->getPrefixedText() ) );
158155 }
159 - return array( array( 'cannotdelete', $article->mTitle->getPrefixedText() ) );
160156 }
161157
162158 /**
@@ -284,4 +280,4 @@
285281 public function getVersion() {
286282 return __CLASS__ . ': $Id$';
287283 }
288 -}
\ No newline at end of file
 284+}
Index: trunk/phase3/includes/FileDeleteForm.php
@@ -121,23 +121,21 @@
122122 $error = '';
123123 $dbw = wfGetDB( DB_MASTER );
124124 try {
125 - if( wfRunHooks( 'ArticleDelete', array( &$article, &$wgUser, &$reason, &$error ) ) ) {
126 - // delete the associated article first
127 - if( $article->doDeleteArticle( $reason, $suppress, $id, false ) ) {
128 - global $wgRequest;
129 - if( $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn() ) {
130 - $article->doWatch();
131 - } elseif( $title->userIsWatching() ) {
132 - $article->doUnwatch();
133 - }
134 - $status = $file->delete( $reason, $suppress );
135 - if( $status->ok ) {
136 - $dbw->commit();
137 - wfRunHooks( 'ArticleDeleteComplete', array( &$article, &$wgUser, $reason, $id ) );
138 - } else {
139 - $dbw->rollback();
140 - }
 125+ // delete the associated article first
 126+ if( $article->doDeleteArticle( $reason, $suppress, $id, false ) ) {
 127+ global $wgRequest;
 128+ if( $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn() ) {
 129+ $article->doWatch();
 130+ } elseif( $title->userIsWatching() ) {
 131+ $article->doUnwatch();
141132 }
 133+ $status = $file->delete( $reason, $suppress );
 134+ if( $status->ok ) {
 135+ $dbw->commit();
 136+ wfRunHooks( 'ArticleDeleteComplete', array( &$article, &$wgUser, $reason, $id ) );
 137+ } else {
 138+ $dbw->rollback();
 139+ }
142140 }
143141 } catch ( MWException $e ) {
144142 // rollback before returning to prevent UI from displaying incorrect "View or restore N deleted edits?"

Follow-up revisions

RevisionCommit summaryAuthorDate
r84642Removing pass by reference, and making the $error argument for doDeleteArticl...laner22:13, 23 March 2011
r84712Follow up to r84638. Moving the $wgUser global, and fixing formatting.laner21:32, 24 March 2011
r89345Fix regression in r84638, causing ArticleDeleteComplete to be called twice on...catrope15:42, 2 June 2011

Comments

#Comment by IAlex (talk | contribs)   22:04, 23 March 2011

Be sure to enable reporting for all error types in your PHP configuration; I'm getting this now:

Deprecated: Call-time pass-by-reference has been deprecated in includes/Article.php on line 3055

#Comment by Platonides (talk | contribs)   21:25, 24 March 2011

You forgot to move the global $wgUser:

Unused global $wgUser in function doDelete line 3050
$wgUser is used as local variable in line 3107, function doDeleteArticle
$wgUser is used as local variable in line 3235, function doDeleteArticle

Place spaces surrounding the = of $error.

Status & tagging log