From 72f4bd3dad0df6097a84369e0826e010e7a86389 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 23 Aug 2005 08:15:14 +0000 Subject: [PATCH] * Move ArticleSave hook execution into Article insert/update functions, so they get called on non-EditPage actions that use these functions to create or update pages. --- RELEASE-NOTES | 3 +++ includes/Article.php | 23 +++++++++++++++++++++++ includes/EditPage.php | 40 ++++++++++++---------------------------- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 1a2d7ef738..9a6c466d2a 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -45,6 +45,9 @@ Misc work going on..... * (bug 3218) Use proper quoting on history Compare Revisions button * (bug 3220) Fix escaping of block URLs in Recentchanges * (bug 3227) Fix SQL injection introduced in experimental code +* Move ArticleSave hook execution into Article insert/update functions, + so they get called on non-EditPage actions that use these functions + to create or update pages. === Caveats === diff --git a/includes/Article.php b/includes/Article.php index 887393fb75..87bda1de85 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1037,6 +1037,13 @@ class Article { $fname = 'Article::insertNewArticle'; wfProfileIn( $fname ); + if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text, + &$summary, &$isminor, &$watchthis, NULL ) ) ) { + wfDebug( "$fname: ArticleSave hook aborted save!\n" ); + wfProfileOut( $fname ); + return false; + } + $this->mGoodAdjustment = $this->isCountable( $text ); $this->mTotalAdjustment = 1; @@ -1097,6 +1104,10 @@ class Article { $oldid = 0; # new article $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid ); + + wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text, + $summary, $isminor, + $watchthis, NULL ) ); wfProfileOut( $fname ); } @@ -1205,6 +1216,14 @@ class Article { wfProfileIn( $fname ); $good = true; + if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text, + &$summary, &$minor, + &$watchthis, &$sectionanchor ) ) ) { + wfDebug( "$fname: ArticleSave hook aborted save!\n" ); + wfProfileOut( $fname ); + return false; + } + $isminor = ( $minor && $wgUser->isLoggedIn() ); if ( $this->isRedirect( $text ) ) { # Remove all content but redirect @@ -1326,6 +1345,10 @@ class Article { $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision ); } + wfRunHooks( 'ArticleSaveComplete', + array( &$this, &$wgUser, $text, + $summary, $minor, + $watchthis, $sectionanchor ) ); wfProfileOut( $fname ); return $good; } diff --git a/includes/EditPage.php b/includes/EditPage.php index df6d3a29cd..13242a0e24 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -485,17 +485,11 @@ class EditPage { wfProfileOut( $fname ); return false; } - if (wfRunHooks('ArticleSave', array(&$this->mArticle, &$wgUser, &$this->textbox1, - &$this->summary, &$this->minoredit, &$this->watchthis, NULL))) - { - - $isComment=($this->section=='new'); - $this->mArticle->insertNewArticle( $this->textbox1, $this->summary, - $this->minoredit, $this->watchthis, false, $isComment); - wfRunHooks('ArticleSaveComplete', array(&$this->mArticle, &$wgUser, $this->textbox1, - $this->summary, $this->minoredit, - $this->watchthis, NULL)); - } + + $isComment=($this->section=='new'); + $this->mArticle->insertNewArticle( $this->textbox1, $this->summary, + $this->minoredit, $this->watchthis, false, $isComment); + wfProfileOut( $fname ); return false; } @@ -574,23 +568,13 @@ class EditPage { $this->textbox1 = $text; $this->section = ''; - if (wfRunHooks('ArticleSave', array(&$this->mArticle, &$wgUser, &$text, - &$this->summary, &$this->minoredit, - &$this->watchthis, &$sectionanchor))) - { - # update the article here - if($this->mArticle->updateArticle( $text, $this->summary, $this->minoredit, - $this->watchthis, '', $sectionanchor )) - { - wfRunHooks('ArticleSaveComplete', - array(&$this->mArticle, &$wgUser, $text, - $this->summary, $this->minoredit, - $this->watchthis, $sectionanchor)); - wfProfileOut( $fname ); - return false; - } else { - $this->isConflict = true; - } + # update the article here + if( $this->mArticle->updateArticle( $text, $this->summary, $this->minoredit, + $this->watchthis, '', $sectionanchor ) ) { + wfProfileOut( $fname ); + return false; + } else { + $this->isConflict = true; } wfProfileOut( $fname ); return true; -- 2.20.1