mediawiki.api.edit: Remove "format: 'json'"
[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 var msg = 'Use of mediawiki.api callback params is deprecated. Use the Promise instead.';
7 $.extend( mw.Api.prototype, {
8
9 /**
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.
13 *
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
18 */
19 postWithEditToken: function ( params, ok, err ) {
20 if ( ok || err ) {
21 mw.track( 'mw.deprecate', 'api.cbParam' );
22 mw.log.warn( msg );
23 }
24
25 return this.postWithToken( 'edit', params ).done( ok ).fail( err );
26 },
27
28 /**
29 * API helper to grab an edit token.
30 *
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.
36 */
37 getEditToken: function ( ok, err ) {
38 if ( ok || err ) {
39 mw.track( 'mw.deprecate', 'api.cbParam' );
40 mw.log.warn( msg );
41 }
42
43 return this.getToken( 'edit' ).done( ok ).fail( err );
44 },
45
46 /**
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}
56 */
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 ) ) {
61 err = ok;
62 ok = additionalParams;
63 additionalParams = undefined;
64 }
65
66 if ( ok || err ) {
67 mw.track( 'mw.deprecate', 'api.cbParam' );
68 mw.log.warn( msg );
69 }
70
71 return this.postWithEditToken( $.extend( {
72 action: 'edit',
73 section: 'new',
74 title: String( title ),
75 summary: header,
76 text: message
77 }, additionalParams ) ).done( ok ).fail( err );
78 }
79 } );
80
81 /**
82 * @class mw.Api
83 * @mixins mw.Api.plugin.edit
84 */
85
86 }( mediaWiki, jQuery ) );