3 * @classdesc Posts messages to wikitext talk pages.
5 * @class mw.messagePoster.WikitextMessagePoster
6 * @extends mw.messagePoster.MessagePoster
7 * @type {mw.messagePoster.WikitextMessagePoster}
10 * @description Create an instance of `mw.messagePoster.WikitextMessagePoster`.
11 * @param {mw.Title} title Wikitext page in a talk namespace, to post to
12 * @param {mw.Api} api mw.Api object to use
14 function WikitextMessagePoster( title, api ) {
20 WikitextMessagePoster,
21 mw.messagePoster.MessagePoster
26 * @param {string} subject Section title.
27 * @param {string} body Message body, as wikitext. Signature code will automatically be added unless the message already contains the string ~~~.
28 * @param {Object} [options] Message options:
29 * @param {string} [options.tags] [Change tags](https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Tags) to add to the message's revision, pipe-separated.
31 WikitextMessagePoster.prototype.post = function ( subject, body, options ) {
32 options = options || {};
33 mw.messagePoster.WikitextMessagePoster.super.prototype.post.call( this, subject, body, options );
35 // Add signature if needed
36 if ( body.indexOf( '~~~' ) === -1 ) {
40 const additionalParams = { redirect: true };
41 if ( options.tags !== undefined ) {
42 additionalParams.tags = options.tags;
44 return this.api.newSection(
49 ).then( ( resp, jqXHR ) => {
50 if ( resp.edit.result === 'Success' ) {
51 return $.Deferred().resolve( resp, jqXHR );
53 // mw.Api checks for response error. Are there actually cases where the
54 // request fails, but it's not caught there?
55 return $.Deferred().reject( 'api-unexpected' );
57 }, ( code, details ) => $.Deferred().reject( 'api-fail', code, details ) ).promise();
60 mw.messagePoster.factory.register( 'wikitext', WikitextMessagePoster );
61 mw.messagePoster.WikitextMessagePoster = WikitextMessagePoster;