| 1 |
( function () { |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
function WikitextMessagePoster( title, api ) { |
| 15 |
this.api = api; |
| 16 |
this.title = title; |
| 17 |
} |
| 18 |
|
| 19 |
OO.inheritClass( |
| 20 |
WikitextMessagePoster, |
| 21 |
mw.messagePoster.MessagePoster |
| 22 |
); |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
WikitextMessagePoster.prototype.post = function ( subject, body, options ) { |
| 32 |
options = options || {}; |
| 33 |
mw.messagePoster.WikitextMessagePoster.super.prototype.post.call( this, subject, body, options ); |
| 34 |
|
| 35 |
|
| 36 |
if ( body.indexOf( '~~~' ) === -1 ) { |
| 37 |
body += '\n\n~~~~'; |
| 38 |
} |
| 39 |
|
| 40 |
const additionalParams = { redirect: true }; |
| 41 |
if ( options.tags !== undefined ) { |
| 42 |
additionalParams.tags = options.tags; |
| 43 |
} |
| 44 |
return this.api.newSection( |
| 45 |
this.title, |
| 46 |
subject, |
| 47 |
body, |
| 48 |
additionalParams |
| 49 |
).then( ( resp, jqXHR ) => { |
| 50 |
if ( resp.edit.result === 'Success' ) { |
| 51 |
return $.Deferred().resolve( resp, jqXHR ); |
| 52 |
} else { |
| 53 |
|
| 54 |
|
| 55 |
return $.Deferred().reject( 'api-unexpected' ); |
| 56 |
} |
| 57 |
}, ( code, details ) => $.Deferred().reject( 'api-fail', code, details ) ).promise(); |
| 58 |
}; |
| 59 |
|
| 60 |
mw.messagePoster.factory.register( 'wikitext', WikitextMessagePoster ); |
| 61 |
mw.messagePoster.WikitextMessagePoster = WikitextMessagePoster; |
| 62 |
}() ); |