Page MenuHomePhabricator

Class and style attributes stripped from templates when template-generated
Closed, DuplicatePublic

Description

See https://en.wikipedia.org/wiki/CSCL_Globe?veaction=edit where the infobox loses it's infoboxicity.

Event Timeline

Esanders renamed this task from Class and style attributes stripped from multi-part templates to Class and style attributes stripped templates when template-generated.
Esanders raised the priority of this task from to Needs Triage.
Esanders updated the task description. (Show Details)
Esanders added a project: Parsoid.
Esanders set Security to None.
Esanders subscribed.
Esanders renamed this task from Class and style attributes stripped templates when template-generated to Class and style attributes stripped from templates when template-generated.Jan 8 2015, 2:10 PM

If you template-generate the class and style attributes of the table, and also the caption, both are lost.

In the example below, eviltable.txt is identical to nonevitable.txt except that part of the first line and all of the second line is wrapped in {{echo}}

$ cat noneviltable.txt 
{|class="infobox" style="width:315px;float:right;clear:right;border-spacing:2px;font-size:90%"
|+
| Hello
|-
| world
|}

$ cat eviltable.txt 
{|{{echo|1=class="infobox" style="width:315px;float:right;clear:right;border-spacing:2px;font-size:90%"
|+
}}
| Hello
|-
| world
|}

$ node tests/parse.js < noneviltable.txt 
<body>
<table class="infobox" style="width:315px;float:right;clear:right;border-spacing:2px;font-size:90%" data-parsoid='{"dsr":[0,119,94,2]}'>
<caption data-parsoid='{"dsr":[95,97,2,null]}'></caption>
<tbody data-parsoid='{"dsr":[98,117,0,0]}'>
<tr data-parsoid='{"autoInsertedEnd":true,"autoInsertedStart":true,"dsr":[98,105,0,0]}'>
<td data-parsoid='{"autoInsertedEnd":true,"dsr":[98,105,1,0]}'> Hello</td>
</tr>
<tr data-parsoid='{"startTagSrc":"|-","autoInsertedEnd":true,"dsr":[106,116,2,0]}'>
<td data-parsoid='{"autoInsertedEnd":true,"dsr":[109,116,1,0]}'> world</td>
</tr>
</tbody>
</table>
</body>

$ node tests/parse.js < eviltable.txt 
<body>
<table about="#mwt2" typeof="mw:ExpandedAttrs">
<tbody data-parsoid='{"dsr":[110,129,0,0]}'>
<tr data-parsoid='{"dsr":[110,117,0,0]}'>
<td data-parsoid='{"dsr":[110,117,1,0]}'> Hello</td>
</tr>
<tr data-parsoid='{"startTagSrc":"|-","dsr":[118,128,2,0]}'>
<td data-parsoid='{"dsr":[121,128,1,0]}'> world</td>
</tr>
</tbody>
</table>
</body>

Also noteworthy is the deeply nested data-mw value on the table:

data-mw='{"attribs":[[{"txt":"+","html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-mw=\"{&amp;quot;parts&amp;quot;:[{&amp;quot;template&amp;quot;:{&amp;quot;target&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;echo&amp;quot;,&amp;quot;href&amp;quot;:&amp;quot;./Template:Echo&amp;quot;},&amp;quot;params&amp;quot;:{&amp;quot;1&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;+\\n&amp;quot;}},&amp;quot;i&amp;quot;:0}}]}\">+&lt;/span>&lt;span about=\"#mwt1\" data-parsoid=\"{}\">\n&lt;/span>&lt;span about=\"#mwt1\" data-parsoid=\"{}\">\n&lt;/span>&lt;link rel=\"mw:PageProp/Category\" href=\"./Category:Pages_using_duplicate_arguments_in_template_calls\" about=\"#mwt1\" data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;simple&amp;quot;,&amp;quot;a&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;./Category:Pages_using_duplicate_arguments_in_template_calls&amp;quot;},&amp;quot;sa&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;Category:Pages_using_duplicate_arguments_in_template_calls&amp;quot;}}\">"},{"html":""}]]}'

(I manually cleaned up the output because --normalize removes class attributes and --normalize=parsoid removes style attributes)

This is related T48811 and the patch for review https://gerrit.wikimedia.org/r/#/c/173834/ which fixes many instances of this (but I just noticed doesn't seem to handle this properly .. I think that is probably some tweak to the functionality I added for this. Will get this test case working there. But, this could be closed as a duplicate of that.

Note, however, that these kind of tables will effectively get wrapped as one large block and will not be editable in VE as a table.

This is related T48811 and the patch for review https://gerrit.wikimedia.org/r/#/c/173834/ which fixes many instances of this (but I just noticed doesn't seem to handle this properly .. I think that is probably some tweak to the functionality I added for this.

Seems to be because the transclusion is not expanding to what you think it would expand to. See the expanded template source for the transclusion below.

[subbu@earth lib] node parse --dump tplsrc < /tmp/foo
=================================
Template:Echo
---------------------------------
+

[[Category:Pages_using_duplicate_arguments_in_template_calls]]
---------------------------------
....

Ah it is the "|" char in the echo template. Try this instead. So, this is indeed a duplicate of T48811 and is fixed by that patch up for review.

[subbu@earth lib] git branch
* bug_46811
[subbu@earth lib] cat /tmp/foo
{|{{echo|1=class="infobox" style="width:315px;float:right;clear:right;border-spacing:2px;font-size:90%"
{{!}}+
}}
| Hello
|-
| world
|}
[subbu@earth lib] node parse < /tmp/foo [[ html and body tags stripped out below ]]
<table class="infobox" style="width:315px;float:right;clear:right;border-spacing:2px;font-size:90%" about="#mwt1" typeof="mw:Transclusion mw:ExpandedAttrs" data-parsoid='{"dsr":[0,135,113,2],"pi":[[{"k":"1","named":true,"spc":["","","","\n"]}]],"src":"{|{{echo|1=class=\"infobox\" style=\"width:315px;float:right;clear:right;border-spacing:2px;font-size:90%\"\n{{!}}+\n}}\n| Hello\n|-\n| world\n|}"}' data-mw='{"parts":["{|",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"class=\"infobox\" style=\"width:315px;float:right;clear:right;border-spacing:2px;font-size:90%\"\n{{!}}+"}},"i":0}},"\n| Hello\n|-\n| world\n|}"]}'>
<caption></caption>
<tbody><tr><td> Hello</td></tr>
<tr>
<td> world</td></tr>
</tbody></table>

Seems to be because the transclusion is not expanding to what you think it would expand to. See the expanded template source for the transclusion below.

[subbu@earth lib] node parse --dump tplsrc < /tmp/foo
=================================
Template:Echo
---------------------------------
+

[[Category:Pages_using_duplicate_arguments_in_template_calls]]
---------------------------------
....

Good catch, that's because I forgot to escape a pipe. But escaping that doesn't fix the problem:

$ cat eviltable.txt 
{|{{echo|1=class="infobox" style="width:315px;float:right;clear:right;border-spacing:2px;font-size:90%"
{{!}}+
}}
| Hello
|-
| world
|}

$ node tests/parse.js < eviltable.txt 
<body>
<table about="#mwt2" typeof="mw:ExpandedAttrs">
<tbody data-parsoid='{"dsr":[114,133,0,0]}'>
<tr data-parsoid='{"dsr":[114,121,0,0]}'>
<td data-parsoid='{"dsr":[114,121,1,0]}'> Hello</td>
</tr>
<tr data-parsoid='{"startTagSrc":"|-","dsr":[122,132,2,0]}'>
<td data-parsoid='{"dsr":[125,132,1,0]}'> world</td>
</tr>
</tbody>
</table>

</body>

The big data-mw is:

'{"attribs":[[{"txt":"\"infobox\" style","html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=\"{&amp;quot;pi&amp;quot;:[[{&amp;quot;k&amp;quot;:&amp;quot;1&amp;quot;,&amp;quot;named&amp;quot;:true,&amp;quot;spc&amp;quot;:[&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;\\n&amp;quot;]}]],&amp;quot;dsr&amp;quot;:[2,113,null,null]}\" data-mw=\"{&amp;quot;parts&amp;quot;:[{&amp;quot;template&amp;quot;:{&amp;quot;target&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;echo&amp;quot;,&amp;quot;href&amp;quot;:&amp;quot;./Template:Echo&amp;quot;},&amp;quot;params&amp;quot;:{&amp;quot;1&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;class=\\&amp;quot;infobox\\&amp;quot; style=\\&amp;quot;width:315px;float:right;clear:right;border-spacing:2px;font-size:90%\\&amp;quot;\\n{{!}}+&amp;quot;}},&amp;quot;i&amp;quot;:0}}]}\">class=\"infobox\" style=\"width:315px;float:right;clear:right;border-spacing:2px;font-size:90%\"\n&lt;/span>"},{"html":""}]]}'

which is different from before (now includes more than just the +), but seeing a field set to \"infobox\" style worries me a bit.

You can leave the table editable as a table in VE if the echo transclusion doesn't also include the "{{!|}}+" part in it. In that case, the transclusion will be treated with a mw:ExpandedAttrs as follows:

<table class="infobox" style="width:315px;float:right;clear:right;border-spacing:2px;font-size:90%" about="#mwt2" typeof="mw:ExpandedAttrs" ...

That patch for review support this better than currently deployed master.

You can leave the table editable as a table in VE if the echo transclusion doesn't also include the "{{!|}}+" part in it. In that case, the transclusion will be treated with a mw:ExpandedAttrs as follows:

<table class="infobox" style="width:315px;float:right;clear:right;border-spacing:2px;font-size:90%" about="#mwt2" typeof="mw:ExpandedAttrs" ...

That patch for review support this better than currently deployed master.

Yeah, unfortunately the template we're dealing with outputs both. It looks like this is indeed a full duplicate of T48811 , which is about the pattern {| {{infobox aircraft begin}} . Ed and I were investigating {| {{infobox ship begin}} (on https://en.wikipedia.org/wiki/CSCL_Globe ).

Confirmed that rendering of enwiki:CSCL_Globe is fixed on Parsoid HEAD.