Background
We ran into issues relating to a new feature and we or other teams are likely to run it into again. Why this should be fixed:
- This delayed our project roll out as was not intuitive and is likely to delay others in future.
- To workaround it we add to write double the code we normally would have done. Other teams are likely to copy that approach leading to additional technical debt.
- Some lesser used features may be incompatible with GlobalPreferences because they haven't realized this bug is present in their software.
Steps to replicate the issue (include links if applicable):
- Enable GlobalPreferences on the skin preference.
- Go to https://cs.wikipedia.org/wiki/Speci%C3%A1ln%C3%AD:API_p%C3%ADskovi%C5%A1t%C4%9B#action=options&format=json&optionname=skin&optionvalue=vector-2022&formatversion=2
- Submit
What happens?:
I get error:
Option `skin` is globally overridden. You can use the \"globalpreferences\" API to change the option globally, or the \"globalpreferenceoverrides\" API to set a local override.
What should have happened instead?:
My intent is pretty obvious here. GlobalPreferences should handle it - it should call the API for me to set up a local override.
At the very least it should throw an error with error code so I can handle this error case.
Developer notes
- The existing saveOption client side function should take into account GlobalPreferences one way or the other. Suggest using hook or providing an alternative client side library inside extension.
var api = new mw.Api();
api.saveOption( 'skin', 'vector-2022' )- The client side function may need knowledge of which preferences are global and which are not.
- The API should throw an error when an attempt to save a preference that is a global preference is made.
Workaround
The problem can be worked around with the following code:
var api = new mw.Api();
api.saveOption( 'skin', 'vector-2022' ).then( function (r) {
try {
if ( r.warnings.options.warnings.indexOf('globalpreferenceoverrides') > -1 ) {
return api.postWithToken( 'csrf',
{ action: 'globalpreferenceoverrides', optionname: 'skin', optionvalue: 'vector-2022' }
);
}
} catch ( e ) {
// do nothing
}
} ).then( function (r) {
// success!
} );