Merge "Add tests for WikiMap and WikiReference"
[lhc/web/wiklou.git] / resources / src / mediawiki.api / mediawiki.api.edit.js
1 /**
2 * @class mw.Api.plugin.edit
3 */
4 ( function ( mw, $ ) {
5
6 $.extend( mw.Api.prototype, {
7
8 /**
9 * Post to API with edit 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.
12 *
13 * @param {Object} params API parameters
14 * @param {Object} [ajaxOptions]
15 * @return {jQuery.Promise} See #post
16 */
17 postWithEditToken: function ( params, ajaxOptions ) {
18 return this.postWithToken( 'edit', params, ajaxOptions );
19 },
20
21 /**
22 * API helper to grab an edit token.
23 *
24 * @return {jQuery.Promise}
25 * @return {Function} return.done
26 * @return {string} return.done.token Received token.
27 */
28 getEditToken: function () {
29 return this.getToken( 'edit' );
30 },
31
32 /**
33 * Post a new section to the page.
34 *
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}
41 */
42 newSection: function ( title, header, message, additionalParams ) {
43 return this.postWithEditToken( $.extend( {
44 action: 'edit',
45 section: 'new',
46 title: String( title ),
47 summary: header,
48 text: message
49 }, additionalParams ) );
50 }
51 } );
52
53 /**
54 * @class mw.Api
55 * @mixins mw.Api.plugin.edit
56 */
57
58 }( mediaWiki, jQuery ) );