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