From: Andrew Otto Date: Fri, 10 Jun 2016 20:07:34 +0000 (-0400) Subject: Add $visibilityChangeMap parameter to RevDelList doPostCommitUpdates X-Git-Tag: 1.31.0-rc.0~6448 X-Git-Url: http://git.cyclocoop.org/ecrire?a=commitdiff_plain;h=ee75aa9bee3ea8b1c446795138f05d9ef7d08f79;p=lhc%2Fweb%2Fwiklou.git Add $visibilityChangeMap parameter to RevDelList doPostCommitUpdates 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 --- diff --git a/docs/hooks.txt b/docs/hooks.txt index f9f833356a..af4dddbc74 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -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 diff --git a/includes/revisiondelete/RevDelArchiveList.php b/includes/revisiondelete/RevDelArchiveList.php index 72c460e0db..ad9259b307 100644 --- a/includes/revisiondelete/RevDelArchiveList.php +++ b/includes/revisiondelete/RevDelArchiveList.php @@ -77,7 +77,7 @@ class RevDelArchiveList extends RevDelRevisionList { return Status::newGood(); } - public function doPostCommitUpdates() { + public function doPostCommitUpdates( array $visibilityChangeMap ) { return Status::newGood(); } } diff --git a/includes/revisiondelete/RevDelFileList.php b/includes/revisiondelete/RevDelFileList.php index 75e1885b0c..00cb2e147c 100644 --- a/includes/revisiondelete/RevDelFileList.php +++ b/includes/revisiondelete/RevDelFileList.php @@ -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(); diff --git a/includes/revisiondelete/RevDelList.php b/includes/revisiondelete/RevDelList.php index 87e641db54..0a86e943d8 100644 --- a/includes/revisiondelete/RevDelList.php +++ b/includes/revisiondelete/RevDelList.php @@ -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(); } diff --git a/includes/revisiondelete/RevDelRevisionList.php b/includes/revisiondelete/RevDelRevisionList.php index 27e5148611..3486645c05 100644 --- a/includes/revisiondelete/RevDelRevisionList.php +++ b/includes/revisiondelete/RevDelRevisionList.php @@ -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(); } }