Page MenuHomePhabricator

Newly parsed/inserted template content should honour parse data (especially style modules)
Open, LowPublic8 Estimated Story Points

Description

Inserting a template that uses an extension tag that adds one or more (style) modules to the page does not result in VisualEditor loading those modules.

When inserting a "Code block" (the syntaxhighlight extension tag) using VisualEditor, the ext.pygments module is manually loaded by the ve.ce.MWSyntaxHighlightNode class.

Generic logic for this does exist in VisualEditor, but is only used after saving an edit. Then, ve.init.mw.DesktopArticleTarget will load any missing modules provided by the parser, as well as new values from jsconfigvars.

However these three places in VisualEditor do not use this:

  • Inserting or updating a template call.
  • Inserting or updating an extension tag (internal base class).
  • Inserting a mediawiki user signature.

https://github.com/wikimedia/mediawiki-extensions-VisualEditor/blob/f89a6a388096bcfe1b080a36a93fd0dbe9bc6553/modules/ve-mw/ce/nodes/ve.ce.MWSignatureNode.js#L85-L103
https://github.com/wikimedia/mediawiki-extensions-VisualEditor/blob/f89a6a388096bcfe1b080a36a93fd0dbe9bc6553/modules/ve-mw/ce/nodes/ve.ce.MWExtensionNode.js#L73-L80
https://github.com/wikimedia/mediawiki-extensions-VisualEditor/blob/f89a6a388096bcfe1b080a36a93fd0dbe9bc6553/modules/ve-mw/ce/nodes/ve.ce.MWTransclusionNode.js#L137-L166

I imagine these could also expose the modules array from the parse API and pass it to mw.loader.loader().

Example:

  1. https://www.mediawiki.org/wiki/Project:Sandbox?action=edit
  2. Insert Template
  3. Name "Phpi"
  4. Content parameter "$foo = foo();"
  5. Insert

The pygments module is not loaded. Text is unstyled. After saving, the text is styled.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

After saving, the text is styled.

When I try this, I don't see styled text immediately after the save. Unstyled text persists after the save until I reload the page.

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

After saving, the text is styled.

When I try this, I don't see styled text immediately after the save. Unstyled text persists after the save until I reload the page.

Interesting, I didn't notice that before. This is odd because VisualEditor does currently have logic in place for ensuring any needed modules are loaded when rendering the page post-save. After saving, it uses the MediaWiki API to render using the PHP parser's HTML output. And it gets back an array of jsconfigvars and modules. It seems pygments is not among them.

Trying on https://en.wikipedia.beta.wmflabs.org/wiki/Sandbox, I get the following response:

{"visualeditoredit":{
  "content":"<p><code class=\"mw-highlight\" dir=\"ltr\"><span class=\"nv\">$foo</span> <span class=\"o\">=</span> <span class=\"nx\">foo</span><span class=\"p\">();</span></code></p>\n<div class=\"mw-kartographer-container thumb tright\">...",
  ...
  "displayTitleHtml":"Sandbox",
  "modules":["ext.kartographer.frame"],
  "jsconfigvars":[],
  "isRedirect": ... }}

Looks the visualeditoredit module isn't merging the modulestyles property. Should be fixed in https://gerrit.wikimedia.org/r/#/c/337641/.