+ promise;
+
+ // Logged-out users can't have user options; we can't depend on mw.user, that'd be circular
+ if ( mw.config.get( 'wgUserName' ) === null ) {
+ return $.Deferred().reject( 'notloggedin' ).promise();
+ }
+
+ // If another options request to this API is pending, wait for it first
+ if (
+ saveOptionsRequests[ this.defaults.ajax.url ] &&
+ // Avoid long chains of promises, they may cause memory leaks
+ saveOptionsRequests[ this.defaults.ajax.url ].state() === 'pending'
+ ) {
+ promise = saveOptionsRequests[ this.defaults.ajax.url ].then( function () {
+ // Don't expose the old promise's result, it would be confusing
+ return $.Deferred().resolve();
+ }, function () {
+ return $.Deferred().resolve();
+ } );
+ } else {