2 * @class mw.Api.plugin.edit
6 var msg
= 'Use of mediawiki.api callback params is deprecated. Use the Promise instead.';
7 $.extend( mw
.Api
.prototype, {
10 * Post to API with edit token. If we have no token, get one and try to post.
11 * If we have a cached token try using that, and if it fails, blank out the
12 * cached token and start over.
14 * @param {Object} params API parameters
15 * @param {Function} [ok] Success callback (deprecated)
16 * @param {Function} [err] Error callback (deprecated)
17 * @return {jQuery.Promise} See #post
19 postWithEditToken: function ( params
, ok
, err
) {
21 mw
.track( 'mw.deprecate', 'api.cbParam' );
25 return this.postWithToken( 'edit', params
).done( ok
).fail( err
);
29 * API helper to grab an edit token.
31 * @param {Function} [ok] Success callback (deprecated)
32 * @param {Function} [err] Error callback (deprecated)
33 * @return {jQuery.Promise}
34 * @return {Function} return.done
35 * @return {string} return.done.token Received token.
37 getEditToken: function ( ok
, err
) {
39 mw
.track( 'mw.deprecate', 'api.cbParam' );
43 return this.getToken( 'edit' ).done( ok
).fail( err
);
47 * Post a new section to the page.
48 * @see #postWithEditToken
49 * @param {mw.Title|String} title Target page
50 * @param {string} header
51 * @param {string} message wikitext message
52 * @param {Object} [additionalParams] Additional API parameters, e.g. `{ redirect: true }`
53 * @param {Function} [ok] Success handler (deprecated)
54 * @param {Function} [err] Error handler (deprecated)
55 * @return {jQuery.Promise}
57 newSection: function ( title
, header
, message
, additionalParams
, ok
, err
) {
58 // Until we remove 'ok' and 'err' parameters, we have to support code that passes them,
59 // but not additionalParams...
60 if ( $.isFunction( additionalParams
) ) {
62 ok
= additionalParams
;
63 additionalParams
= undefined;
67 mw
.track( 'mw.deprecate', 'api.cbParam' );
71 return this.postWithEditToken( $.extend( {
74 title
: String( title
),
77 }, additionalParams
) ).done( ok
).fail( err
);
83 * @mixins mw.Api.plugin.edit
86 }( mediaWiki
, jQuery
) );