Page MenuHomePhabricator

Expose `modules` and `jsconfigvars` from Parsoid's parse API when converting wikitext
Open, Stalled, LowPublic8 Story Points

Description

Currently a lot of extensions will conditionally load modules based on the content of the page, e.g. only load math code if equations are present, or only load MultimediaViewer if images are present.

When VE is used the content of the page will change asynchronously, and these modules will not be present if an equation or image is added, for example. In some cases (e.g. math) the module is actually loaded by VE, so the problem is bypassed, but others (e.g. MMV) aren't required in VE, but are required after save.

Ideally we could run the same content-checking hooks asynchronously and load any modules that are required automatically.

Related Objects

StatusAssignedTask
OpenNone
OpenNone
OpenNone
OpenNone
OpenNone
OpenNone
ResolvedEsanders
OpenNone
OpenNone
ResolvedJules78120
OpenNone
ResolvedDannyH
OpenNone
OpenEsanders
OpenNone
OpenEsanders
OpenNone
ResolvedEsanders
StalledNone
OpenNone

Event Timeline

Esanders created this task.Jul 9 2016, 5:35 PM
Restricted Application added subscribers: Zppix, Aklapper. · View Herald TranscriptJul 9 2016, 5:35 PM

Could we perhaps do a fake page render after save in the VE API, and send back a list of modules to load? We have a similar hack for gathering up the edit page checkboxes for the save dialog.

I'm not sure what this is about. API action=parse can already return modules, which are needed to display the page correctly/fully. Extensions can add modules to ParserOutput in PHP with addModules(). Or if they're checking it client-side from a small "bootstrap" module on page load, they should instead use the 'wikipage.content' mw.hook, and other extensions that replace content on the page (like VE) should fire that hook (I think VE already does).

Krinkle triaged this task as Normal priority.
Jdforrester-WMF changed the task status from Open to Stalled.Jul 12 2016, 7:23 PM

I agree with @matmarex. Extensions that lazy-load modules based on server-side checks would be calling addModules() accordingly and be included in the API response that VisualEditor gets. Relevant code:

/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js#L878
/modules/ve-mw/init/ve.init.mw.ArticleTarget.js#L446-L467

ve.init.mw.DesktopArticleTarget.js
ve.init.mw.DesktopArticleTarget.prototype.saveComplete = function ( /* .., */ modules, jsconfigvars ) {
	// ..
		mw.config.set( jsconfigvars );
		mw.loader.load( modules );

Extensions, site-scripts and user-scripts that perform these checks client-side typically load a minimalistic module unconditionally on every page that performs its check from mw.hook( 'wikipage.content' ) handler, which VisualEditor re-triggers after save.

In this case I am using RESTBase to convert wikitext to HTML (to show preview in the new wikitext editor).

The client-side hooks would still work as long as VE triggers them. I'm not sure about the server-side ones. I imagine Parsoid won't reach out to the API for this stuff in most cases. And even when it does, it would probably ignore the modules and jsconfigvars` from the API response. Re-tagging as a Parsoid issue.

Krinkle renamed this task from Create a system for registering modules to load if content changes asynchronously to Expose `modules` and `jsconfigvars` from Parse API in Parsoid when converting wikitext.Nov 18 2016, 8:27 PM

Parsoid adds module styles to the page (see ApiRequest code and DOMProcessor code ) .

What endpoint are you guys talking about where this info is not showing up?

transform/wikitext/to/html

transform/wikitext/to/html

I think I know what is going on. The modules are added to the head and you request a parse with bodyOnly => the header is stripped. Can't you process this without bodyOnly? I don't remember the reasoning why that flag was introduced. /cc @GWicke

But, anyway, I think Parsoid's output doesn't expose jsconfigvars even though it requests it from the MediaWiki API.

ssastry added a comment.EditedApr 6 2017, 2:15 PM

But, anyway, I think Parsoid's output doesn't expose jsconfigvars even though it requests it from the MediaWiki API.

This part is now covered by T162399 as a separate ticket.

Is there anything to do in this ticket now since Parsoid is already adding modules to the <head> and the issue seems to be that VE is requesting body-only and thus not getting the information?

Jdforrester-WMF set the point value for this task to 0.

@Jdforrester-WMF Note that in T139852#3160428 I am saying that this is a VE issue, not a Parsoid one. The Parsoid piece is a separate ticket.

Jdforrester-WMF renamed this task from Expose `modules` and `jsconfigvars` from Parse API in Parsoid when converting wikitext to Expose `modules` and `jsconfigvars` from Parsoid's parse API when converting wikitext.
Jdforrester-WMF lowered the priority of this task from Normal to Low.
Jdforrester-WMF removed a project: Parsoid.
Jdforrester-WMF changed the point value for this task from 0 to 8.

Our workaround in T147702 re-implements expandModuleNames to extract the style modules from the link tag.