blob: f38e88b5c38c0d3724a0ffda14af74f134046329 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
/**
* @class mw.Api.plugin.parse
*/
( function ( mw, $ ) {
$.extend( mw.Api.prototype, {
/**
* Convenience method for 'action=parse'.
*
* @param {string|mw.Title} content Content to parse, either as a wikitext string or
* a mw.Title.
* @param {Object} additionalParams Parameters object to set custom settings, e.g.
* redirects, sectionpreview. prop should not be overridden.
* @return {jQuery.Promise}
* @return {Function} return.done
* @return {string} return.done.data Parsed HTML of `wikitext`.
*/
parse: function ( content, additionalParams ) {
var apiPromise,
config = $.extend( {
formatversion: 2,
action: 'parse',
contentmodel: 'wikitext'
}, additionalParams );
if ( mw.Title && content instanceof mw.Title ) {
// Parse existing page
config.page = content.getPrefixedDb();
} else {
// Parse wikitext from input
config.text = String( content );
}
apiPromise = this.get( config );
return apiPromise
.then( function ( data ) {
return data.parse.text;
} )
.promise( { abort: apiPromise.abort } );
}
} );
/**
* @class mw.Api
* @mixins mw.Api.plugin.parse
*/
}( mediaWiki, jQuery ) );
|