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
This commit is contained in:
daniel 2019-11-26 21:59:00 +01:00
parent cc9d3a041e
commit bb43130314
3 changed files with 55 additions and 1 deletions

View file

@ -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 );

View file

@ -17,7 +17,6 @@ use WikitextContent;
* @group RevisionStore
* @group Storage
* @group Database
* @group medium
*/
class McrWriteBothRevisionStoreDbTest extends RevisionStoreDbTestBase {

View file

@ -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