Page MenuHomePhabricator

Show deprecation notices when accessing wg* JavaScript globals
Closed, ResolvedPublic

Description

As the preferred way to access the wg* variables in JavaScript is to use mw.config.get()/.set(), accessing them as globals (i.e. as members of window) should show deprecation notices in debug mode, just like it is done for the functions from wikibits.js.

Details

Reference
bz56550

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 2:35 AM
bzimport added a project: MediaWiki-JavaScript.
bzimport set Reference to bz56550.
Schnark created this task.Nov 4 2013, 9:46 AM

mw.config.get('wg*') is currently basically a wrapper for window.wg*. To make such deprecation notices possible we'd have to duplicate the values, which could cause them to get out-of-sync if something modified them after page load.

brion added a comment.Nov 4 2013, 6:08 PM

Hm, how would deprecation actually work? Can we add getters on the window object?

(In reply to comment #1)

mw.config.get('wg*') is currently basically a wrapper for window.wg*. To make
such deprecation notices possible we'd have to duplicate the values, which
could cause them to get out-of-sync if something modified them after page
load.

Is this an actual issue? Once they are set, they shouldn't be changed anyway. So using a new object for mw.config.values instead of window and copying the variables over when they are set the first time using mw.log.deprecate shouldn't break more than replacing some of the wikibits.js functions with $.noop will break.

(In reply to comment #2)

Hm, how would deprecation actually work? Can we add getters on the window
object?

Yes, if you don't believe it, have a look at wikibits.js.

Ltrlg added a comment.Nov 5 2013, 6:57 PM

(In reply to comment #3)

(In reply to comment #1)

mw.config.get('wg*') is currently basically a wrapper for window.wg*. To make
such deprecation notices possible we'd have to duplicate the values, which
could cause them to get out-of-sync if something modified them after page
load.

Is this an actual issue? Once they are set, they shouldn't be changed anyway.
So using a new object for mw.config.values instead of window and copying the
variables over when they are set the first time using mw.log.deprecate
shouldn't break more than replacing some of the wikibits.js functions with
$.noop will break.

Apparently VisualEditor sets one, see bug 56532.

I just tried, and found that mw.log.deprecate can be called multiple times for the same variable without any problems. So mw.config.set could just call it, and whenever a wg* variable is changed via mw.config.set the global value would be updated, too. Only the other way round wouldn't work (or require some extra code instead of mw.log.deprecate).

mw.log.deprecate warnings are now visible when not in debug mode too.

Change 133162 had a related patch set uploaded by Gerrit Patch Uploader:
Show deprecation notices when accessing wg* JavaScript globals

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

Krinkle claimed this task.Nov 24 2014, 10:10 PM
Krinkle updated the task description. (Show Details)
Krinkle set Security to None.

Change 133162 had a related patch set uploaded (by Krinkle):
mw.config: Show deprecation notices when accessing globals

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

Patch-For-Review

Ricordisamoa added a subscriber: Ricordisamoa.
Krenair added a subscriber: Krenair.Jan 3 2015, 3:14 PM
Krinkle closed this task as Resolved.Jan 5 2015, 3:23 AM
Krinkle edited projects, added MW-1.25-release; removed Patch-For-Review.

Change 133162 merged by jenkins-bot:
mw.config: Show deprecation notices when accessing globals

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