From: Aaron Schulz Date: Sat, 17 May 2008 17:53:46 +0000 (+0000) Subject: * Add higher level newRevisionFromEditComplete hook X-Git-Tag: 1.31.0-rc.0~47571 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=7c2c02953c3afe01f147e533e8d107fe823edb3e;p=lhc%2Fweb%2Fwiklou.git * Add higher level newRevisionFromEditComplete hook * Use this hook for autoreviewing. Merge to one function again. * Remove template ID query for $usestabletemplates, not needed * Improve includes change diff if $usestabletemplates is on --- diff --git a/docs/hooks.txt b/docs/hooks.txt index 70ff967bf7..03dfd425a4 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -800,6 +800,11 @@ for all 'SkinTemplate'-type skins, use the SkinTemplateToolboxEnd hook instead. $tools: array of tools +'newRevisionFromEditComplete': called when a revision was inserted due to an edit +$title: the page title +$rev: the new revision +$baseID: the revision ID this was based off, if any + 'OutputPageBeforeHTML': a page has been processed by the parser and the resulting HTML is about to be displayed. $parserOutput: the parserOutput (object) that corresponds to the page diff --git a/includes/Article.php b/includes/Article.php index cef4470b9e..263e939b48 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1362,10 +1362,11 @@ class Article { * EDIT_NEW is specified and the article does exist, a duplicate key error will cause an exception * to be thrown from the Database. These two conditions are also possible with auto-detection due * to MediaWiki's performance-optimised locking strategy. + * @param $baseRevId, the revision ID this edit was based off, if any * * @return bool success */ - function doEdit( $text, $summary, $flags = 0 ) { + function doEdit( $text, $summary, $flags = 0, $baseRevId = false ) { global $wgUser, $wgDBtransactions; wfProfileIn( __METHOD__ ); @@ -1445,6 +1446,8 @@ class Article { $dbw->begin(); $revisionId = $revision->insertOn( $dbw ); + + wfRunHooks( 'newRevisionFromEditComplete', array($this->mTitle, $revision, $baseRevId) ); # Update page $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision ); @@ -1513,6 +1516,8 @@ class Article { 'text' => $text ) ); $revisionId = $revision->insertOn( $dbw ); + + wfRunHooks( 'newRevisionFromEditComplete', array($this->mTitle, $revision, false) ); $this->mTitle->resetArticleID( $newid ); @@ -1865,6 +1870,8 @@ class Article { # Insert a null revision $nullRevision = Revision::newNullRevision( $dbw, $id, $comment, true ); $nullRevId = $nullRevision->insertOn( $dbw ); + + wfRunHooks( 'newRevisionFromEditComplete', array($this->mTitle, $nullRevision, false) ); # Update page record $dbw->update( 'page', @@ -2524,7 +2531,7 @@ class Article { if( $bot && ($wgUser->isAllowed('markbotedits') || $wgUser->isAllowed('bot')) ) $flags |= EDIT_FORCE_BOT; - $this->doEdit( $target->getText(), $summary, $flags ); + $this->doEdit( $target->getText(), $summary, $flags, $target->getId() ); wfRunHooks( 'ArticleRollbackComplete', array( $this, $wgUser, $target ) ); @@ -2967,6 +2974,7 @@ class Article { 'minor_edit' => $minor ? 1 : 0, ) ); $revision->insertOn( $dbw ); + wfRunHooks( 'newRevisionFromEditComplete', array($this->mTitle, $revision, false) ); $this->updateRevisionOn( $dbw, $revision ); $dbw->commit(); diff --git a/includes/SpecialImport.php b/includes/SpecialImport.php index 76bd646ab5..3e7b5be3ad 100644 --- a/includes/SpecialImport.php +++ b/includes/SpecialImport.php @@ -216,9 +216,9 @@ class ImportReporter { $comment = $detail; // quick $dbw = wfGetDB( DB_MASTER ); - $nullRevision = Revision::newNullRevision( - $dbw, $title->getArticleId(), $comment, true ); + $nullRevision = Revision::newNullRevision( $dbw, $title->getArticleId(), $comment, true ); $nullRevision->insertOn( $dbw ); + wfRunHooks( 'newRevisionFromEditComplete', array($title, $nullRevision, false) ); # Update page record $article = new Article( $title ); $article->updateRevisionOn( $dbw, $nullRevision ); diff --git a/includes/Title.php b/includes/Title.php index fbbbc798a8..e1422f4b61 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2599,6 +2599,7 @@ class Title { # Save a null revision in the page's history notifying of the move $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true ); $nullRevId = $nullRevision->insertOn( $dbw ); + wfRunHooks( 'newRevisionFromEditComplete', array($nt, $nullRevision, false) ); # Change the name of the target page: $dbw->update( 'page', @@ -2625,6 +2626,7 @@ class Title { 'comment' => $comment, 'text' => $redirectText ) ); $redirectRevision->insertOn( $dbw ); + wfRunHooks( 'newRevisionFromEditComplete', array($this, $redirectRevision, false) ); $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 ); # Now, we record the link from the redirect to the new title. @@ -2686,6 +2688,7 @@ class Title { # Save a null revision in the page's history notifying of the move $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true ); $nullRevId = $nullRevision->insertOn( $dbw ); + wfRunHooks( 'newRevisionFromEditComplete', array($nt, $nullRevision, false) ); # Rename page entry $dbw->update( 'page', @@ -2712,6 +2715,7 @@ class Title { 'comment' => $comment, 'text' => $redirectText ) ); $redirectRevision->insertOn( $dbw ); + wfRunHooks( 'newRevisionFromEditComplete', array($this, $redirectRevision, false) ); $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 ); # Record the just-created redirect's linking to the page diff --git a/includes/filerepo/ICRepo.php b/includes/filerepo/ICRepo.php index 805dc02ccf..e0ef3401ed 100644 --- a/includes/filerepo/ICRepo.php +++ b/includes/filerepo/ICRepo.php @@ -286,6 +286,7 @@ class ICFile extends LocalFile{ # Create a null revision $nullRevision = Revision::newNullRevision( $dbw, $descTitle->getArticleId(), $log->getRcComment(), false ); $nullRevision->insertOn( $dbw ); + wfRunHooks( 'newRevisionFromEditComplete', array($descTitle, $nullRevision, false) ); $article->updateRevisionOn( $dbw, $nullRevision ); # Invalidate the cache for the description page diff --git a/includes/filerepo/LocalFile.php b/includes/filerepo/LocalFile.php index f96d171870..6258ef0ef4 100644 --- a/includes/filerepo/LocalFile.php +++ b/includes/filerepo/LocalFile.php @@ -859,6 +859,7 @@ class LocalFile extends File # Create a null revision $nullRevision = Revision::newNullRevision( $dbw, $descTitle->getArticleId(), $log->getRcComment(), false ); $nullRevision->insertOn( $dbw ); + wfRunHooks( 'newRevisionFromEditComplete', array($descTitle, $nullRevision, false) ); $article->updateRevisionOn( $dbw, $nullRevision ); # Invalidate the cache for the description page