mediawiki.api: Remove deprecated function parameters
authorBartosz Dziewoński <matma.rex@gmail.com>
Sat, 28 Jun 2014 11:44:19 +0000 (13:44 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Mon, 29 Sep 2014 22:41:55 +0000 (00:41 +0200)
* '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
resources/src/mediawiki.api/mediawiki.api.category.js
resources/src/mediawiki.api/mediawiki.api.edit.js
resources/src/mediawiki.api/mediawiki.api.js
resources/src/mediawiki.api/mediawiki.api.parse.js
resources/src/mediawiki.api/mediawiki.api.watch.js
tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js

index 7ee3ff7..7bb3a43 100644 (file)
@@ -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 ==
 
index 7dd9730..14077e0 100644 (file)
@@ -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 } );
                },
 
                 * 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',
                                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 } );
                },
 
                 * 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;
                                        }
                                        return titles;
                                } )
-                               .done( ok )
-                               .fail( err )
                                .promise( { abort: apiPromise.abort } );
                }
        } );
index 714c38c..dbe45bf 100644 (file)
@@ -3,7 +3,6 @@
  */
 ( function ( mw, $ ) {
 
-       var msg = 'Use of mediawiki.api callback params is deprecated. Use the Promise instead.';
        $.extend( mw.Api.prototype, {
 
                /**
                 * 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' );
                },
 
                /**
                 * @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 ) );
                }
        } );
 
index e5c85df..b85c8e8 100644 (file)
 
        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 );
                },
                 * 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 );
                },
                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 );
                                }
                        }
 
-                       // 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'
index b1f1d2b..2dcf807 100644 (file)
@@ -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 } );
                }
        } );
index af2dee1..40ba136 100644 (file)
@@ -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',
                        )
                );
 
-               // 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 } );
        }
 
                 *
                 * @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 } );
                }
        } );
 
index 76fa6be..1d5656e 100644 (file)
                } );
        } );
 
-       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 );