Page MenuHomePhabricator

Inserted templates and preexisting templates have very different structures
Closed, ResolvedPublic

Description

  • Create a document that uses a template.
  • Edit that document, and in VE add another instance of that template.
  • Compare the VE data model for the pre-existing template and the just-added template.

This example is using {{sfn}} on enwiki:

pre-existingjust-added
image.png (2,348×386 px, 104 KB)
image.png (608×690 px, 74 KB)

You can see that the pre-existing one has a lot of extra information inside attributes.mw.

ve.dm.MWTransclusionModel sets this up in insertTransclusionNode, and has access to the generated contents that have just been fetched from the API, which is this case would be:

<p id="mwAg"><sup about="#mwt1" class="mw-ref reference" id="cite_ref-FOOTNOTESmith12_1-0" rel="dc:references" typeof="mw:Transclusion mw:Extension/ref" data-mw='{"name":"ref","attrs":{"group":"","name":"FOOTNOTESmith12"},"body":{"id":"mw-reference-text-cite_note-FOOTNOTESmith12-1"},"parts":[{"template":{"target":{"wt":"Sfn","href":"./Template:Sfn"},"params":{"1":{"wt":"Smith"},"2":{"wt":"12"}},"i":0}}]}'><a href="./Battle_of_the_Saw#cite_note-FOOTNOTESmith12-1" id="mwAw"><span class="mw-reflink-text" id="mwBA"><span class="cite-bracket" id="mwBQ">[</span>1<span class="cite-bracket" id="mwBg">]</span></span></a></sup></p>
<div class="mw-references-wrap" typeof="mw:Extension/references" about="#mwt3" id="mwBw" data-mw='{"name":"references","attrs":{},"autoGenerated":true}'><ol class="mw-references references" id="mwCA"><li about="#cite_note-FOOTNOTESmith12-1" id="cite_note-FOOTNOTESmith12-1" data-mw-footnote-number="1"><span class="mw-cite-backlink" id="mwCQ"><a href="./Battle_of_the_Saw#cite_ref-FOOTNOTESmith12_1-0" rel="mw:referencedBy" id="mwCg"><span class="mw-linkback-text" id="mwCw"></span></a></span> <span id="mw-reference-text-cite_note-FOOTNOTESmith12-1" class="mw-reference-text reference-text"><a rel="mw:WikiLink" href="./Battle_of_the_Saw#CITEREFSmith12" class="mw-selflink-fragment" id="mwDA">Smith <span typeof="mw:Entity" id="mwDQ">&amp;</span> 12</a>.<span class="error harv-error" style="display: none; font-size:100%" id="mwDg"> sfn error: no target: CITEREFSmith12 (<a rel="mw:WikiLink" href="./Category:Harv_and_Sfn_template_errors" title="Category:Harv and Sfn template errors" id="mwDw">help</a>)</span><link rel="mw:PageProp/Category" href="./Category:Harv_and_Sfn_no-target_errors" id="mwEA"/></span></li>
</ol></div>

i.e. all the information that's on the pre-rendered version is present, we're just not importing it. We could probably run this through a dm.ModelFromDomConverter and use the data that creates, rather then the sparse data that we're currently using. This would then be consistent.

Event Timeline

Change #1229778 had a related patch set uploaded (by DLynch; author: DLynch):

[mediawiki/extensions/VisualEditor@master] MWTransclusionModel: import the data from generatedContent if present

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

Change #1229778 merged by jenkins-bot:

[mediawiki/extensions/VisualEditor@master] MWTransclusionModel: import the data from generatedContent if present

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

For QA, please just test anything you can think of involving adding templates to the page and then further interacting with them. In particular, complex additions of multiple templates feel most at-risk for causing something to get mixed up.

In theory this change should have reduced the chance that there's any difference in behavior between already-on-the-page templates and just-added templates. So if it worked, if anything, behavior should be more consistent than it was. However, there's a chance that something has been missed about handling particularly complicated template insertions -- it tries to fall back to the old behavior if it finds something unexpected, but that might have gotten mixed up.

Context for testing: this was to support T407849, so you can probably bundle some of the QA together.