Page MenuHomePhabricator

Wikilinks where the link target is a <tvar> are always marked as changed in visual diffs
Closed, ResolvedPublic

Description

Wikilinks where the link target is a <tvar> are always marked as changed in visual diffs. This is because those links are not recognized as links, and instead treated as alien nodes.

For example: https://www.mediawiki.org/w/index.php?title=Manual:Messages_API&diff=prev&oldid=6865557

Wikitext diff
Screenshot 2025-05-10 at 23-45-25 Manual Messages API Różnice pomiędzy wersjami – MediaWiki.png (1,903×1,193 px, 218 KB)
Visual diff
Screenshot 2025-05-10 at 23-45-20 Manual Messages API Różnice pomiędzy wersjami – MediaWiki.png (1,903×3,823 px, 550 KB)
Expected visual diff
Screenshot 2025-05-10 at 23-45-41 Manual Messages API Różnice pomiędzy wersjami – MediaWiki.png (1,903×1,193 px, 175 KB)

Previously: T324790: Visual diffs on translateable pages highlight unchanged translation markers as added and removed

Event Timeline

Change #1143953 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/extensions/VisualEditor@master] Recognize wikilinks with generated href, make their target uneditable

https://gerrit.wikimedia.org/r/1143953

Couldn’t it be made so that the link targets are editable somehow (even if only as plain text, without search or other fancy things)? Most of the links on mediawiki.org are <tvar>s, and it’s a pain that they cannot be edited with VE.

For the record, the current UX doesn’t allow editing either (not even the link text ­– so what you already did is definitely an improvement, thanks!):

Screenshot from 2025-05-11 15-46-49.png (452×119 px, 10 KB)

I'm not sure what you mean by plain text. It'd be possible to make the "computed" target editable (e.g. given wikitext like [[{{1x|xxx}}|link]], it could show "Xxx" as the link target). But editing such a link would lose the original markup, and so I think that it would be too easy for users to accidentally "corrupt" the article. I felt that allowing it to be deleted, but not edited, was an acceptable workaround.

It's not really possible to show the original wikitext or the link target (e.g. {{1x|xxx}} in this example), because we don't have it in the Parsoid output. Instead, we have this:

<a typeof="mw:ExpandedAttrs" about="#mwt2" rel="mw:WikiLink" href="//en.wikipedia.org/wiki/Xxx" title="Xxx" class="mw-redirect mw-disambig" id="mwAw" data-mw="{&quot;attribs&quot;:[[{&quot;txt&quot;:&quot;href&quot;},{&quot;html&quot;:&quot;<span about=\&quot;#mwt1\&quot; typeof=\&quot;mw:Transclusion\&quot; data-parsoid='{\&quot;pi\&quot;:[[{\&quot;k\&quot;:\&quot;1\&quot;}]],\&quot;dsr\&quot;:[2,12,null,null]}' data-mw='{\&quot;parts\&quot;:[{\&quot;template\&quot;:{\&quot;target\&quot;:{\&quot;wt\&quot;:\&quot;1x\&quot;,\&quot;href\&quot;:\&quot;./Template:1x\&quot;},\&quot;params\&quot;:{\&quot;1\&quot;:{\&quot;wt\&quot;:\&quot;xxx\&quot;}},\&quot;i\&quot;:0}}]}'>xxx</span>&quot;}]]}">link</a>

If you decode/parse that data-mw attribute (an annoyance in its own right), you'll find that it says that the value of the href attribute has been generated from another piece of HTML, "flattened" to plain text:

<span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]],"dsr":[2,12,null,null]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"xxx"}},"i":0}}]}'>xxx</span>

Similarly if you start with wikitext like [[<tvar name=a>xxx</tvar>|link]], the href will be something like this:

<meta typeof="mw:Annotation/tvar" data-parsoid='{"dsr":[187,200,null,null]}' data-mw='{"attrs":{"name":"a"},"rangeId":"mwa0","extendedRange":false,"wtOffsets":[187,200]}'/>xxx<meta typeof="mw:Annotation/tvar/End" data-parsoid='{"dsr":[203,210,null,null]}' data-mw='{"wtOffsets":[203,210]}'/>

(There is a partial explanation of this markup in the spec: https://www.mediawiki.org/wiki/Specs/HTML/2.8.0#Generated_attributes_of_HTML_tags)

The only correct editing interface for this would be another visual editor surface – kind of like an image caption or reference content, but different, since the content is not really present in the final document, plus there are limitations on what content should be allowed in link targets. This is about 10x more complex than what I feel like doing in my free time on a weekend, and about 100x more complex than what I feel comfortable springing on the visual editor's maintainers without discussing it first.

I'm not sure what you mean by plain text. […] It's not really possible to show the original wikitext or the link target (e.g. {{1x|xxx}} in this example)

I meant that, {{1x|xxx}}. I agree that the result, i.e. Xxx, shouldn’t be there. (As a translation administrator, I’d hate having to put back all the <tvar>s VE lost before marking pages for translation.)

If you decode/parse that data-mw attribute (an annoyance in its own right), you'll find that it says that the value of the href attribute has been generated from another piece of HTML, "flattened" to plain text:

<span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]],"dsr":[2,12,null,null]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"xxx"}},"i":0}}]}'>xxx</span>

Isn’t this exactly the kind of markup that gets converted to {{1x|xxx}} when I save the edit? Or does that conversion happen in PHP, and we have no JS implementation for doing so?

This is about 10x more complex than what I feel like doing in my free time on a weekend, and about 100x more complex than what I feel comfortable springing on the visual editor's maintainers without discussing it first.

I see. I still think it would be really beneficial to make the link targets editable, but feel free to have the patch merged as-is, and my wish can be a follow-up, so that the perfect doesn’t become the enemy of good.

Isn’t this exactly the kind of markup that gets converted to {{1x|xxx}} when I save the edit? Or does that conversion happen in PHP, and we have no JS implementation for doing so?

Yes, it happens in PHP. It'd be possible to query the API to convert it back and forth, but that's also more work and probably has weird edge cases.

Change #1143953 merged by jenkins-bot:

[mediawiki/extensions/VisualEditor@master] Recognize wikilinks with generated href, make their target uneditable

https://gerrit.wikimedia.org/r/1143953