Nothing Special   »   [go: up one dir, main page]

Page MenuHomePhabricator

Hidden gadget "preferences" being exported in mw.user.options
Closed, ResolvedPublicBUG REPORT

Description

Hidden gadgets do not have associated user preferences and are only meant to be loaded as dependencies by other gadgets or user scripts.

However, mw.user.options on every page load, even for non-signed-in users, contains the preferences apparently associated to them.

Steps to reproduce
Run in the JS console:

let json = await $.getJSON('/w/api.php?action=query&format=json&list=gadgets&gaprop=id%7Cmetadata&formatversion=2');
let hiddenGadgets = json.query.gadgets.filter(g => g.metadata.settings.hidden).map(g => g.id);
hiddenGadgets.forEach(g => console.log(mw.user.options.get('gadget-' + g)));

Expected result
undefined printed on console (22 times on enwiki as it has 22 hidden gadgets)

Actual result
0 printed on console 22 times

These options can't be changed. Running new mw.Api().saveOption('gadget-morebits', 1) and reloading the page still causes mw.user.options.get('gadget-morebits') to give 0.

They add page load costs and don't seem useful in any way. If some js wanted to find out whether a gadget exists (which seems like the only possible usecase) it could use mw.loader.moduleRegistry instead.

Event Timeline

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

[mediawiki/extensions/Gadgets@master] Avoid adding hidden gadgets in default options

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

mw.user.options in the html page (which add page load costs) only contains the non-default options (that is empy for logged-out users).

On runtime the default options are mixed into mw.user.options to fill in the defaults and that's value are reported by your example above.
It just increase the package file user.json, which should be cached after loaded once (minified and compressed).

The default values are added for T291748.
But it sounds okay to remove the hidden gadget also from the default options, because there are not shown on Special:Preferences and not needed to remove default values from the database etc.

Change 753524 merged by jenkins-bot:

[mediawiki/extensions/Gadgets@master] Avoid adding hidden gadgets in default options

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

Umherirrender assigned this task to SD0001.
Umherirrender triaged this task as Medium priority.

Just mentioning this discussion I opened, wondering if an hidden gadget will surely become loaded for everyone if the "default" keyword is added afterwards, i.e. not at the time the gadget definition was created.

(and conversely, also wondering if the gadget will no longer be loaded for everyone, if the "default" keyword is removed afterwards)