From: Brad Jorsch Date: Mon, 3 Jun 2019 13:59:33 +0000 (-0400) Subject: DeleteLogFormatter: Handle missing ofield/nfield X-Git-Tag: 1.34.0-rc.0~1438 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=144ebd06c73cb85998f5d9e03a992f44c4adb234;p=lhc%2Fweb%2Fwiklou.git DeleteLogFormatter: Handle missing ofield/nfield ofield and nfield may be missing from old log entries. Take that into account when processing. Bug: T224815 Change-Id: I06dda3106bab9980f6fa7d515542e94a91c17f64 --- diff --git a/includes/logging/DeleteLogFormatter.php b/includes/logging/DeleteLogFormatter.php index 8078e2e02c..048b567c70 100644 --- a/includes/logging/DeleteLogFormatter.php +++ b/includes/logging/DeleteLogFormatter.php @@ -270,8 +270,6 @@ class DeleteLogFormatter extends LogFormatter { } } - $old = $this->parseBitField( $rawParams['6::ofield'] ); - $new = $this->parseBitField( $rawParams['7::nfield'] ); if ( !is_array( $rawParams['5::ids'] ) ) { $rawParams['5::ids'] = explode( ',', $rawParams['5::ids'] ); } @@ -279,8 +277,6 @@ class DeleteLogFormatter extends LogFormatter { $params = [ '::type' => $rawParams['4::type'], ':array:ids' => $rawParams['5::ids'], - ':assoc:old' => [ 'bitmask' => $old ], - ':assoc:new' => [ 'bitmask' => $new ], ]; static $fields = [ @@ -289,9 +285,20 @@ class DeleteLogFormatter extends LogFormatter { Revision::DELETED_USER => 'user', Revision::DELETED_RESTRICTED => 'restricted', ]; - foreach ( $fields as $bit => $key ) { - $params[':assoc:old'][$key] = (bool)( $old & $bit ); - $params[':assoc:new'][$key] = (bool)( $new & $bit ); + + if ( isset( $rawParams['6::ofield'] ) ) { + $old = $this->parseBitField( $rawParams['6::ofield'] ); + $params[':assoc:old'] = [ 'bitmask' => $old ]; + foreach ( $fields as $bit => $key ) { + $params[':assoc:old'][$key] = (bool)( $old & $bit ); + } + } + if ( isset( $rawParams['7::nfield'] ) ) { + $new = $this->parseBitField( $rawParams['7::nfield'] ); + $params[':assoc:new'] = [ 'bitmask' => $new ]; + foreach ( $fields as $bit => $key ) { + $params[':assoc:new'][$key] = (bool)( $new & $bit ); + } } } elseif ( $subtype === 'restore' ) { $rawParams = $entry->getParameters(); diff --git a/tests/phpunit/includes/logging/DeleteLogFormatterTest.php b/tests/phpunit/includes/logging/DeleteLogFormatterTest.php index 0e6855d9a9..6648c31c25 100644 --- a/tests/phpunit/includes/logging/DeleteLogFormatterTest.php +++ b/tests/phpunit/includes/logging/DeleteLogFormatterTest.php @@ -457,7 +457,7 @@ class DeleteLogFormatterTest extends LogFormatterTestCase { ], ], - // Legacy format + // Legacy formats [ [ 'type' => 'suppress', @@ -495,6 +495,27 @@ class DeleteLogFormatterTest extends LogFormatterTestCase { ], ], ], + [ + [ + 'type' => 'delete', + 'action' => 'revision', + 'comment' => 'Old rows might lack ofield/nfield (T224815)', + 'namespace' => NS_MAIN, + 'title' => 'Page', + 'params' => [ + 'oldid', + '1234', + ], + ], + [ + 'legacy' => true, + 'text' => 'User changed visibility of revisions on page Page', + 'api' => [ + 'type' => 'oldid', + 'ids' => [ '1234' ], + ], + ], + ] ]; }