api.js: Add an else to avoid unnecessary checks
[lhc/web/wiklou.git] / resources / src / mediawiki / api.js
index b9db059..0e9c19b 100644 (file)
@@ -51,7 +51,7 @@
        }
 
        // Pre-populate with fake ajax promises to save http requests for tokens
-       // we already have on the page via the user.tokens module (bug 34733).
+       // we already have on the page via the user.tokens module (T36733).
        promises[ defaultOptions.ajax.url ] = {};
        $.each( mw.user.tokens.get(), function ( key, value ) {
                // This requires #getToken to use the same key as user.tokens.
                 * @method
                 */
                abort: function () {
-                       $.each( this.requests, function ( index, request ) {
+                       this.requests.forEach( function ( request ) {
                                if ( request ) {
                                        request.abort();
                                }
                /**
                 * Massage parameters from the nice format we accept into a format suitable for the API.
                 *
+                * NOTE: A value of undefined/null in an array will be represented by Array#join()
+                * as the empty string. Should we filter silently? Warn? Leave as-is?
+                *
                 * @private
                 * @param {Object} parameters (modified in-place)
                 * @param {boolean} useUS Whether to use U+001F when joining multi-valued parameters.
                        // Handle common MediaWiki API idioms for passing parameters
                        for ( key in parameters ) {
                                // Multiple values are pipe-separated
-                               if ( $.isArray( parameters[ key ] ) ) {
+                               if ( Array.isArray( parameters[ key ] ) ) {
                                        if ( !useUS || parameters[ key ].join( '' ).indexOf( '|' ) === -1 ) {
                                                parameters[ key ] = parameters[ key ].join( '|' );
                                        } else {
                                                parameters[ key ] = '\x1f' + parameters[ key ].join( '\x1f' );
                                        }
-                               }
-                               // Boolean values are only false when not given at all
-                               if ( parameters[ key ] === false || parameters[ key ] === undefined ) {
+                               } else if ( parameters[ key ] === false || parameters[ key ] === undefined ) {
+                                       // Boolean values are only false when not given at all
                                        delete parameters[ key ];
                                }
                        }
                                                        jqXHR
                                                );
                                        } else if ( result.error ) {
+                                               // errorformat=bc
                                                code = result.error.code === undefined ? 'unknown' : result.error.code;
                                                apiDeferred.reject( code, result, result, jqXHR );
                                        } else if ( result.errors ) {
+                                               // errorformat!=bc
                                                code = result.errors[ 0 ].code === undefined ? 'unknown' : result.errors[ 0 ].code;
                                                apiDeferred.reject( code, result, result, jqXHR );
                                        } else {
        /**
         * @static
         * @property {Array}
-        * List of errors we might receive from the API.
-        * For now, this just documents our expectation that there should be similar messages
-        * available.
+        * Very incomplete and outdated list of errors we might receive from the API. Do not use.
+        * @deprecated since 1.29
         */
        mw.Api.errors = [
                // occurs when POST aborted
                'stashwrongowner',
                'stashnosuchfilekey'
        ];
+       mw.log.deprecate( mw.Api, 'errors', mw.Api.errors, null, 'mw.Api.errors' );
 
        /**
         * @static
         * @property {Array}
-        * List of warnings we might receive from the API.
-        * For now, this just documents our expectation that there should be similar messages
-        * available.
+        * Very incomplete and outdated list of warnings we might receive from the API. Do not use.
+        * @deprecated since 1.29
         */
        mw.Api.warnings = [
                'duplicate',
                'exists'
        ];
+       mw.log.deprecate( mw.Api, 'warnings', mw.Api.warnings, null, 'mw.Api.warnings' );
 
 }( mediaWiki, jQuery ) );