wiki.techinc.nl/resources/mediawiki.api/mediawiki.api.parse.js
Timo Tijhof e9186da841 Pass JSHint on resources/{mediawiki.api,jquery,mediawiki}/*
Notes:
* JSHint stuff
* Code conventions
* jQuery best practices
* mediawiki.debug:
  - Append a text node instead of html. Though .append()
    does check if it looks "like" not-html and creates a text
    node, this is not more a sanity/security thing than a
    reliable documented feature. http://api.jquery.com/append/ :
    "HTML string, DOM element(s) or jQuery object".

While at it:
* Update .jshintignore to also cover:
  - resources/mediawiki.libs/CLDRPluralRuleParser.js
* Update .jshintrc to set onevar back to true (was set to false
  temporarily but not removed).
* Fix files in resources/mediawiki and resources/jquery as well.
  These dirs where already covered, perhaps these were missed or
  recently introduced, again.
* Add missing dependencies:
  jquery.highlightText -> jquery.mwExtension ($.escapeRE)
  jquery.tablesorter -> jquery.mwExtension ($.escapeRE)
  mediawiki.page.watch.ajax -> jquery.mwExtension ($.escapeRE)

Change-Id: I30a55717d0963ce23e51cef1f1df9e549e4c232e
2012-09-03 23:44:08 +02:00

42 lines
962 B
JavaScript

/**
* mw.Api methods for parsing wikitext.
*/
( function ( mw, $ ) {
$.extend( mw.Api.prototype, {
/**
* Convinience method for 'action=parse'. Parses wikitext into HTML.
*
* @param wikiText {String}
* @param ok {Function} [optional] deprecated (success callback)
* @param err {Function} [optional] deprecated (error callback)
* @return {jQuery.Promise}
*/
parse: function ( wikiText, ok, err ) {
var apiDeferred = $.Deferred();
// Backwards compatibility (< MW 1.20)
if ( ok ) {
apiDeferred.done( ok );
}
if ( err ) {
apiDeferred.fail( err );
}
this.get( {
action: 'parse',
text: wikiText
} )
.done( function ( data ) {
if ( data.parse && data.parse.text && data.parse.text['*'] ) {
apiDeferred.resolve( data.parse.text['*'] );
}
} )
.fail( apiDeferred.reject );
// Return the promise
return apiDeferred.promise();
}
} );
}( mediaWiki, jQuery ) );