Page MenuHomePhabricator

VisualEditor breaks templates/parser functions in Media links
Open, Needs TriagePublic

Description

  1. Upload a file named Example.jpg
  2. Create a page named Example with [[Media:{{PAGENAME}}.jpg]]
  3. Edit Example with the VisualEditor, add a space and click save the edits.

Expected outcome:
The source still contains [[Media:{{PAGENAME}}.jpg]].

Observed outcome:
The source contains [//localhost:1352/wiki/images/a/a9/Example.jpg Media:Example.jpg] instead.

Note that there are real use cases for using templates or parser functions in Media links, case in point the {{FILEPREFIX}} parser function of my Attachments extension.

Event Timeline

Are you using the latest versions of VisualEditor and Parsoid? I recall similar issues but they have been fixed a while ago (e.g. T198511). I couldn't reproduce this problem locally.

Yes I am using MediaWiki 1.35.2 with the bundled VisualEditor & Parsoid. I should add that the Media: link being turned into an external link is immediately apparent when opening the VIsualEditor.

I am having this problem still using MediaWiki 1.35.4 from Debian 11 stable, with the bundled visualEditor.

any [[Media:filename.ext]] tags on a page edited by Visual Editor are immediately broken. In my case they are broken by adding: "index.php?Title=" at the start of the tag, so [[Media:filename.ext]] becomes [[index.php?Title=Media:filename.ext]] , which leads to a new page, not to the media I am expecting.

If I use [[File:filename.ext]] then everything is fine, VE does not mangle it.

This does look like the same problem addressed back in #T198511 , but the fixes there (plus newer ones) are present inside modules/ve-mw/dm/annotations/ve.dm.MWInternalLinkAnnotation.js - specifically the code there does seem aware of a MediaLink:

ve.dm.MWInternalLinkAnnotation.static.matchRdfaTypes = [ 'mw:WikiLink', 'mw:MediaLink' ];

But regardless of manifestation, the problem remains that any [[Media: link is broken, wheras any [[File: link to the same file is not broken. This seems like more of a parsing bug than something deeper in the link handling?

Unfortunately this means I have to disable VE for my customer who wants it so badly, but all their pages break every edit. :(