Page MenuHomePhabricator

importDump doesn't assign to local users by default
Closed, ResolvedPublic

Description

After a report in IRC...

		$this->addOption( 'username-prefix', 'Prefix for interwiki usernames', false, true );
		$this->addOption( 'no-local-users',
			'Treat all usernames as interwiki. ' .
			'The default is to assign edits to local users where they exist.',
			false, false
		);

But if we look how they're used...

		if ( $this->hasOption( 'username-prefix' ) ) {
			$importer->setUsernamePrefix(
				$this->getOption( 'username-prefix' ),
				!$this->hasOption( 'no-local-users' )
			);
		}

which calls

	/**
	 * @since 1.31
	 * @param string $usernamePrefix Prefix to apply to unknown (and possibly also known) usernames
	 * @param bool $assignKnownUsers Whether to apply the prefix to usernames that exist locally
	 */
	public function setUsernamePrefix( $usernamePrefix, $assignKnownUsers ) {
		$this->externalUserNames = new ExternalUserNames( $usernamePrefix, $assignKnownUsers );
	}

But if setUsernamePrefix isn't called... we rely on the default assignment in the constructor of WikiImporter...

		$this->externalUserNames = new ExternalUserNames( 'imported', false );

The false there would mean that local usernames are not assigned...

	/**
	 * @param string $usernamePrefix Prefix to apply to unknown (and possibly also known) usernames
	 * @param bool $assignKnownUsers Whether to apply the prefix to usernames that exist locally
	 */
	public function __construct( $usernamePrefix, $assignKnownUsers ) {
		$this->usernamePrefix = rtrim( (string)$usernamePrefix, ':>' );
		$this->assignKnownUsers = (bool)$assignKnownUsers;
	}

In Special:Import, Assign edits to local users where the named user exists locally is not enabled by default, but also setUsernamePrefix is called unconditionally (to other flags, at least)...

			// @phan-suppress-next-line PhanTypeMismatchArgumentNullable False positive
			$importer->setUsernamePrefix( $fullInterwikiPrefix, $assignKnownUsers );

Event Timeline

Change 959219 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/core@master] importDump: Unconditionally call $importer->setUsernamePrefix()

https://gerrit.wikimedia.org/r/959219

subscribing as i was the one who reported on irc

Change 959219 merged by jenkins-bot:

[mediawiki/core@master] importDump: Unconditionally call $importer->setUsernamePrefix()

https://gerrit.wikimedia.org/r/959219

Change 960726 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/core@REL1_40] importDump: Unconditionally call $importer->setUsernamePrefix()

https://gerrit.wikimedia.org/r/960726

Change 960727 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/core@REL1_39] importDump: Unconditionally call $importer->setUsernamePrefix()

https://gerrit.wikimedia.org/r/960727

Change 960727 merged by jenkins-bot:

[mediawiki/core@REL1_39] importDump: Unconditionally call $importer->setUsernamePrefix()

https://gerrit.wikimedia.org/r/960727

Reedy claimed this task.

Change 960726 merged by jenkins-bot:

[mediawiki/core@REL1_40] importDump: Unconditionally call $importer->setUsernamePrefix()

https://gerrit.wikimedia.org/r/960726