Merge "Followup a88df43d: make $wgDebugDumpSql log commented queries again"
[lhc/web/wiklou.git] / resources / src / mediawiki / api.js
index 43b20b8..5f82b18 100644 (file)
@@ -67,7 +67,6 @@
         *  each individual request by passing them to #get or #post (or directly #ajax) later on.
         */
        mw.Api = function ( options ) {
-               // TODO: Share API objects with exact same config.
                options = options || {};
 
                // Force a string if we got a mw.Uri object
                options.ajax = $.extend( {}, defaultOptions.ajax, options.ajax );
 
                this.defaults = options;
+               this.requests = [];
        };
 
        mw.Api.prototype = {
+               /**
+                * Abort all unfinished requests issued by this Api object.
+                *
+                * @method
+                */
+               abort: function () {
+                       $.each( this.requests, function ( index, request ) {
+                               if ( request ) {
+                                       request.abort();
+                               }
+                       } );
+               },
 
                /**
                 * Perform API get request
                /**
                 * Perform API post request
                 *
-                * TODO: Post actions for non-local hostnames will need proxy.
-                *
                 * @param {Object} parameters
                 * @param {Object} [ajaxOptions]
                 * @return {jQuery.Promise}
                 *  Fail: Error code
                 */
                ajax: function ( parameters, ajaxOptions ) {
-                       var token,
+                       var token, requestIndex,
+                               api = this,
                                apiDeferred = $.Deferred(),
                                xhr, key, formData;
 
                                        }
                                } );
 
+                       requestIndex = this.requests.length;
+                       this.requests.push( xhr );
+                       xhr.always( function () {
+                               api.requests[ requestIndex ] = null;
+                       } );
                        // Return the Promise
                        return apiDeferred.promise( { abort: xhr.abort } ).fail( function ( code, details ) {
                                if ( !( code === 'http' && details && details.textStatus === 'abort' ) ) {