summaryrefslogtreecommitdiff
path: root/resources/src/mediawiki.api/mediawiki.api.parse.js
diff options
context:
space:
mode:
Diffstat (limited to 'resources/src/mediawiki.api/mediawiki.api.parse.js')
-rw-r--r--resources/src/mediawiki.api/mediawiki.api.parse.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/resources/src/mediawiki.api/mediawiki.api.parse.js b/resources/src/mediawiki.api/mediawiki.api.parse.js
new file mode 100644
index 00000000..b1f1d2b0
--- /dev/null
+++ b/resources/src/mediawiki.api/mediawiki.api.parse.js
@@ -0,0 +1,45 @@
+/**
+ * @class mw.Api.plugin.parse
+ */
+( function ( mw, $ ) {
+
+ $.extend( mw.Api.prototype, {
+ /**
+ * Convenience method for 'action=parse'.
+ *
+ * @param {string} wikitext
+ * @param {Function} [ok] Success callback (deprecated)
+ * @param {Function} [err] Error callback (deprecated)
+ * @return {jQuery.Promise}
+ * @return {Function} return.done
+ * @return {string} return.done.data Parsed HTML of `wikitext`.
+ */
+ parse: function ( wikitext, ok, err ) {
+ var apiPromise = this.get( {
+ action: 'parse',
+ contentmodel: 'wikitext',
+ text: wikitext
+ } );
+
+ // Backwards compatibility (< MW 1.20)
+ if ( ok || err ) {
+ mw.track( 'mw.deprecate', 'api.cbParam' );
+ mw.log.warn( 'Use of mediawiki.api callback params is deprecated. Use the Promise instead.' );
+ }
+
+ return apiPromise
+ .then( function ( data ) {
+ return data.parse.text['*'];
+ } )
+ .done( ok )
+ .fail( err )
+ .promise( { abort: apiPromise.abort } );
+ }
+ } );
+
+ /**
+ * @class mw.Api
+ * @mixins mw.Api.plugin.parse
+ */
+
+}( mediaWiki, jQuery ) );