Page MenuHomePhabricator

VisualEditor: Certain templates cannot be insterted by copy-pasting plaintext without the raw-text output of the template being inserted in its place
Closed, ResolvedPublic

Description

Description

Most templates you can copy-paste as plaintext wikicode and paste into VisualEditor. Pasting the plaintext "{{cn}}" into a VisualEditor document will result in the wikicode "{{cn}}". The same applies to all article cleanup templates and infoboxes.

However, if you paste in the plaintext string "{{dab}}", the result will be the text contents of the page Template:Disambiguation, namely "{{Dmbox|type=disambig|text=<includeonly>{{#if:{{{nocat...". The same applies to {{db-a7}}, the result is just the raw content of the template page itself.

This is quite confusing since there are no clues left to the user that they haven't actually transcluded a template. Some articles have had an accidentally expanded speedy deletion template on them for 6+ months (example 1, example 2)

I have not been able to figure out what exactly differentiates un-copyable templates and copyable templates. Templates based on Template:Dmbox are un-copyable, while templates based on Template:Ambox are copyable.

How to reproduce

Paste the plaintext string "{{dab}}" into an English Wikipedia sandbox and see the resulting wikicode..

Expected behavior

The plaintext string "{{dab}}" should be the wikicode in the saved page

VisualEditor is clearly able to add this template since if you go to Insert > Template > dab, the correct wikicode is returned.

Previous related tasks

The only related topic to this I could find was the 2013 regression T56410.

Event Timeline

matmarex added a subscriber: Krinkle.
matmarex subscribed.

This happens when the template's wikitext starts with a <templatestyles> tag. It outputs a <style> tag in HTML, which is apparently stripped by our paste sanitization code, and along with it the information about the transclusion is also lost (because it's always placed on the first tag generated by the template).

Actually, I was wrong to blame the paste sanitization code. The <style> tag disappears because we parse the HTML snippet as a whole document, and it lands inside the <head> element, which we ignore.

Change 660962 had a related patch set uploaded (by Bartosz Dziewoński; owner: Bartosz Dziewoński):
[VisualEditor/VisualEditor@master] ve.dm.Converter: Fail hard on "about" attributes in weird places

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

Change 660963 had a related patch set uploaded (by Bartosz Dziewoński; owner: Bartosz Dziewoński):
[VisualEditor/VisualEditor@master] ve.createDocumentFromHtml: Do not lose <style> tags in doc fragments

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

Change 660962 abandoned by Bartosz Dziewoński:
[VisualEditor/VisualEditor@master] ve.dm.Converter: Fail hard on "about" attributes in weird places

Reason:
It's unclear if this is entirely correct, and it's not needed to fix the bug (it was meant to be a preventative measure against similar future bugs).

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

Change 660963 merged by jenkins-bot:
[VisualEditor/VisualEditor@master] ve.createDocumentFromHtml: Do not lose <style> tags in doc fragments

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

Change 666740 had a related patch set uploaded (by Bartosz Dziewoński; owner: Bartosz Dziewoński):
[mediawiki/extensions/VisualEditor@master] Update VE core submodule to master (3c56d0611)

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

Change 666740 merged by jenkins-bot:
[mediawiki/extensions/VisualEditor@master] Update VE core submodule to master (3c56d0611)

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