3 * This is an implementation of MessagePoster for wikitext talk pages.
5 * @class mw.messagePoster.WikitextMessagePoster
6 * @extends mw.messagePoster.MessagePoster
9 * @param {mw.Title} title Wikitext page in a talk namespace, to post to
10 * @param {mw.Api} api mw.Api object to use
12 function WikitextMessagePoster( title
, api
) {
18 WikitextMessagePoster
,
19 mw
.messagePoster
.MessagePoster
24 * @param {string} subject Section title.
25 * @param {string} body Message body, as wikitext. Signature code will automatically be added unless the message already contains the string ~~~.
26 * @param {Object} [options] Message options:
27 * @param {string} [options.tags] [Change tags](https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Tags) to add to the message's revision, pipe-separated.
29 WikitextMessagePoster
.prototype.post = function ( subject
, body
, options
) {
31 options
= options
|| {};
32 mw
.messagePoster
.WikitextMessagePoster
.parent
.prototype.post
.call( this, subject
, body
, options
);
34 // Add signature if needed
35 if ( body
.indexOf( '~~~' ) === -1 ) {
39 additionalParams
= { redirect
: true };
40 if ( options
.tags
!== undefined ) {
41 additionalParams
.tags
= options
.tags
;
43 return this.api
.newSection(
48 ).then( function ( resp
, jqXHR
) {
49 if ( resp
.edit
.result
=== 'Success' ) {
50 return $.Deferred().resolve( resp
, jqXHR
);
52 // mw.Api checks for response error. Are there actually cases where the
53 // request fails, but it's not caught there?
54 return $.Deferred().reject( 'api-unexpected' );
56 }, function ( code
, details
) {
57 return $.Deferred().reject( 'api-fail', code
, details
);
61 mw
.messagePoster
.factory
.register( 'wikitext', WikitextMessagePoster
);
62 mw
.messagePoster
.WikitextMessagePoster
= WikitextMessagePoster
;