Avoid DB rows with usable names but ID = 0 by introducing "interwiki" usernames
authorBrad Jorsch <bjorsch@wikimedia.org>
Wed, 25 Oct 2017 19:26:53 +0000 (15:26 -0400)
committerTim Starling <tstarling@wikimedia.org>
Thu, 30 Nov 2017 02:12:44 +0000 (13:12 +1100)
commit96bd79b4a36a7216dce4ad8b5915d592ba1dff8b
treec482e61b22f0fc9d930ce90110a57eef82368e7a
parent5af3ad33ed1b27bd5f77038c89844d513d078cba
Avoid DB rows with usable names but ID = 0 by introducing "interwiki" usernames

Importing revisions in MediaWiki has long been weird: if the username on
the imported revision exists locally it's automatically attributed to
the local user, while if the name does not exist locally we wind up with
revision table rows with rev_user = 0 and rev_user_text being a valid
name that someone might later create. "Global" blocks too create rows
with ipb_by = 0 an ipb_by_text being a valid name.

The upcoming actor table change, as things currently stand, would
regularize that a bit by automatically attributing those imported
revisions to the newly-created user. But that's not necessarily what we
actually want to happen. And it would certainly confuse CentralAuth's
attempt to detect its own global blocks.

Thus, this patch introduces "interwiki" usernames that aren't valid for
local use, of the format "iw>Example".[1] Linker will interpret these
names and generate an appropriate interwiki link in history pages and
the like, as if from wikitext like `[[iw:User:Example]]`.

Imports for non-existant local users (and optionally for existing local
users too) will credit the edit to such an interwiki name. There is also
a new hook, 'ImportHandleUnknownUser', to allow extension such as
CentralAuth to create local users as their edits are imported.

Block will no longer accept usable-but-nonexistent names for 'byText' or
->setBlocker(). CentralAuth's global blocks will be submitted with an
interwiki username (see Ieae5d24f9).

Wikis that have imported edits or CentralAuth global blocks should run
the new maintenance/cleanupUsersWithNoId.php maintenance script. This
isn't done by update.php because (1) it needs an interwiki prefix to use
and (2) the updater can't know whether to pass the `--assign` flag.

[1]: '>' was used instead of the more usual ':' because WMF wikis have
many existing usernames containing colons.

Bug: T9240
Bug: T20209
Bug: T111605
Change-Id: I5401941c06102e8faa813910519d55482dff36cb
Depends-On: Ieae5d24f9098c1977447c50a8d4e2cab58a24d9f
17 files changed:
RELEASE-NOTES-1.31
autoload.php
docs/hooks.txt
includes/Block.php
includes/DefaultSettings.php
includes/Linker.php
includes/api/ApiImport.php
includes/api/i18n/en.json
includes/api/i18n/qqq.json
includes/import/WikiImporter.php
includes/specials/SpecialImport.php
languages/i18n/en.json
languages/i18n/qqq.json
maintenance/cleanupUsersWithNoId.php [new file with mode: 0644]
maintenance/importDump.php
tests/phpunit/includes/BlockTest.php
tests/phpunit/includes/import/ImportTest.php