From bfd17608dbe1c6911dfce965b2fc7b2c9c25bc16 Mon Sep 17 00:00:00 2001 From: Happy-melon Date: Tue, 25 May 2010 16:40:02 +0000 Subject: [PATCH] (bug 23641) refactor code around Article::doEdit(), and restored access to watch/unwatch settings to ArticleSaveComplete hook, removed in r14834 AFAICT. Patch by Tisane. --- CREDITS | 1 + includes/Article.php | 91 ++++++++++++++++++++++---------------------- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/CREDITS b/CREDITS index 2db17bf12e..de7adc2e48 100644 --- a/CREDITS +++ b/CREDITS @@ -125,6 +125,7 @@ following names for their contribution to the product. * Stefano Codari * Str4nd * svip +* Tisane * Zachary Hauri == Translators == diff --git a/includes/Article.php b/includes/Article.php index a747f25049..629574488d 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1811,28 +1811,8 @@ class Article { ( $suppressRC ? EDIT_SUPPRESS_RC : 0 ) | ( $bot ? EDIT_FORCE_BOT : 0 ); - # If this is a comment, add the summary as headline - if ( $comment && $summary != "" ) { - $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $summary ) . "\n\n" . $text; - } + $this->doEdit( $text, $summary, $flags, false, null, $watchthis, $comment, '', true ); - $this->doEdit( $text, $summary, $flags ); - - $dbw = wfGetDB( DB_MASTER ); - if ( $watchthis ) { - if ( !$this->mTitle->userIsWatching() ) { - $dbw->begin(); - $this->doWatch(); - $dbw->commit(); - } - } else { - if ( $this->mTitle->userIsWatching() ) { - $dbw->begin(); - $this->doUnwatch(); - $dbw->commit(); - } - } - $this->doRedirect( $this->isRedirect( $text ) ); } /** @@ -1843,30 +1823,11 @@ class Article { ( $minor ? EDIT_MINOR : 0 ) | ( $forceBot ? EDIT_FORCE_BOT : 0 ); - $status = $this->doEdit( $text, $summary, $flags ); + $status = $this->doEdit( $text, $summary, $flags, false, null, $watchthis, false, $sectionanchor, true ); if ( !$status->isOK() ) { return false; } - $dbw = wfGetDB( DB_MASTER ); - if ( $watchthis ) { - if ( !$this->mTitle->userIsWatching() ) { - $dbw->begin(); - $this->doWatch(); - $dbw->commit(); - } - } else { - if ( $this->mTitle->userIsWatching() ) { - $dbw->begin(); - $this->doUnwatch(); - $dbw->commit(); - } - } - - $extraQuery = ''; // Give extensions a chance to modify URL query on update - wfRunHooks( 'ArticleUpdateBeforeRedirect', array( $this, &$sectionanchor, &$extraQuery ) ); - - $this->doRedirect( $this->isRedirect( $text ), $sectionanchor, $extraQuery ); return true; } @@ -1920,6 +1881,10 @@ class Article { * * @param $baseRevId the revision ID this edit was based off, if any * @param $user Optional user object, $wgUser will be used if not passed + * @param $watchthis Watch the page if true, unwatch the page if false, do nothing if null + * @param $sectionanchor The section anchor for the page; used for redirecting the user back to the page + * after the edit is successfully committed + * @param $redirect If true, redirect the user back to the page after the edit is successfully committed * * @return Status object. Possible errors: * edit-hook-aborted: The ArticleSave hook aborted the edit but didn't set the fatal flag of $status @@ -1936,7 +1901,8 @@ class Article { * * Compatibility note: this function previously returned a boolean value indicating success/failure */ - public function doEdit( $text, $summary, $flags = 0, $baseRevId = false, $user = null ) { + public function doEdit( $text, $summary, $flags = 0, $baseRevId = false, $user = null , $watchthis = null, + $comment = false, $sectionanchor = '', $redirect = false) { global $wgUser, $wgDBtransactions, $wgUseAutomaticEditSummaries; # Low-level sanity check @@ -1953,9 +1919,14 @@ class Article { $this->loadPageData(); $flags = $this->checkFlags( $flags ); + + # If this is a comment, add the summary as headline + if ( $comment && $summary != "" ) { + $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $summary ) . "\n\n" . $text; + } if ( !wfRunHooks( 'ArticleSave', array( &$this, &$user, &$text, &$summary, - $flags & EDIT_MINOR, null, null, &$flags, &$status ) ) ) + $flags & EDIT_MINOR, &$watchthis, null, &$flags, &$status) ) ) { wfDebug( __METHOD__ . ": ArticleSave hook aborted save!\n" ); wfProfileOut( __METHOD__ ); @@ -2085,6 +2056,9 @@ class Article { Article::onArticleEdit( $this->mTitle ); # Update links tables, site stats, etc. $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, $changed ); + + $extraQuery = ''; # Give extensions a chance to modify URL query on update + wfRunHooks( 'ArticleUpdateBeforeRedirect', array( $this, &$sectionanchor, &$extraQuery ) ); } else { # Create new article $status->value['new'] = true; @@ -2148,7 +2122,7 @@ class Article { Article::onArticleCreate( $this->mTitle ); wfRunHooks( 'ArticleInsertComplete', array( &$this, &$user, $text, $summary, - $flags & EDIT_MINOR, null, null, &$flags, $revision ) ); + $flags & EDIT_MINOR, &$watchthis, null, &$flags, $revision ) ); } # Do updates right now unless deferral was requested @@ -2160,9 +2134,34 @@ class Article { $status->value['revision'] = $revision; wfRunHooks( 'ArticleSaveComplete', array( &$this, &$user, $text, $summary, - $flags & EDIT_MINOR, null, null, &$flags, $revision, &$status, $baseRevId ) ); - + $flags & EDIT_MINOR, &$watchthis, null, &$flags, $revision, &$status, $baseRevId, + &$redirect) ); + + # Watch or unwatch the page + if ( $watchthis == true) { + if ( !$this->mTitle->userIsWatching() ) { + $dbw->begin(); + $this->doWatch(); + $dbw->commit(); + } + } elseif ($watchthis == false) { + if ( $this->mTitle->userIsWatching() ) { + $dbw->begin(); + $this->doUnwatch(); + $dbw->commit(); + } + } + + if ( $redirect ) { + if ( $sectionanchor || $extraQuery ) { + $this->doRedirect( $this->isRedirect( $text ), $sectionanchor, $extraQuery ); + } else { + $this->doRedirect( $this->isRedirect( $text ) ); + } + } + wfProfileOut( __METHOD__ ); + return $status; } -- 2.20.1