From 7e2d5705394f0fd50df609100d887d85a8f753f0 Mon Sep 17 00:00:00 2001 From: Fomafix Date: Wed, 27 Jan 2016 08:22:04 +0000 Subject: [PATCH] mediawiki.api.parse: Use formatversion=2 for API requests MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit With formatversion=2 the response uses UTF-8 instead of escape sequences with hex for encoding of non-ASCII characters (e.g. "\u00e4" for "ä"). The structural change in the response of formatversion=2 is abstracted by this mw.Api plugin. The test is updated. Change-Id: I155d220dd4693bff6f8fc6c817698f2b4ac9660f --- resources/src/mediawiki/api/parse.js | 3 ++- .../suites/resources/mediawiki.api/mediawiki.api.parse.test.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/resources/src/mediawiki/api/parse.js b/resources/src/mediawiki/api/parse.js index bc3d44f946..49219d782c 100644 --- a/resources/src/mediawiki/api/parse.js +++ b/resources/src/mediawiki/api/parse.js @@ -14,6 +14,7 @@ */ parse: function ( wikitext ) { var apiPromise = this.get( { + formatversion: 2, action: 'parse', contentmodel: 'wikitext', text: wikitext @@ -21,7 +22,7 @@ return apiPromise .then( function ( data ) { - return data.parse.text[ '*' ]; + return data.parse.text; } ) .promise( { abort: apiPromise.abort } ); } 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 cd0db7c965..f2865ebb63 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 @@ -16,7 +16,7 @@ this.server.respondWith( /action=parse.*&text='''Hello\+world'''/, function ( request ) { request.respond( 200, { 'Content-Type': 'application/json' }, - '{ "parse": { "text": { "*": "

Hello world

" } } }' + '{ "parse": { "text": "

Hello world

" } }' ); } ); -- 2.20.1