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 project: Growth-Team. · View Herald TranscriptNov 23 2020, 5:41 PM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Amorymeltzer updated the task description. (Show Details)Nov 23 2020, 6:24 PM
Amorymeltzer updated the task description. (Show Details)Nov 23 2020, 7:01 PM
SD0001 added a subscriber: SD0001.EditedNov 23 2020, 7:43 PM

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.

Ammarpad added a subscriber: Ammarpad.EditedNov 24 2020, 2:58 AM

Date.js "last official release was Alpha-1 on November 19th, 2007.". This is all but dead project.