Page MenuHomePhabricator

Consolidate logic for parsing expiries
Open, Needs TriagePublic

Description

As a watchlist user, I want the logic for parsing expiries to be consolidated, so that the tool can run with efficiency and reliability in the back-end.

Background: We have basically the same logic for parsing "expiry" user inputs in WatchedItemStore::updateOrDeleteExpiries(), SpecialBlock::parseExpiryInput(), SpecialUserrights::expiryToTimestamp(), ProtectionForm::getExpiry(), ApiProtect::execute(), FlaggedRevs PageStabilityForm::getExpiry(), and possibly other extensions as well. With minor variations, that code is generally[1]

if ( wfIsInfinity( $expiry ) ) {
    return 'infinity';
}

$unix = strtotime( $expiry );
return $unix === false ? false : wfTimestamp( TS_MW, $unix );

We should probably consolidate that logic into one place, possibly with additional error checking to avoid accepting past expiries and such. Also, for the benefit of APIs[2] we might also add 'expiry' as a type to ParamValidator.

[1]: Well, most of them still have checks for PHP 5.0 returning -1 instead of false on invalid input. I left that out here.
[2]: In the Action API in core, we could use it in ApiBlock, ApiProtect, and ApiUserrights, and ApiWatch.

Acceptance Criteria:

  • Consolidate logic for parsing expiries

Related

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Change 983968 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/core@master] BlockUser: parse expiries using ExpiryDef::normalizeExpiry

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

This task was created before we introduced ExpiryDef, which largely addresses the issue. We just need to make use of ExpiryDef::nomralizeExpiry in more places.

Change 983969 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/core@master] ApiProtect: parse expiries using ExpiryDef::normalizeExpiry

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

Change 983970 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/core@master] ProtectionForm: parse expiries using ExpiryDef::normalizeExpiry

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

Change 983968 merged by jenkins-bot:

[mediawiki/core@master] BlockUser: parse expiries using ExpiryDef::normalizeExpiry

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