Page MenuHomePhabricator

Remove wgMonthNamesShort from mw.config
Closed, ResolvedPublic

Description

Looks like this is the sort of data export that really belongs with a specific module that needs it, rather than side-wide or on every page.


"wgMonthNamesShort": ["", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],

However, checking Codesearch shows it isn't actually used anywhere in core, nor in any WMF-deployed extensions. And in other repos, there's also only very few uses:

  • SemanticMediaWiki: 1 use of wgMonthNames in ext.smw.dataItem.time.js.
  • SemanticResultFormats: 1 use of wgMonthNames in ext.srf.api.results.js
  • PageForms: 1 use of wgMonthNamesShort in PF_jsGrid.js.

Migration

For a MediaWiki extension:

  • To access month names in the current user's interface language, use mediawiki.language.months.abbrev. Documentation: mediawiki.language, and T219340#5060585 for example code
  • The access month names in the wiki's main content language, you will have to either lazy-load them from the Messages API, or (for greater performance) export them server-side in a generated package file where you export the result of $context->msg('jan')->inContentLanguage()->text() etc.

For a gadget, or user script:

Event Timeline

Krinkle created this task.Mar 26 2019, 11:01 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptMar 26 2019, 11:01 PM

This was introduced in 2011 (MW 1.18; r86088) for use by jquery.tablesorter. However, it was migrated to use the mediawiki.language module instead, which provides month names as well as genitive month names. (gerrit 55496).

Thus this is no longer needed. The existence of that module makes migration even easier for extensions as they wouldn't even need to augment their JS modules with data export. Instead, they can use mediawiki.language.months module directly.

Example:

extension.json
"ext.example": {
  "dependencies": [ "mediawiki.language.months" ]
}
file.js
// Month name
var name = mw.language.months.names[ i ];
var nameLc = mw.language.months.names[ i ].toLowerCase();
var nameReEsc = mw.RegExp.escape( name );

// Month name (genitive)
var genitive = mw.language.months.genitive[ i ].;

// Short month name
var short = mw.language.months.abbrev[ i ];

There is an important difference between wgMonthNames and mw.language.months.names: wgMonthNames uses the language of the wiki, while mw.language.months.names is in the language of the user.
This probably also means that sorting dates in tables is broken when the user has an interface language different from the content.

TheDJ added a subscriber: TheDJ.Mar 27 2019, 10:18 AM

This probably also means that sorting dates in tables is broken when the user has an interface language different from the content.

See T126744: Sorting of month names in tables should depend on page content language ;)

There are some gadgets and user scripts that depend on wgMonthNames.

A deprecation warning when accessing a deprecated JavaScript config variables would be nice:

mw.config.get( 'wgMonthNames' )

should trigger deprecation warning in the JavaScript console like the global JavaScript config variables (window.wgMonthNames) already do:

Jdlrobson triaged this task as Low priority.Apr 1 2019, 5:57 PM
Jdlrobson edited projects, added patch-welcome; removed Readers-Web-Backlog.
Jdlrobson added a subscriber: Jdlrobson.

Ideally maintainers from SemanticMediaWiki and PageForms will lead here. Am happy to help make the deprecation happen once that's done.
@Fomafix totally agree with the approach here and will happily review such a patch to get the ball rolling here.

PageForms would be @Yaron_Koren; Semantic MediaWiki is (I think) @mwjames.

There are some gadgets and user scripts that depend on wgMonthNames.

Yep...

> mwgrep wgMonthNames
testwiki        MediaWiki:Afch-master.js/core.js
itwikinews      MediaWiki:Catwatch.js
astwiki         MediaWiki:Common.js
eswiki          MediaWiki:Common.js
testwiki        MediaWiki:Gadget-afch.js/core.js
guwiki          MediaWiki:Gadget-AjaxQuickDelete.js
guwikiquote     MediaWiki:Gadget-AjaxQuickDelete.js
ptwiki          MediaWiki:Gadget-arquivarPEs.js
itwiki          MediaWiki:Gadget-CatWatch.js
itwikiversity   MediaWiki:Gadget-CatWatch.js
ptwiki          MediaWiki:Gadget-contentFeatured.js
testwiki        MediaWiki:Gadget-contentFeatured.js
itwiki          MediaWiki:Gadget-contribsrange.js
ptwiki          MediaWiki:Gadget-fastbuttons.js/core.js
testwiki        MediaWiki:Gadget-fastbuttons.js/core.js
ptwiki          MediaWiki:Gadget-lastEditUser.js
azbwiki         MediaWiki:Gadget-libAPI.js
commonswiki     MediaWiki:Gadget-libAPI.js
fawiki          MediaWiki:Gadget-libAPI.js
testwiki        MediaWiki:Gadget-libAPI.js
ukwiki          MediaWiki:Gadget-libAPI.js
azbwiki         MediaWiki:Gadget-libUtil.js
commonswiki     MediaWiki:Gadget-libUtil.js
fawiki          MediaWiki:Gadget-libUtil.js
fiwiki          MediaWiki:Gadget-libUtil.js
lvwiki          MediaWiki:Gadget-libUtil.js
mlwiki          MediaWiki:Gadget-libUtil.js
plwikinews      MediaWiki:Gadget-libUtil.js
testwiki        MediaWiki:Gadget-libUtil.js
urwiki          MediaWiki:Gadget-libUtil.js
urwikibooks     MediaWiki:Gadget-libUtil.js
ckbwiki         MediaWiki:Gadget-messages-dropdown.js
fawiki          MediaWiki:Gadget-messages-dropdown.js
brwikimedia     MediaWiki:Gadget-NewVillagePump.js/Core.js
ptwiki          MediaWiki:Gadget-NewVillagePump.js/Core.js
testwiki        MediaWiki:Gadget-NewVillagePump.js/Core.js
testwiki        MediaWiki:Gadget-newVillagePump.js/core.js
urwiki          MediaWiki:Gadget-OneClickArchiver.js
test2wiki       MediaWiki:Gadget-PermissionOTRS.js
bhwiki          MediaWiki:Gadget-ProveIt-classic.js
enwiki          MediaWiki:Gadget-ProveIt-classic.js
srwiki          MediaWiki:Gadget-ProveIt-classic.js
srwiktionary    MediaWiki:Gadget-ProveIt-classic.js
elwiki          MediaWiki:Gadget-ProveIt.js
fawiki          MediaWiki:Gadget-ProveIt.js
gomwiki         MediaWiki:Gadget-ProveIt.js
kkwiki          MediaWiki:Gadget-ProveIt.js
piwiki          MediaWiki:Gadget-ProveIt.js
pswiki          MediaWiki:Gadget-ProveIt.js
siwiki          MediaWiki:Gadget-ProveIt.js
test2wiki       MediaWiki:Gadget-ProveIt.js
urwiki          MediaWiki:Gadget-ProveIt.js
zh_yuewiki      MediaWiki:Gadget-ProveIt.js
tawiki          MediaWiki:Gadget-ProveItMain.js
testwiki        MediaWiki:Gadget-revisionsSysopsActions.js
ptwiki          MediaWiki:Gadget-revisionSysopsActions.js
lezwiki         MediaWiki:Gadget-wefcore.js
lvwiki          MediaWiki:Gadget-wefcore.js
nowiki          MediaWiki:Gadget-work-in-progress.js
itwikinews      MediaWiki:Modifiche alla pagina principale.js
commonswiki     MediaWiki:OneClickArchiver.js
commonswiki     MediaWiki:ProcessFileMoverRequests.js
ruwiki          MediaWiki:Tool/RightsLog.js
incubatorwiki   MediaWiki:Wp/bgn/Gadget-messages-dropdown.js
incubatorwiki   MediaWiki:Wp/bgn/Gadget-ProveIt.js

I just removed the use of wgMonthNamesShort from Page Forms, in https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/PageForms/+/502664/ .

$ mwgrep wgMonthNamesShort
astwiki             MediaWiki:Common.js
azbwiki             MediaWiki:Gadget-libAPI.js
commonswiki         MediaWiki:Gadget-libAPI.js
commonswiki         MediaWiki:OneClickArchiver.js
commonswiki         MediaWiki:ProcessFileMoverRequests.js
enwiki              MediaWiki:Gadget-morebits.js
eswiki              MediaWiki:Common.js
fawiki              MediaWiki:Gadget-libAPI.js
guwiki              MediaWiki:Gadget-AjaxQuickDelete.js
guwikiquote         MediaWiki:Gadget-AjaxQuickDelete.js
itwiki              MediaWiki:Gadget-CatWatch.js
itwikinews          MediaWiki:Catwatch.js
itwikinews          MediaWiki:Modifiche alla pagina principale.js
itwikiversity       MediaWiki:Gadget-CatWatch.js
nowiki              MediaWiki:Gadget-work-in-progress.js
ruwiki              MediaWiki:Tool/RightsLog.js
testwiki            MediaWiki:Gadget-libAPI.js
testwiki            MediaWiki:Gadget-morebits.js
ukwiki              MediaWiki:Gadget-libAPI.js
urwiki              MediaWiki:Gadget-OneClickArchiver.js

(total: 20, shown: 20)

There could be many more usages in user namespace.

Sure, those can be found via Global Search as well if you're interested. I'm only pasting the site-wide usage here so that interested volunteers active on Phab can help with them if possible, and for developers to see if there are cases we could accomodate more easily with an alternative.

In either case, existing usage in gadgets will not block removal of the key from MW as it was not created for gadgets, it was created for a core feature that is now obsolete. It is being removed to make space in the performance budget for other things in the future. It is only existed because a core feature needed it at some point in the past. Everything is exposed to gadgets by default, but there is no promise it will stay. It can be used as convenience where it happens to work today. Alternatives are Date() and Intl functions provided by browsers, or the MW API.

There will be a Tech News announcement at least a few weeks before it gets removed. We're not there yet :)

@Krinkle am I good to claim this and remove or does more need to be done beforehand? (Just wanted to double check prior to making any commit.) Also: you have a question at the github issue you created

@TheSandDoctor The wgMonthNamesShort variable is ready for removal I think. The other one not yet.

Krinkle updated the task description. (Show Details)Mar 13 2020, 7:22 PM

Change 579624 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] OutputPage: Remove 'wgMonthNamesShort' from mw.config

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

Change 579624 merged by jenkins-bot:
[mediawiki/core@master] OutputPage: Remove 'wgMonthNamesShort' from mw.config

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

Krinkle renamed this task from Remove wgMonthNames and wgMonthNamesShort from mw.config to Remove wgMonthNamesShort from mw.config.Mar 13 2020, 10:14 PM
Krinkle updated the task description. (Show Details)

(Reducing scope to wgMonthNamesShort for now)

Krinkle updated the task description. (Show Details)Mar 13 2020, 10:15 PM
Krinkle closed this task as Resolved.Mar 13 2020, 10:18 PM
Krinkle claimed this task.

I've done a couple dozen more tourbot replacements over user scripts that were still using it. There are now 0 uses of it in any gadget, site scripts, or user scripts I coul find via mwgrep, mwgrep --user and global search.

(There are non-zero search results, but they were either false positives where it mentions its name but does not use it, or results from an outdated search index from prior to my edit.)