Page MenuHomePhabricator

PageTriage's external Date.js modifies/overwrites native JavaScript Date prototype, should be updated
Open, Needs TriagePublic

Description

(This is arguably a duplicate of T250932, but that's about the one specific case, whereas I'm talking about all of them. Merge away if so desired.)

This means that a lot of javascript can be different if a page is in the queue. As noted in T250932#6078951 this is an (old) external library, and T250932#6078983 suggests that merely updating the external library would fix this issue. Thus, if it must be used (I'm not familiar with the PageTriage codebase) it should be updated.

A page not in the queue (e.g. en:Macbeth):
Object.getOwnPropertyNames(Date.prototype).length //47
typeof Date.prototype.add //undefined
typeof Date.now() //number
new Date().getMonthName() //Uncaught TypeError

A page in the queue (e.g. en:Anahit Yulanda Varan):
Object.getOwnPropertyNames(Date.prototype).length //145
typeof Date.prototype.add //function
typeof Date.now() //object
new Date().getMonthName() //November

Inconsistencies in environment between pages isn't good, especially if it's overwriting behavior (T250932). Moreover, as this apparently only loads if wgAction === 'view', these discrepancies will also exist when editing a page in the queue. Doing so can also muck up other code, which is how I found this: some of Twinkle's Morebits.date library won't work reliably, as it relied on picking up the native Date's methods.

Event Timeline

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

PageTriage appears to be using Date.js just for the single function Date.parseExact, that too for parsing the yyyyMMddHHmmss timestamp format only. This functionality can be easily made available through a utility function that extracts the date parts from the string and feeds them into Date.UTC(), and the library can then be removed.

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

[mediawiki/extensions/PageTriage@master] Remove deprecated date.js library

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

Change 692892 merged by jenkins-bot:

[mediawiki/extensions/PageTriage@master] Remove deprecated date.js library

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

I've at long last figured out how to set up a local MW dev env. Will file a fresh patch soon, this time after testing.

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