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