jenkins-bot has submitted this change and it was merged. Change subject: mediawiki.api.parse: Allow parsing pages ......................................................................
mediawiki.api.parse: Allow parsing pages Bug: T46925 Change-Id: Ic0d762d02c96e0b39b4983d3b66ebdfb6f88d3a2 --- M resources/src/mediawiki/api/parse.js M tests/qunit/suites/resources/mediawiki.api/mediawiki.api.parse.test.js 2 files changed, 29 insertions(+), 7 deletions(-) Approvals: Krinkle: Looks good to me, approved jenkins-bot: Verified diff --git a/resources/src/mediawiki/api/parse.js b/resources/src/mediawiki/api/parse.js index 49219d7..02528dc 100644 --- a/resources/src/mediawiki/api/parse.js +++ b/resources/src/mediawiki/api/parse.js @@ -7,18 +7,30 @@ /** * Convenience method for 'action=parse'. * - * @param {string} wikitext + * @param {string|mw.Title} content Content to parse, either as a wikitext string or + * a mw.Title. + * @param {Object} additionalParams Parameters object to set custom settings, e.g. + * redirects, sectionpreview. prop should not be overridden. * @return {jQuery.Promise} * @return {Function} return.done * @return {string} return.done.data Parsed HTML of `wikitext`. */ - parse: function ( wikitext ) { - var apiPromise = this.get( { + parse: function ( content, additionalParams ) { + var apiPromise, config = $.extend( { formatversion: 2, action: 'parse', - contentmodel: 'wikitext', - text: wikitext - } ); + contentmodel: 'wikitext' + }, additionalParams ); + + if ( typeof content === 'string' ) { + // Wikitext + config.text = content; + } else { + // mw.Title + config.page = content.getPrefixedDb(); + } + + apiPromise = this.get( config ); return apiPromise .then( function ( data ) { diff --git a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.parse.test.js b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.parse.test.js index f2865eb..4fab90d 100644 --- a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.parse.test.js +++ b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.parse.test.js @@ -6,7 +6,7 @@ } ) ); QUnit.test( 'Hello world', function ( assert ) { - QUnit.expect( 1 ); + QUnit.expect( 2 ); var api = new mw.Api(); @@ -20,6 +20,16 @@ ); } ); + api.parse( new mw.Title( 'Earth' ) ).done( function ( html ) { + assert.equal( html, '<p><b>Earth</b> is a planet.</p>' ); + } ); + + this.server.respondWith( /action=parse.*&page=Earth/, function ( request ) { + request.respond( 200, { 'Content-Type': 'application/json' }, + '{ "parse": { "text": "<p><b>Earth</b> is a planet.</p>" } }' + ); + } ); + this.server.respond(); } ); }( mediaWiki ) ); -- To view, visit https://gerrit.wikimedia.org/r/276660 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ic0d762d02c96e0b39b4983d3b66ebdfb6f88d3a2 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Mattflaschen <mflasc...@wikimedia.org> Gerrit-Reviewer: Catrope <roan.katt...@gmail.com> Gerrit-Reviewer: Edokter <er...@darcoury.nl> Gerrit-Reviewer: Jack Phoenix <j...@countervandalism.net> Gerrit-Reviewer: Jackmcbarn <jackmcb...@gmail.com> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: Mattflaschen <mflasc...@wikimedia.org> Gerrit-Reviewer: Mooeypoo <mor...@gmail.com> Gerrit-Reviewer: Phuedx <g...@samsmith.io> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits