From bb431303140d8ec95c21b56fb3166a6b6653c8f7 Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 26 Nov 2019 21:59:00 +0100 Subject: [PATCH] RevisionStore: force "Unknown user" instead of empty user name When restoring revisions that have an empty user name associated with them, force "Unknown user" to be used instead, even if the actor table has an entry for the empty user name. Bug: T236624 Change-Id: I31edd5f7d89d9b43806ad18e96f5e93cff0f8c6f --- includes/Revision/RevisionStore.php | 6 +++ .../McrWriteBothRevisionStoreDbTest.php | 1 - .../Revision/RevisionStoreDbTestBase.php | 49 +++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/includes/Revision/RevisionStore.php b/includes/Revision/RevisionStore.php index 218024fc95e..a52951a05db 100644 --- a/includes/Revision/RevisionStore.php +++ b/includes/Revision/RevisionStore.php @@ -1787,6 +1787,12 @@ class RevisionStore $user = new UserIdentityValue( 0, 'Unknown user', 0 ); } + if ( $user->getName() === '' ) { + // T236624: If the user name is empty, force 'Unknown user', + // even if the actor table has an entry for the empty user name. + $user = new UserIdentityValue( 0, 'Unknown user', 0 ); + } + $db = $this->getDBConnectionRefForQueryFlags( $queryFlags ); // Legacy because $row may have come from self::selectFields() $comment = $this->commentStore->getCommentLegacy( $db, 'ar_comment', $row, true ); diff --git a/tests/phpunit/includes/Revision/McrWriteBothRevisionStoreDbTest.php b/tests/phpunit/includes/Revision/McrWriteBothRevisionStoreDbTest.php index 8c0960bd385..1dac8329a88 100644 --- a/tests/phpunit/includes/Revision/McrWriteBothRevisionStoreDbTest.php +++ b/tests/phpunit/includes/Revision/McrWriteBothRevisionStoreDbTest.php @@ -17,7 +17,6 @@ use WikitextContent; * @group RevisionStore * @group Storage * @group Database - * @group medium */ class McrWriteBothRevisionStoreDbTest extends RevisionStoreDbTestBase { diff --git a/tests/phpunit/includes/Revision/RevisionStoreDbTestBase.php b/tests/phpunit/includes/Revision/RevisionStoreDbTestBase.php index d06693e46bf..9ddd8578a4b 100644 --- a/tests/phpunit/includes/Revision/RevisionStoreDbTestBase.php +++ b/tests/phpunit/includes/Revision/RevisionStoreDbTestBase.php @@ -78,6 +78,7 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase { $this->tablesUsed[] = 'page'; $this->tablesUsed[] = 'revision'; $this->tablesUsed[] = 'comment'; + $this->tablesUsed[] = 'actor'; $this->tablesUsed += $this->getMcrTablesToReset(); @@ -1165,6 +1166,54 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase { $this->assertSame( 'Unknown user', $record->getUser()->getName() ); } + /** + * Test for T236624. + * + * @covers \MediaWiki\Revision\RevisionStore::newRevisionFromArchiveRow + */ + public function testNewRevisionFromArchiveRow_empty_actor() { + $store = MediaWikiServices::getInstance()->getRevisionStore(); + + $row = (object)[ + 'ar_id' => '1', + 'ar_page_id' => '2', + 'ar_namespace' => '0', + 'ar_title' => 'Something', + 'ar_rev_id' => '2', + 'ar_text_id' => '47', + 'ar_timestamp' => '20180528192356', + 'ar_minor_edit' => '0', + 'ar_deleted' => '0', + 'ar_len' => '78', + 'ar_parent_id' => '0', + 'ar_sha1' => 'deadbeef', + 'ar_comment_text' => 'whatever', + 'ar_comment_data' => null, + 'ar_comment_cid' => null, + 'ar_user' => '0', + 'ar_user_text' => '', // this is the important bit + 'ar_actor' => null, // we will fill this in below + 'ar_content_format' => null, + 'ar_content_model' => null, + ]; + + // create an actor row for the empty user name (see also T225469) + $this->db->insert( 'actor', [ [ + 'actor_user' => $row->ar_user, + 'actor_name' => $row->ar_user_text, + ] ] ); + + $row->ar_actor = $this->db->insertId(); + + \Wikimedia\suppressWarnings(); + $record = $store->newRevisionFromArchiveRow( $row ); + \Wikimedia\suppressWarnings( true ); + + $this->assertInstanceOf( RevisionRecord::class, $record ); + $this->assertInstanceOf( UserIdentityValue::class, $record->getUser() ); + $this->assertSame( 'Unknown user', $record->getUser()->getName() ); + } + /** * @covers \MediaWiki\Revision\RevisionStore::newRevisionFromRow * @covers \MediaWiki\Revision\RevisionStore::newRevisionFromRowAndSlots