2 * @class mw.Api.plugin.options
6 $.extend( mw.Api.prototype, {
9 * Asynchronously save the value of a single user option using the API. See #saveOptions.
11 * @param {string} name
12 * @param {string|null} value
13 * @return {jQuery.Promise}
15 saveOption: function ( name, value ) {
17 param[ name ] = value;
18 return this.saveOptions( param );
22 * Asynchronously save the values of user options using the API.
24 * If a value of `null` is provided, the given option will be reset to the default value.
26 * Any warnings returned by the API, including warnings about invalid option names or values,
27 * are ignored. However, do not rely on this behavior.
29 * If necessary, the options will be saved using several parallel API requests. Only one promise
30 * is always returned that will be resolved when all requests complete.
32 * @param {Object} options Options as a `{ name: value, … }` object
33 * @return {jQuery.Promise}
35 saveOptions: function ( options ) {
36 var name, value, bundleable,
40 for ( name in options ) {
41 value = options[ name ] === null ? null : String( options[ name ] );
43 // Can we bundle this option, or does it need a separate request?
44 if ( this.defaults.useUS ) {
45 bundleable = name.indexOf( '=' ) === -1;
48 ( value === null || value.indexOf( '|' ) === -1 ) &&
49 ( name.indexOf( '|' ) === -1 && name.indexOf( '=' ) === -1 );
53 if ( value !== null ) {
54 grouped.push( name + '=' + value );
56 // Omitting value resets the option
60 if ( value !== null ) {
61 deferreds.push( this.postWithToken( 'csrf', {
68 // Omitting value resets the option
69 deferreds.push( this.postWithToken( 'csrf', {
78 if ( grouped.length ) {
79 deferreds.push( this.postWithToken( 'csrf', {
86 return $.when.apply( $, deferreds );
93 * @mixins mw.Api.plugin.options
96 }( mediaWiki, jQuery ) );