mediawiki.api.parse: Use formatversion=2 for API requests
authorFomafix <fomafix@googlemail.com>
Wed, 27 Jan 2016 08:22:04 +0000 (08:22 +0000)
committer[[mw:User:Fomafix]] <gerritpatchuploader@gmail.com>
Wed, 27 Jan 2016 08:22:04 +0000 (08:22 +0000)
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
tests/qunit/suites/resources/mediawiki.api/mediawiki.api.parse.test.js

index bc3d44f..49219d7 100644 (file)
@@ -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 } );
                }
index cd0db7c..f2865eb 100644 (file)
@@ -16,7 +16,7 @@
 
                this.server.respondWith( /action=parse.*&text='''Hello\+world'''/, function ( request ) {
                        request.respond( 200, { 'Content-Type': 'application/json' },
-                               '{ "parse": { "text": { "*": "<p><b>Hello world</b></p>" } } }'
+                               '{ "parse": { "text": "<p><b>Hello world</b></p>" } }'
                        );
                } );