Page MenuHomePhabricator

Date.js external include breaks Date.now() (line 41) for modern javascript
Open, Needs TriagePublic

Description

When using PageTriage, it loads date.js as an external include.

Doing this registers Date.now() = Date() (https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/PageTriage/+/master/modules/external/date.js#41)

This overrides the native javascript Date.now() method, and does so in a way that breaks compability with other extensions - in my case https://www.mediawiki.org/wiki/Extension:Mermaid

This happens because after loading this extension, Date.Now() returns a formatted date string instead of the correct integer timestamp. This also has downstream effect in other javascript libraries that call Date.Now()

This remapping call should just be removed from the library, it serves no purpose with modern JS.

Event Timeline

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

This remapping call should just be removed from the library, it serves no purpose with modern JS.

What do you call modern JS? ;)

Noting we're also using a 13 year old library, which was 5 years old at point of inclusion

It seems to have changed a bit since then https://github.com/datejs/Datejs

Noting, we don't really tend to change 3rd party libraries. It should proably be upgraded or removed if not actually needed

Yeah, it was fixed very shortly after their 1.0 release - https://github.com/datejs/Datejs/commit/97f5c7c58c5bc5accdab8aa7602b6ac56462d778#diff-ee7fadf63f1ef613fe47c471483042e0.

So looks like if you can just update the library dependency, all should be good.

Change 730702 had a related patch set uploaded (by SD0001; author: SD0001):

[mediawiki/extensions/PageTriage@master] Replace deprecated date.js library with moment

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