From: Adam Wight Date: Tue, 23 Apr 2019 21:14:47 +0000 (-0700) Subject: Use POST to submit wikitext to mw.api.parse X-Git-Tag: 1.34.0-rc.0~1844^2 X-Git-Url: http://git.cyclocoop.org//%22javascript:ModifierStyle%28%27%22.%24id.%22%27%29/%22?a=commitdiff_plain;h=ce01e262ac04ee4dcdbebd7fcea6f15f3ae44d3e;p=lhc%2Fweb%2Fwiklou.git Use POST to submit wikitext to mw.api.parse It was impossible to parse wikitext longer than the maximum URL length of about 2000 characters, because our library only used GET requests. This patch switches to using POST for inline content, while still using GET when parsing existing pages. Bug: T216837 Change-Id: I971b7fc197517a2761f2100fc2aeda087ff52a78 --- diff --git a/resources/src/mediawiki.api/parse.js b/resources/src/mediawiki.api/parse.js index 42b0771dbf..447b9365d4 100644 --- a/resources/src/mediawiki.api/parse.js +++ b/resources/src/mediawiki.api/parse.js @@ -26,13 +26,13 @@ if ( mw.Title && content instanceof mw.Title ) { // Parse existing page config.page = content.getPrefixedDb(); + apiPromise = this.get( config ); } else { // Parse wikitext from input config.text = String( content ); + apiPromise = this.post( config ); } - apiPromise = this.get( config ); - return apiPromise .then( function ( data ) { return data.parse.text; 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 0bcce12476..29cffafc56 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 @@ -7,7 +7,7 @@ } ) ); QUnit.test( '.parse( string )', function ( assert ) { - this.server.respondWith( /action=parse.*&text='''Hello(\+|%20)world'''/, [ 200, + this.server.respondWith( 'POST', /api.php/, [ 200, { 'Content-Type': 'application/json' }, '{ "parse": { "text": "

Hello world

" } }' ] ); @@ -18,7 +18,7 @@ } ); QUnit.test( '.parse( Object.toString )', function ( assert ) { - this.server.respondWith( /action=parse.*&text='''Hello(\+|%20)world'''/, [ 200, + this.server.respondWith( 'POST', /api.php/, [ 200, { 'Content-Type': 'application/json' }, '{ "parse": { "text": "

Hello world

" } }' ] ); @@ -33,7 +33,7 @@ } ); QUnit.test( '.parse( mw.Title )', function ( assert ) { - this.server.respondWith( /action=parse.*&page=Earth/, [ 200, + this.server.respondWith( 'GET', /action=parse.*&page=Earth/, [ 200, { 'Content-Type': 'application/json' }, '{ "parse": { "text": "

Earth is a planet.

" } }' ] );