Merge "Import: Handle uploads with sha1 starting with 0 properly"
[mediawiki.git] / resources / src / mediawiki / api / edit.js
blob22affb1dab5dc3450d1edd38426cc29a44a61211
1 /**
2  * @class mw.Api.plugin.edit
3  */
4 ( function ( mw, $ ) {
6         $.extend( mw.Api.prototype, {
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                 },
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                 },
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         } );
53         /**
54          * @class mw.Api
55          * @mixins mw.Api.plugin.edit
56          */
58 }( mediaWiki, jQuery ) );