From d576babcc4fbd020981c521bf8541bec8b13a7a9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Sat, 28 Jun 2014 13:44:19 +0200 Subject: [PATCH] mediawiki.api: Remove deprecated function parameters * 'ok' and 'err' parameters to various functions. Tracked with mw.track( 'mw.deprecate' ) as 'api.cbParam'. Deprecated since MW 1.20, printing console warnings since MW 1.23. * 'async' parameter to mediawiki.api.category #getCategories. Tracked with mw.track( 'mw.deprecate' ) as 'api.async'. Deprecated and printing console warnings since MW 1.23. Also removed is mw.Api#normalizeAjaxOptions, which is no longer needed and which has never been used by anything outside mediawiki.api module. Announced in https://www.mail-archive.com/wikitech-l%40lists.wikimedia.org/msg78108.html Change-Id: I0a650fdb4affd394ae419e21d54baf790116f6f7 --- RELEASE-NOTES-1.25 | 4 ++ .../mediawiki.api/mediawiki.api.category.js | 44 ++----------------- .../src/mediawiki.api/mediawiki.api.edit.js | 42 +++--------------- resources/src/mediawiki.api/mediawiki.api.js | 41 ++--------------- .../src/mediawiki.api/mediawiki.api.parse.js | 12 +---- .../src/mediawiki.api/mediawiki.api.watch.js | 21 +++------ .../mediawiki.api/mediawiki.api.test.js | 38 ---------------- 7 files changed, 24 insertions(+), 178 deletions(-) diff --git a/RELEASE-NOTES-1.25 b/RELEASE-NOTES-1.25 index 7ee3ff76e1..7bb3a432e9 100644 --- a/RELEASE-NOTES-1.25 +++ b/RELEASE-NOTES-1.25 @@ -42,6 +42,10 @@ changes to languages because of Bugzilla reports. * Removed LogEventsList::getDisplayTitle(). (deprecated since 1.20) * Removed Preferences::trySetUserEmail(). (deprecated since 1.20) * Removed mw.user.name() and mw.user.anonymous() methods. (deprecated since 1.20) +* Removed 'ok' and 'err' parameters in the mediawiki.api modules. (deprecated + since 1.20) +* Removed 'async' parameter from the mw.Api#getCategories() method. (deprecated + since 1.20) == Compatibility == diff --git a/resources/src/mediawiki.api/mediawiki.api.category.js b/resources/src/mediawiki.api/mediawiki.api.category.js index 7dd9730f77..14077e022f 100644 --- a/resources/src/mediawiki.api/mediawiki.api.category.js +++ b/resources/src/mediawiki.api/mediawiki.api.category.js @@ -3,29 +3,21 @@ */ ( function ( mw, $ ) { - var msg = 'Use of mediawiki.api callback params is deprecated. Use the Promise instead.'; $.extend( mw.Api.prototype, { /** * Determine if a category exists. * * @param {mw.Title|string} title - * @param {Function} [ok] Success callback (deprecated) - * @param {Function} [err] Error callback (deprecated) * @return {jQuery.Promise} * @return {Function} return.done * @return {boolean} return.done.isCategory Whether the category exists. */ - isCategory: function ( title, ok, err ) { + isCategory: function ( title ) { var apiPromise = this.get( { prop: 'categoryinfo', titles: String( title ) } ); - if ( ok || err ) { - mw.track( 'mw.deprecate', 'api.cbParam' ); - mw.log.warn( msg ); - } - return apiPromise .then( function ( data ) { var exists = false; @@ -38,8 +30,6 @@ } return exists; } ) - .done( ok ) - .fail( err ) .promise( { abort: apiPromise.abort } ); }, @@ -49,13 +39,11 @@ * E.g. given "Foo", return "Food", "Foolish people", "Foosball tables"... * * @param {string} prefix Prefix to match. - * @param {Function} [ok] Success callback (deprecated) - * @param {Function} [err] Error callback (deprecated) * @return {jQuery.Promise} * @return {Function} return.done * @return {string[]} return.done.categories Matched categories */ - getCategoriesByPrefix: function ( prefix, ok, err ) { + getCategoriesByPrefix: function ( prefix ) { // Fetch with allpages to only get categories that have a corresponding description page. var apiPromise = this.get( { list: 'allpages', @@ -63,11 +51,6 @@ apnamespace: mw.config.get( 'wgNamespaceIds' ).category } ); - if ( ok || err ) { - mw.track( 'mw.deprecate', 'api.cbParam' ); - mw.log.warn( msg ); - } - return apiPromise .then( function ( data ) { var texts = []; @@ -78,8 +61,6 @@ } return texts; } ) - .done( ok ) - .fail( err ) .promise( { abort: apiPromise.abort } ); }, @@ -87,34 +68,17 @@ * Get the categories that a particular page on the wiki belongs to. * * @param {mw.Title|string} title - * @param {Function} [ok] Success callback (deprecated) - * @param {Function} [err] Error callback (deprecated) - * @param {boolean} [async=true] Asynchronousness (deprecated) * @return {jQuery.Promise} * @return {Function} return.done * @return {boolean|mw.Title[]} return.done.categories List of category titles or false * if title was not found. */ - getCategories: function ( title, ok, err, async ) { + getCategories: function ( title ) { var apiPromise = this.get( { prop: 'categories', titles: String( title ) - }, { - async: async === undefined ? true : async } ); - if ( ok || err ) { - mw.track( 'mw.deprecate', 'api.cbParam' ); - mw.log.warn( msg ); - } - if ( async !== undefined ) { - mw.track( 'mw.deprecate', 'api.async' ); - mw.log.warn( - 'Use of mediawiki.api async=false param is deprecated. ' + - 'The sychronous mode will be removed in the future.' - ); - } - return apiPromise .then( function ( data ) { var titles = false; @@ -132,8 +96,6 @@ } return titles; } ) - .done( ok ) - .fail( err ) .promise( { abort: apiPromise.abort } ); } } ); diff --git a/resources/src/mediawiki.api/mediawiki.api.edit.js b/resources/src/mediawiki.api/mediawiki.api.edit.js index 714c38cd27..dbe45bf618 100644 --- a/resources/src/mediawiki.api/mediawiki.api.edit.js +++ b/resources/src/mediawiki.api/mediawiki.api.edit.js @@ -3,7 +3,6 @@ */ ( function ( mw, $ ) { - var msg = 'Use of mediawiki.api callback params is deprecated. Use the Promise instead.'; $.extend( mw.Api.prototype, { /** @@ -12,35 +11,21 @@ * cached token and start over. * * @param {Object} params API parameters - * @param {Function} [ok] Success callback (deprecated) - * @param {Function} [err] Error callback (deprecated) * @return {jQuery.Promise} See #post */ - postWithEditToken: function ( params, ok, err ) { - if ( ok || err ) { - mw.track( 'mw.deprecate', 'api.cbParam' ); - mw.log.warn( msg ); - } - - return this.postWithToken( 'edit', params ).done( ok ).fail( err ); + postWithEditToken: function ( params ) { + return this.postWithToken( 'edit', params ); }, /** * API helper to grab an edit token. * - * @param {Function} [ok] Success callback (deprecated) - * @param {Function} [err] Error callback (deprecated) * @return {jQuery.Promise} * @return {Function} return.done * @return {string} return.done.token Received token. */ - getEditToken: function ( ok, err ) { - if ( ok || err ) { - mw.track( 'mw.deprecate', 'api.cbParam' ); - mw.log.warn( msg ); - } - - return this.getToken( 'edit' ).done( ok ).fail( err ); + getEditToken: function () { + return this.getToken( 'edit' ); }, /** @@ -50,31 +35,16 @@ * @param {string} header * @param {string} message wikitext message * @param {Object} [additionalParams] Additional API parameters, e.g. `{ redirect: true }` - * @param {Function} [ok] Success handler (deprecated) - * @param {Function} [err] Error handler (deprecated) * @return {jQuery.Promise} */ - newSection: function ( title, header, message, additionalParams, ok, err ) { - // Until we remove 'ok' and 'err' parameters, we have to support code that passes them, - // but not additionalParams... - if ( $.isFunction( additionalParams ) ) { - err = ok; - ok = additionalParams; - additionalParams = undefined; - } - - if ( ok || err ) { - mw.track( 'mw.deprecate', 'api.cbParam' ); - mw.log.warn( msg ); - } - + newSection: function ( title, header, message, additionalParams ) { return this.postWithEditToken( $.extend( { action: 'edit', section: 'new', title: String( title ), summary: header, text: message - }, additionalParams ) ).done( ok ).fail( err ); + }, additionalParams ) ); } } ); diff --git a/resources/src/mediawiki.api/mediawiki.api.js b/resources/src/mediawiki.api/mediawiki.api.js index e5c85dfa97..b85c8e8df3 100644 --- a/resources/src/mediawiki.api/mediawiki.api.js +++ b/resources/src/mediawiki.api/mediawiki.api.js @@ -74,32 +74,15 @@ mw.Api.prototype = { - /** - * Normalize the ajax options for compatibility and/or convenience methods. - * - * @param {Object} [arg] An object contaning one or more of options.ajax. - * @return {Object} Normalized ajax options. - */ - normalizeAjaxOptions: function ( arg ) { - // Arg argument is usually empty - // (before MW 1.20 it was used to pass ok callbacks) - var opts = arg || {}; - // Options can also be a success callback handler - if ( typeof arg === 'function' ) { - opts = { ok: arg }; - } - return opts; - }, - /** * Perform API get request * * @param {Object} parameters - * @param {Object|Function} [ajaxOptions] + * @param {Object} [ajaxOptions] * @return {jQuery.Promise} */ get: function ( parameters, ajaxOptions ) { - ajaxOptions = this.normalizeAjaxOptions( ajaxOptions ); + ajaxOptions = ajaxOptions || {}; ajaxOptions.type = 'GET'; return this.ajax( parameters, ajaxOptions ); }, @@ -110,11 +93,11 @@ * TODO: Post actions for non-local hostnames will need proxy. * * @param {Object} parameters - * @param {Object|Function} [ajaxOptions] + * @param {Object} [ajaxOptions] * @return {jQuery.Promise} */ post: function ( parameters, ajaxOptions ) { - ajaxOptions = this.normalizeAjaxOptions( ajaxOptions ); + ajaxOptions = ajaxOptions || {}; ajaxOptions.type = 'POST'; return this.ajax( parameters, ajaxOptions ); }, @@ -130,7 +113,6 @@ ajax: function ( parameters, ajaxOptions ) { var token, apiDeferred = $.Deferred(), - msg = 'Use of mediawiki.api callback params is deprecated. Use the Promise instead.', xhr, key, formData; parameters = $.extend( {}, this.defaults.parameters, parameters ); @@ -183,21 +165,6 @@ } } - // 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; - } - // Make the AJAX request xhr = $.ajax( ajaxOptions ) // If AJAX fails, reject API call with error code 'http' diff --git a/resources/src/mediawiki.api/mediawiki.api.parse.js b/resources/src/mediawiki.api/mediawiki.api.parse.js index b1f1d2b06f..2dcf8078fe 100644 --- a/resources/src/mediawiki.api/mediawiki.api.parse.js +++ b/resources/src/mediawiki.api/mediawiki.api.parse.js @@ -8,31 +8,21 @@ * Convenience method for 'action=parse'. * * @param {string} wikitext - * @param {Function} [ok] Success callback (deprecated) - * @param {Function} [err] Error callback (deprecated) * @return {jQuery.Promise} * @return {Function} return.done * @return {string} return.done.data Parsed HTML of `wikitext`. */ - parse: function ( wikitext, ok, err ) { + parse: function ( wikitext ) { var apiPromise = this.get( { action: 'parse', contentmodel: 'wikitext', text: wikitext } ); - // Backwards compatibility (< MW 1.20) - if ( ok || err ) { - mw.track( 'mw.deprecate', 'api.cbParam' ); - mw.log.warn( 'Use of mediawiki.api callback params is deprecated. Use the Promise instead.' ); - } - return apiPromise .then( function ( data ) { return data.parse.text['*']; } ) - .done( ok ) - .fail( err ) .promise( { abort: apiPromise.abort } ); } } ); diff --git a/resources/src/mediawiki.api/mediawiki.api.watch.js b/resources/src/mediawiki.api/mediawiki.api.watch.js index af2dee10ad..40ba136d3f 100644 --- a/resources/src/mediawiki.api/mediawiki.api.watch.js +++ b/resources/src/mediawiki.api/mediawiki.api.watch.js @@ -12,8 +12,6 @@ * @param {string|mw.Title|string[]|mw.Title[]} pages Full page name or instance of mw.Title, or an * array thereof. If an array is passed, the return value passed to the promise will also be an * array of appropriate objects. - * @param {Function} [ok] Success callback (deprecated) - * @param {Function} [err] Error callback (deprecated) * @return {jQuery.Promise} * @return {Function} return.done * @return {Object|Object[]} return.done.watch Object or list of objects (depends on the `pages` @@ -22,7 +20,7 @@ * @return {boolean} return.done.watch.watched Whether the page is now watched or unwatched * @return {string} return.done.watch.message Parsed HTML of the confirmational interface message */ - function doWatchInternal( pages, ok, err, addParams ) { + function doWatchInternal( pages, addParams ) { // XXX: Parameter addParams is undocumented because we inherit this // documentation in the public method... var apiPromise = this.postWithToken( 'watch', @@ -36,19 +34,11 @@ ) ); - // Backwards compatibility (< MW 1.20) - if ( ok || err ) { - mw.track( 'mw.deprecate', 'api.cbParam' ); - mw.log.warn( 'Use of mediawiki.api callback params is deprecated. Use the Promise instead.' ); - } - return apiPromise .then( function ( data ) { // If a single page was given (not an array) respond with a single item as well. return $.isArray( pages ) ? data.watch : data.watch[0]; } ) - .done( ok ) - .fail( err ) .promise( { abort: apiPromise.abort } ); } @@ -58,16 +48,17 @@ * * @inheritdoc #doWatchInternal */ - watch: function ( pages, ok, err ) { - return doWatchInternal.call( this, pages, ok, err ); + watch: function ( pages ) { + return doWatchInternal.call( this, pages ); }, + /** * Convenience method for `action=watch&unwatch=1`. * * @inheritdoc #doWatchInternal */ - unwatch: function ( pages, ok, err ) { - return doWatchInternal.call( this, pages, ok, err, { unwatch: 1 } ); + unwatch: function ( pages ) { + return doWatchInternal.call( this, pages, { unwatch: 1 } ); } } ); diff --git a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js index 76fa6bedb2..1d5656e971 100644 --- a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js +++ b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js @@ -61,44 +61,6 @@ } ); } ); - QUnit.test( 'Deprecated callback methods', function ( assert ) { - QUnit.expect( 3 ); - - var api = new mw.Api(); - - this.suppressWarnings(); - - api.get( {}, function () { - assert.ok( true, 'Function argument treated as success callback.' ); - } ); - - api.get( {}, { - ok: function () { - assert.ok( true, '"ok" property treated as success callback.' ); - } - } ); - - api.get( { action: 'doesntexist' }, { - err: function () { - assert.ok( true, '"err" property treated as error callback.' ); - } - } ); - - this.restoreWarnings(); - - this.server.respondWith( /action=query/, function ( request ) { - request.respond( 200, { 'Content-Type': 'application/json' }, '[]' ); - } ); - - this.server.respondWith( /action=doesntexist/, function ( request ) { - request.respond( 200, { 'Content-Type': 'application/json' }, - '{ "error": { "code": "unknown_action" } }' - ); - } ); - - this.server.respond(); - } ); - QUnit.test( 'getToken( pre-populated )', function ( assert ) { QUnit.expect( 2 ); -- 2.20.1