Page MenuHomePhabricator

Add mw.util.isInfinity() to parity wfIsInfinity()
Closed, ResolvedPublic

Description

This is to parity the global PHP function wfIsInfinity(). In our JavaScript, especially around watchlisting, we use both infinity and infinite (and sometimes other strings) as infinity values, depending on if we're talking about the Expiring-Watchlist-Items dropdown (which uses infinite) or API interaction (which more commonly uses infinity).

We need a Core stable method to test if a string is infinity, such that we don't need to worry about which context the value is coming from.

This will be especially useful for the work that is going into T265716: Allow users to set their default watchlist item expiry time.

Justification for putting in mw.util

  • It doesn't fit soundly in any other singular module, and is used by multiple other modules
  • It's a very tiny string comparison (small footprint)
  • It could and probably should become widely used, i.e. in gadgets and scripts that work with expiries

Acceptance criteria

  • mw.util.isInfinity() should return true for the same values as MediaWiki's ExpiryDef::INFINITY_VALS, which includes: infinite, indefinite, infinity, never
  • Inject the ExpiryDef::INFINITY_VALS into the JS, so that we still have one list of values to maintain.

Event Timeline

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

[mediawiki/core@master] mw.util: introduce isInfinity to parity MW's wfIsInfinity()

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

Change 982923 merged by jenkins-bot:

[mediawiki/core@master] mw.util: introduce isInfinity to parity MW's wfIsInfinity()

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

Shouldn't we be fixing this tech debt by converging magic values to the same constant?

Shouldn't we be fixing this tech debt by converging magic values to the same constant?

The value can come from user input, customized interface messages, gadgets, etc. I think settling on a single value is a great idea but it would be a slow process and I guess require API deprecation. More than I have time for :/

Shouldn't we be fixing this tech debt by converging magic values to the same constant?

The value can come from user input, customized interface messages, gadgets, etc. I think settling on a single value is a great idea but it would be a slow process and I guess require API deprecation. More than I have time for :/

Sure, but is there no task for this?

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

[mediawiki/skins/Vector@master] watchstar: use mw.util.isInfinity() instead of comparing to 'infinity'

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

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

[mediawiki/core@master] mediawiki.special.block: use mw.util.isInfinity

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

Change #1015659 merged by jenkins-bot:

[mediawiki/core@master] mediawiki.special.block: use mw.util.isInfinity

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

Change #995192 merged by jenkins-bot:

[mediawiki/skins/Vector@master] watchstar: use mw.util.isInfinity() instead of comparing to 'infinity'

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