2011-12-21 23:52:37 +00:00
|
|
|
/**
|
2013-01-13 00:47:00 +00:00
|
|
|
* @class mw.Api.plugin.parse
|
2011-12-21 23:52:37 +00:00
|
|
|
*/
|
2012-06-07 20:45:53 +00:00
|
|
|
( function ( mw, $ ) {
|
2011-12-09 04:48:39 +00:00
|
|
|
|
2011-12-21 23:52:37 +00:00
|
|
|
$.extend( mw.Api.prototype, {
|
2011-12-09 04:48:39 +00:00
|
|
|
/**
|
2013-01-13 00:47:00 +00:00
|
|
|
* Convinience method for 'action=parse'.
|
2011-12-21 23:52:37 +00:00
|
|
|
*
|
2013-01-13 00:47:00 +00:00
|
|
|
* @param {string} wikitext
|
|
|
|
|
* @param {Function} [ok] Success callback (deprecated)
|
|
|
|
|
* @param {Function} [err] Error callback (deprecated)
|
2012-06-07 20:45:53 +00:00
|
|
|
* @return {jQuery.Promise}
|
2013-01-13 00:47:00 +00:00
|
|
|
* @return {Function} return.done
|
|
|
|
|
* @return {string} return.done.data Parsed HTML of `wikitext`.
|
2011-12-09 04:48:39 +00:00
|
|
|
*/
|
2013-01-13 00:47:00 +00:00
|
|
|
parse: function ( wikitext, ok, err ) {
|
|
|
|
|
var d = $.Deferred();
|
2012-06-07 20:45:53 +00:00
|
|
|
// Backwards compatibility (< MW 1.20)
|
2013-01-13 00:47:00 +00:00
|
|
|
d.done( ok );
|
|
|
|
|
d.fail( err );
|
2012-06-07 20:45:53 +00:00
|
|
|
|
|
|
|
|
this.get( {
|
|
|
|
|
action: 'parse',
|
2013-01-13 00:47:00 +00:00
|
|
|
text: wikitext
|
2012-06-07 20:45:53 +00:00
|
|
|
} )
|
|
|
|
|
.done( function ( data ) {
|
2011-12-27 00:44:49 +00:00
|
|
|
if ( data.parse && data.parse.text && data.parse.text['*'] ) {
|
2013-01-13 00:47:00 +00:00
|
|
|
d.resolve( data.parse.text['*'] );
|
2011-12-21 23:52:37 +00:00
|
|
|
}
|
2012-06-07 20:45:53 +00:00
|
|
|
} )
|
2013-01-13 00:47:00 +00:00
|
|
|
.fail( d.reject );
|
2011-12-09 04:48:39 +00:00
|
|
|
|
2013-01-13 00:47:00 +00:00
|
|
|
return d.promise();
|
2012-06-07 20:45:53 +00:00
|
|
|
}
|
2011-12-21 23:52:37 +00:00
|
|
|
} );
|
2011-12-09 04:48:39 +00:00
|
|
|
|
2013-01-13 00:47:00 +00:00
|
|
|
/**
|
|
|
|
|
* @class mw.Api
|
|
|
|
|
* @mixins mw.Api.plugin.parse
|
|
|
|
|
*/
|
|
|
|
|
|
2012-08-27 17:43:14 +00:00
|
|
|
}( mediaWiki, jQuery ) );
|