Page MenuHomePhabricator

Normalize ipb_address field on ipblocks table
Closed, DeclinedPublic

Description

The polymorphic ipb_address field can contain an IP address, an IP range in CIDR notation, or a username. The username case is one of the few places that missed out on actor migration, so updating it is still required when users are renamed.

Direct references to ipb_address are rare in core and extensions. It would be simple to stop reading this field for user blocks. Then we could stop updating it and a script could blank it for user-block related rows.

The Block interface does expose ipb_address as Block::getTargetName(), but internally it is already discriminated, with a user block being stored as a UserIdentity.

DatabaseBlock::initFromRow() calls AbstractBlock::setTarget() with ipb_address which calls BlockUtils::parseBlockTarget() which converts the string to a UserIdentity. Instead DatabaseBlock::initFromRow() would make a UserIdentity from ipb_user, optionally joined on actor for the name, and would pass the UserIdentity to setTarget().

Special:BlockList does not sort by ipb_address, and searches are already aware of the target type.

ApiQueryBlocks searches ipb_address for user input, so will need to parse its input.

Related Objects

Event Timeline

I'm doing the query updates for this as part of T346293. I haven't done a schema migration script.

Change 971343 had a related patch set uploaded (by Tim Starling; author: Tim Starling):

[mediawiki/core@master] Support new block schema

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

Change 972528 had a related patch set uploaded (by Tim Starling; author: Tim Starling):

[mediawiki/extensions/CheckUser@master] Fix CheckUserPrivateEventLogFormatterTest to correctly load blocks from the database

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

Change 972528 merged by jenkins-bot:

[mediawiki/extensions/CheckUser@master] Use real users in CheckUserPrivateEventLogFormatterTest

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

We have T48013 and T163519 which ask for sortable columns in Special:BlockList. If we normalize ipb_address, we prevent indexed sorting by username. So I would like to invite comment on whether that is still a desired feature.

There are 1.5 million user blocks on English Wikipedia, so unindexed sorting is not really feasible.

Sorting by IP address is still possible in the new schema, although T51504 means that a union is required if we want to sort range blocks intermingled with single IP blocks.

If a sortable target column is definitely desired, I think I would prefer to have a username field rather than the old polymorphic address field. Or a custom sort key field which places IP addresses before usernames.

I'm retaining a bt_user_text field for sorting by target (T48013).