[mediawiki.api] bug fixes
[mediawiki.git] / resources / mediawiki / mediawiki.api.parse.js
blobc29d734ef6a18d5e56c8a1244bc663621ef7339a
1 /**
2  * Additional mw.Api methods to assist with API calls related to parsing wikitext.
3  */
5 ( function( $, mw ) {
7         $.extend( mw.Api.prototype, {
8                 /**
9                  * Convinience method for 'action=parse'. Parses wikitext into HTML.
10                  *
11                  * @param wikiText {String}
12                  * @param success {Function} callback to which to pass success HTML
13                  * @param err {Function} callback if error (optional)
14                  * @return {jqXHR}
15                  */
16                 parse: function( wikiText, success, err ) {
17                         var params = {
18                                         text: wikiText,
19                                         action: 'parse'
20                                 },
21                                 ok = function( data ) {
22                                         if ( data && data.parse && data.parse.text && data.parse.text['*'] ) {
23                                                 success( data.parse.text['*'] );
24                                         }
25                                 };
26                         return this.get( params, { ok: ok, err: err } );
27                 }
29         } );
31 } )( jQuery, mediaWiki );