Merge "FormOptions: Document getValueReal(), consistency fixes"
[lhc/web/wiklou.git] / resources / 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 {Function} [ok] Success callback (deprecated)
15 * @param {Function} [err] Error callback (deprecated)
16 * @return {jQuery.Promise} See #post
17 */
18 postWithEditToken: function ( params, ok, err ) {
19 return this.postWithToken( 'edit', params ).done( ok ).fail( err );
20 },
21
22 /**
23 * Api helper to grab an edit token.
24 *
25 * @param {Function} [ok] Success callback
26 * @param {Function} [err] Error callback
27 * @return {jQuery.Promise}
28 * @return {Function} return.done
29 * @return {string} return.done.token Received token.
30 */
31 getEditToken: function ( ok, err ) {
32 return this.getToken( 'edit' ).done( ok ).fail( err );
33 },
34
35 /**
36 * Create a new section of the page.
37 * @see #postWithEditToken
38 * @param {mw.Title|String} title Target page
39 * @param {string} header
40 * @param {string} message wikitext message
41 * @param {Function} [ok] Success handler
42 * @param {Function} [err] Error handler
43 * @return {jQuery.Promise}
44 */
45 newSection: function ( title, header, message, ok, err ) {
46 return this.postWithEditToken( {
47 action: 'edit',
48 section: 'new',
49 format: 'json',
50 title: title.toString(),
51 summary: header,
52 text: message
53 }, ok, err );
54 }
55 } );
56
57 /**
58 * @class mw.Api
59 * @mixins mw.Api.plugin.edit
60 */
61
62 }( mediaWiki, jQuery ) );