From 0de55918891c966b481e5c4b06440e6e03c89c8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Thu, 2 Jan 2020 15:59:50 +0100 Subject: [PATCH] ReplyWidget: Load modules required by the content when previewing Unfortunately mw.Api#parse doesn't provide us with that part of the response, so we have to manually construct the parameters. Bug: T241193 Change-Id: Ie91d5ebc2ef483a69524b838dd3cb852e7c85cd2 --- modules/dt.ui.ReplyWidget.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/dt.ui.ReplyWidget.js b/modules/dt.ui.ReplyWidget.js index 9359f6a9b..e68b58df6 100644 --- a/modules/dt.ui.ReplyWidget.js +++ b/modules/dt.ui.ReplyWidget.js @@ -159,24 +159,33 @@ ReplyWidget.prototype.onInputChange = function () { // wikitext = surface.getDom(); wikitext = this.textWidget.getValue(); if ( !wikitext.trim() ) { - parsePromise = $.Deferred().resolve( '' ).promise(); + parsePromise = $.Deferred().resolve( null ).promise(); } else { wikitext = controller.autoSign( wikitext ); wikitext = wikitext.slice( 0, -4 ) + '~~~~'; wikitext = indent + wikitext.replace( /\n/g, '\n' + indent ); - this.previewRequest = parsePromise = this.api.parse( wikitext, { + this.previewRequest = parsePromise = this.api.post( { + formatversion: 2, + action: 'parse', + text: wikitext, pst: true, + prop: [ 'text', 'modules' ], title: mw.config.get( 'wgPageName' ) } ); } // TODO: Add list context - parsePromise.then( function ( html ) { + parsePromise.then( function ( response ) { var heightAfter, heightBefore = widget.$preview.outerHeight( true ); - widget.$preview.html( html ); + widget.$preview.html( response ? response.parse.text : '' ); heightAfter = widget.$preview.outerHeight( true ); + if ( response ) { + mw.loader.load( response.parse.modulestyles ); + mw.loader.load( response.parse.modules ); + } + // TODO: IE11? window.scrollBy( 0, heightAfter - heightBefore ); } );