*
* @param {Object} parameters
* @param {Object} [ajaxOptions]
- * @return {jQuery.Promise} Done: API response data. Fail: Error code
+ * @return {jQuery.Promise} Done: API response data and the jqXHR object.
+ * Fail: Error code
*/
ajax: function ( parameters, ajaxOptions ) {
var token,
apiDeferred = $.Deferred(),
+ msg = 'Use of mediawiki.api callback params is deprecated. Use the Promise instead.',
xhr;
parameters = $.extend( {}, this.defaults.parameters, parameters );
// Backwards compatibility: Before MediaWiki 1.20,
// callbacks were done with the 'ok' and 'err' property in ajaxOptions.
if ( ajaxOptions.ok ) {
+ mw.track( 'mw.deprecate', 'api.cbParam' );
+ mw.log.warn( msg );
apiDeferred.done( ajaxOptions.ok );
delete ajaxOptions.ok;
}
if ( ajaxOptions.err ) {
+ mw.track( 'mw.deprecate', 'api.cbParam' );
+ mw.log.warn( msg );
apiDeferred.fail( ajaxOptions.err );
delete ajaxOptions.err;
}
} );
} )
// AJAX success just means "200 OK" response, also check API error codes
- .done( function ( result ) {
+ .done( function ( result, textStatus, jqXHR ) {
if ( result === undefined || result === null || result === '' ) {
apiDeferred.reject( 'ok-but-empty',
'OK response but empty result (check HTTP headers?)'
var code = result.error.code === undefined ? 'unknown' : result.error.code;
apiDeferred.reject( code, result );
} else {
- apiDeferred.resolve( result );
+ apiDeferred.resolve( result, jqXHR );
}
} );
apiPromise = this.get( {
action: 'tokens',
type: type
- }, {
- // Due to the API assuming we're logged out if we pass the callback-parameter,
- // we have to disable jQuery's callback system, and instead parse JSON string,
- // by setting 'jsonp' to false.
- // TODO: This concern seems genuine but no other module has it. Is it still
- // needed and/or should we pass this by default?
} )
.done( function ( data ) {
// If token type is not available for this user,