Page MenuHomePhabricator

Normalize $infinityValues before write to logging table when blocking
Closed, ResolvedPublic

Description

MediaWiki's blocking code should normalize the four accepted strings denoting infinity to a single value before they are written to the logging table. One consequence is this:

https://en.wikipedia.org/w/api.php?action=query&list=logevents&letype=block&letitle=User:Quickcare123
https://en.wikipedia.org/w/api.php?action=query&list=logevents&letype=block&letitle=User:GothSpell
https://en.wikipedia.org/w/api.php?action=query&list=logevents&letype=block&letitle=User:Raunaqpvc
https://en.wikipedia.org/w/api.php?action=query&list=logevents&letype=block&letitle=User:Safetycardmaniceland

The API returns these values without normalization as the expiry parameter. Therefore I need to test against all four allowed values - "indefinite", "infinity", "infinite" and "never" - if I am looking in the block log for indefinite blocks. The workaround is to do the normalization in the API, but that still leaves Technical-Debt.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
DannyS712 added a project: MediaWiki-Logevents.
DannyS712 subscribed.

At least at Special:Block, there is already normalization applied:

SpecialBlock::processForm
$expiryTime = self::parseExpiryInput( $data['Expiry'] );
...
$block->setExpiry( $expiryTime );
SpecialBlock::parseExpiryInput
public static function parseExpiryInput( $expiry ) {
	if ( wfIsInfinity( $expiry ) ) {
		return 'infinity';
	}
	$expiry = strtotime( $expiry );
	if ( $expiry < 0 || $expiry === false ) {
		return false;
	}
	return wfTimestamp( TS_MW, $expiry );
}
GlobalFunctions wfIsInfinity
function wfIsInfinity( $str ) {
	// These are hardcoded elsewhere in MediaWiki (e.g. mediawiki.special.block.js).
	$infinityValues = [ 'infinite', 'indefinite', 'infinity', 'never' ];
	return in_array( $str, $infinityValues );
}

That being said, the logging table's parameters are not normalized:

SpecialBlock::processForm
$logParams['5::duration'] = $data['Expiry'];

Change 561574 had a related patch set uploaded (by DannyS712; owner: DannyS712):
[mediawiki/core@master] Use normalized block duration in block log entries

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

@MER-C do you think this warrants a maintenance script to normalize old entries?

Yes please. I'm slightly concerned that this problem may cause silent quantitative inaccuracies or bugs elsewhere. Not normalising the past entries is unnecessarily incurring technical debt. In the long term this information should be stored in a more structured way - but the WMF will only get around to doing that decades after this bug is forgotten about.

But if you're content for this to be Someone Else's Problem, that's also OK. You shouldn't be cleaning up the WMF's technical debt.

Change 561574 merged by jenkins-bot:
[mediawiki/core@master] Use normalized block duration in block log entries

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

DannyS712 moved this task from Backlog to User blocking on the MediaWiki-User-management board.
DannyS712 moved this task from Backlog to Requested scripts on the MediaWiki-Maintenance-system board.

Unlicking this cookie - going forward, log entries should use infinity for all durations that pass wfIsInfinity(). A maintenance script should update existing log entries

Abuse filter hardcodes using indefinite

Change 578721 had a related patch set uploaded (by DannyS712; owner: DannyS712):
[mediawiki/extensions/AbuseFilter@master] Log indefinite blocks as infinity rather than indefinite

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

Change 743601 had a related patch set uploaded (by Umherirrender; author: Umherirrender):

[mediawiki/core@master] Normalize infinity block duration for pre-T241709 log entries

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

Change 578721 abandoned by Umherirrender:

[mediawiki/extensions/AbuseFilter@master] Log indefinite blocks as `infinity` rather than `indefinite`

Reason:

AbuseFilter no longer build the log entry by its own - Ib7c1dc107a169b575f7021e64b6a8fee09529548

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

Change 743601 merged by jenkins-bot:

[mediawiki/core@master] logging: Normalize "infinity" in BlockLogFormatter for pre-T241709 rows

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