Page MenuHomePhabricator

Don't persist default settings in gadget definition pages
Closed, ResolvedPublic

Description

On gadget definition pages, the default settings currently get saved to the page. Even if the editor removes them from the JSON, they get re-added via a pre-save hook.

This is problematic for a couple of reasons:

  1. A number of optional settings have been added in last year or so (supportsUrlLoad, datas, actions, requiresES6). There are other live patches to add targets and namespaces. This doesn't scale. No other kind of JSON configuration file requires all keys to be present in the JSON – if a key is missing it should implicitly take the default value.
  2. When a new setting is added, it gets reflected in the page text the next time someone edits the page - creating misleading diffs.
  3. Although this should be very rare, when a default value is changed, the change does not affect any existing gadgets, only the new ones.

IMO we should stop adding the default settings via pre-save hook, unless explicitly entered by the user.

Event Timeline

I suppose that means we'll either need to merge with a default at the content layer or tolerate the absence at more layers (in a way that keeps useful edit-aborting validation) and then handle the defaults in the Gadget object.

This normalization was originally added in https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Gadgets/+/7156 (in the RL2 branch, where the experiment originated). I don't see anything there beyond the intention to validate the contents and normalize the JSON formatting. At the time, this was probably laziness on our part, because the code used the Gadget object to format the JSON, thus implied default values were no longer distinguishable from input values.

Skipping the substitution of defaults sounds good to me.

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

[mediawiki/extensions/Gadgets@master] Avoid persisting default gadget configs in definitions

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

Community configuration in GrowthExperiments does the same thing. I always found it helpful, it makes the JSON pages sort of self-documenting. Although editing mostly happens via a GUI there so users getting confused by diffs is less of a problem.

Change 982773 merged by jenkins-bot:

[mediawiki/extensions/Gadgets@master] Avoid persisting default gadget configs in definitions

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