Merge "ApiQueryInfo: fix query limits for testactions"
[lhc/web/wiklou.git] / resources / src / mediawiki.messagePoster.wikitext / WikitextMessagePoster.js
1 ( function ( mw, $ ) {
2 /**
3 * This is an implementation of MessagePoster for wikitext talk pages.
4 *
5 * @class mw.messagePoster.WikitextMessagePoster
6 * @extends mw.messagePoster.MessagePoster
7 *
8 * @constructor
9 * @param {mw.Title} title Wikitext page in a talk namespace, to post to
10 * @param {mw.Api} api mw.Api object to use
11 */
12 function WikitextMessagePoster( title, api ) {
13 this.api = api;
14 this.title = title;
15 }
16
17 OO.inheritClass(
18 WikitextMessagePoster,
19 mw.messagePoster.MessagePoster
20 );
21
22 /**
23 * @inheritdoc
24 */
25 WikitextMessagePoster.prototype.post = function ( subject, body ) {
26 mw.messagePoster.WikitextMessagePoster.parent.prototype.post.call( this, subject, body );
27
28 // Add signature if needed
29 if ( body.indexOf( '~~~' ) === -1 ) {
30 body += '\n\n~~~~';
31 }
32
33 return this.api.newSection(
34 this.title,
35 subject,
36 body,
37 { redirect: true }
38 ).then( function ( resp, jqXHR ) {
39 if ( resp.edit.result === 'Success' ) {
40 return $.Deferred().resolve( resp, jqXHR );
41 } else {
42 // mw.Api checks for response error. Are there actually cases where the
43 // request fails, but it's not caught there?
44 return $.Deferred().reject( 'api-unexpected' );
45 }
46 }, function ( code, details ) {
47 return $.Deferred().reject( 'api-fail', code, details );
48 } ).promise();
49 };
50
51 mw.messagePoster.factory.register( 'wikitext', WikitextMessagePoster );
52 mw.messagePoster.WikitextMessagePoster = WikitextMessagePoster;
53 }( mediaWiki, jQuery ) );