Add $visibilityChangeMap parameter to RevDelList doPostCommitUpdates
authorAndrew Otto <acotto@gmail.com>
Fri, 10 Jun 2016 20:07:34 +0000 (16:07 -0400)
committerAndrew Otto <acotto@gmail.com>
Wed, 6 Jul 2016 14:36:08 +0000 (10:36 -0400)
This paramater contains a map of id => old and new visibility bits.
This allows doPostCommitUpdates to do something useful with the
differences before and after a visibility change.  Specifically,
RevDelRevisionList doPostCommitUpdates passes this to the
ArticleRevisionVisibilitySet hook.

Bug: T137287
Change-Id: I1824f56d2aadc15671c442cf30dc1f9f01e821f8

docs/hooks.txt
includes/revisiondelete/RevDelArchiveList.php
includes/revisiondelete/RevDelFileList.php
includes/revisiondelete/RevDelList.php
includes/revisiondelete/RevDelRevisionList.php

index f9f8333..af4dddb 100644 (file)
@@ -683,6 +683,10 @@ $oldPageID: the page ID of the revision when archived (may be null)
 revisions of an article.
 $title: Title object of the article
 $ids: Ids to set the visibility for
+$visibilityChangeMap: Map of revision id to oldBits and newBits.  This array can be
+  examined to determine exactly what visibility bits have changed for each
+  revision.  This array is of the form
+  [id => ['oldBits' => $oldBits, 'newBits' => $newBits], ... ]
 
 'ArticleRollbackComplete': After an article rollback is completed.
 $wikiPage: the WikiPage that was edited
index 72c460e..ad9259b 100644 (file)
@@ -77,7 +77,7 @@ class RevDelArchiveList extends RevDelRevisionList {
                return Status::newGood();
        }
 
-       public function doPostCommitUpdates() {
+       public function doPostCommitUpdates( array $visibilityChangeMap ) {
                return Status::newGood();
        }
 }
index 75e1885..00cb2e1 100644 (file)
@@ -104,7 +104,7 @@ class RevDelFileList extends RevDelList {
                return $status;
        }
 
-       public function doPostCommitUpdates() {
+       public function doPostCommitUpdates( array $visibilityChangeMap ) {
                $file = wfLocalFile( $this->title );
                $file->purgeCache();
                $file->purgeDescription();
index 87e641d..0a86e94 100644 (file)
@@ -132,6 +132,10 @@ abstract class RevDelList extends RevisionListBase {
                $virtualNewBits = 0;
                $logType = 'delete';
 
+               // Will be filled with id => [old, new bits] information and
+               // passed to doPostCommitUpdates().
+               $visibilityChangeMap = [];
+
                // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
                for ( $this->reset(); $this->current(); $this->next() ) {
                        // @codingStandardsIgnoreEnd
@@ -205,6 +209,13 @@ abstract class RevDelList extends RevisionListBase {
                                } elseif ( IP::isIPAddress( $item->getAuthorName() ) ) {
                                        $authorIPs[] = $item->getAuthorName();
                                }
+
+                               // Save the old and new bits in $visibilityChangeMap for
+                               // later use.
+                               $visibilityChangeMap[$item->getId()] = [
+                                       'oldBits' => $oldBits,
+                                       'newBits' => $newBits,
+                               ];
                        } else {
                                $itemStatus->error(
                                        'revdelete-concurrent-change', $item->formatDate(), $item->formatTime() );
@@ -255,8 +266,8 @@ abstract class RevDelList extends RevisionListBase {
 
                // Clear caches
                $that = $this;
-               $dbw->onTransactionIdle( function() use ( $that ) {
-                       $that->doPostCommitUpdates();
+               $dbw->onTransactionIdle( function() use ( $that, $visibilityChangeMap ) {
+                       $that->doPostCommitUpdates( $visibilityChangeMap );
                } );
 
                $dbw->endAtomic( __METHOD__ );
@@ -351,9 +362,10 @@ abstract class RevDelList extends RevisionListBase {
        /**
         * A hook for setVisibility(): do any necessary updates post-commit.
         * STUB
+        * @param array [id => ['oldBits' => $oldBits, 'newBits' => $newBits], ... ]
         * @return Status
         */
-       public function doPostCommitUpdates() {
+       public function doPostCommitUpdates( array $visibilityChangeMap ) {
                return Status::newGood();
        }
 
index 27e5148..3486645 100644 (file)
@@ -170,10 +170,10 @@ class RevDelRevisionList extends RevDelList {
                return Status::newGood();
        }
 
-       public function doPostCommitUpdates() {
+       public function doPostCommitUpdates( array $visibilityChangeMap ) {
                $this->title->purgeSquid();
                // Extensions that require referencing previous revisions may need this
-               Hooks::run( 'ArticleRevisionVisibilitySet', [ $this->title, $this->ids ] );
+               Hooks::run( 'ArticleRevisionVisibilitySet', [ $this->title, $this->ids, $visibilityChangeMap ] );
                return Status::newGood();
        }
 }