2 * @class mw.Api.plugin.edit
6 $.extend( mw
.Api
.prototype, {
9 * Post to API with csrf token. If we have no token, get one and try to post.
10 * If we have a cached token try using that, and if it fails, blank out the
11 * cached token and start over.
13 * @param {Object} params API parameters
14 * @param {Object} [ajaxOptions]
15 * @return {jQuery.Promise} See #post
17 postWithEditToken: function ( params
, ajaxOptions
) {
18 return this.postWithToken( 'csrf', params
, ajaxOptions
);
22 * API helper to grab a csrf token.
24 * @return {jQuery.Promise}
25 * @return {Function} return.done
26 * @return {string} return.done.token Received token.
28 getEditToken: function () {
29 return this.getToken( 'csrf' );
33 * Post a new section to the page.
35 * @see #postWithEditToken
36 * @param {mw.Title|string} title Target page
37 * @param {string} header
38 * @param {string} message wikitext message
39 * @param {Object} [additionalParams] Additional API parameters, e.g. `{ redirect: true }`
40 * @return {jQuery.Promise}
42 newSection: function ( title
, header
, message
, additionalParams
) {
43 return this.postWithEditToken( $.extend( {
46 title
: String( title
),
49 }, additionalParams
) );
55 * @mixins mw.Api.plugin.edit
58 }( mediaWiki
, jQuery
) );