* Add higher level newRevisionFromEditComplete hook
authorAaron Schulz <aaron@users.mediawiki.org>
Sat, 17 May 2008 17:53:46 +0000 (17:53 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Sat, 17 May 2008 17:53:46 +0000 (17:53 +0000)
* 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

docs/hooks.txt
includes/Article.php
includes/SpecialImport.php
includes/Title.php
includes/filerepo/ICRepo.php
includes/filerepo/LocalFile.php

index 70ff967..03dfd42 100644 (file)
@@ -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 
index cef4470..263e939 100644 (file)
@@ -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();
 
index 76bd646..3e7b5be 100644 (file)
@@ -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 );
index fbbbc79..e1422f4 100644 (file)
@@ -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
index 805dc02..e0ef340 100644 (file)
@@ -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
index f96d171..6258ef0 100644 (file)
@@ -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