revisiondelete: Fix $oldBits/$newBits usage in setVisibility()
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 27 May 2016 21:58:10 +0000 (14:58 -0700)
committerKrinkle <krinklemail@gmail.com>
Fri, 3 Jun 2016 23:04:27 +0000 (23:04 +0000)
This addresses the FIXME comment around updateLog()

Change-Id: Iedb9df0b4cf65308a6b58bd9d9295d1850bc2c28

includes/logging/DeleteLogFormatter.php
includes/revisiondelete/RevDelList.php

index f9b7875..c205626 100644 (file)
@@ -61,6 +61,7 @@ class DeleteLogFormatter extends LogFormatter {
                                        && in_array( $params[3], [ 'revision', 'archive', 'oldimage', 'filearchive' ] )
                                )
                        ) {
+                               // See RevDelList::getLogParams()/RevDelLogList::getLogParams()
                                $paramStart = $subtype === 'revision' ? 4 : 3;
 
                                $old = $this->parseBitField( $params[$paramStart + 1] );
index 79d66a9..87e641d 100644 (file)
@@ -125,7 +125,13 @@ abstract class RevDelList extends RevisionListBase {
                        $status->itemStatuses = [];
                }
 
+               // For multi-item deletions, set the old/new bitfields in log_params such that "hid X"
+               // shows in logs if field X was hidden from ANY item and likewise for "unhid Y". Note the
+               // form does not let the same field get hidden and unhidden in different items at once.
+               $virtualOldBits = 0;
+               $virtualNewBits = 0;
                $logType = 'delete';
+
                // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
                for ( $this->reset(); $this->current(); $this->next() ) {
                        // @codingStandardsIgnoreEnd
@@ -187,6 +193,11 @@ abstract class RevDelList extends RevisionListBase {
                                if ( ( $oldBits | $newBits ) & $this->getSuppressBit() ) {
                                        $logType = 'suppress';
                                }
+                               // Track which fields where (un)hidden for each item
+                               $addedBits = ( $oldBits ^ $newBits ) & $newBits;
+                               $removedBits = ( $oldBits ^ $newBits ) & $oldBits;
+                               $virtualNewBits |= $addedBits;
+                               $virtualOldBits |= $removedBits;
 
                                $status->successCount++;
                                if ( $item->getAuthorId() > 0 ) {
@@ -228,14 +239,13 @@ abstract class RevDelList extends RevisionListBase {
                }
 
                // Log it
-               // @FIXME: $newBits/$oldBits set in for loop, makes IDE warnings too
                $this->updateLog(
                        $logType,
                        [
                                'title' => $this->title,
                                'count' => $successCount,
-                               'newBits' => $newBits,
-                               'oldBits' => $oldBits,
+                               'newBits' => $virtualNewBits,
+                               'oldBits' => $virtualOldBits,
                                'comment' => $comment,
                                'ids' => $idsForLog,
                                'authorIds' => $authorIds,