From b36133cded272ac89ce44d4844e759cf28dfa72d Mon Sep 17 00:00:00 2001 From: Matthew Flaschen Date: Thu, 10 Mar 2016 19:04:15 -0500 Subject: [PATCH] mediawiki.api.parse: Restore support for stringified objects Follows-up 11e6b3d. Don't assume non-string values are mw.Title objects. mw.Title is the special case. Restore the previous default of assuming wikitext. This was presumably avoided earlier because 'instanceof' throws if given undefined as right-hand expression and don't want a needless dependency on mediawiki.Title. Change-Id: I794ed4105d116e63ed505a17a237f289b80d3b15 --- resources/src/mediawiki/api/parse.js | 10 +++++----- .../mediawiki.api/mediawiki.api.parse.test.js | 14 +++++++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/resources/src/mediawiki/api/parse.js b/resources/src/mediawiki/api/parse.js index 02528dcfff..418fd2306f 100644 --- a/resources/src/mediawiki/api/parse.js +++ b/resources/src/mediawiki/api/parse.js @@ -22,12 +22,12 @@ contentmodel: 'wikitext' }, additionalParams ); - if ( typeof content === 'string' ) { - // Wikitext - config.text = content; - } else { - // mw.Title + if ( mw.Title && content instanceof mw.Title ) { + // Parse existing page config.page = content.getPrefixedDb(); + } else { + // Parse wikitext from input + config.text = String( content ); } apiPromise = this.get( config ); 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 4fab90d659..dc0cff40e6 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,12 +6,20 @@ } ) ); QUnit.test( 'Hello world', function ( assert ) { - QUnit.expect( 2 ); + QUnit.expect( 3 ); var api = new mw.Api(); api.parse( '\'\'\'Hello world\'\'\'' ).done( function ( html ) { - assert.equal( html, '

Hello world

' ); + assert.equal( html, '

Hello world

', 'Parse wikitext by string' ); + } ); + + api.parse( { + toString: function () { + return '\'\'\'Hello world\'\'\''; + } + } ).done( function ( html ) { + assert.equal( html, '

Hello world

', 'Parse wikitext by toString object' ); } ); this.server.respondWith( /action=parse.*&text='''Hello\+world'''/, function ( request ) { @@ -21,7 +29,7 @@ } ); api.parse( new mw.Title( 'Earth' ) ).done( function ( html ) { - assert.equal( html, '

Earth is a planet.

' ); + assert.equal( html, '

Earth is a planet.

', 'Parse page by Title object' ); } ); this.server.respondWith( /action=parse.*&page=Earth/, function ( request ) { -- 2.20.1