Page MenuHomePhabricator

TemplateStyles don't work when the template is inside a link
Open, Needs TriagePublic


[[A|{{comment|text|comment}}]] doesn't work properly in ruwiki: {{comment}} template contains a <templatestyles> tag, but no template styles are applied.

<templatestyles> expands into this code:

<style data-mw-deduplicate="TemplateStyles:r93295199">'"`UNIQ--templatestyles-00000001-QINU`"'</style>

(note the strip marker).

{{comment|text|comment}} works fine, and <templatestyles> expands correctly:

<style data-mw-deduplicate="TemplateStyles:r93295199">.mw-parser-output .ts-comment-commentedText{border-bottom:1px dotted;cursor:help}@media(hover:none){.mw-parser-output .ts-comment-commentedText:not(.rt-commentedText){border-bottom:0;cursor:auto}}</style>

The problem occurs because the template is used inside a link. The point of using this template inside a link is to provide a tooltip other than the standard tooltip for links.

An example without templates:

[[A|<templatestyles src="Шаблон:Comment/styles.css" /><span class="ts-comment-commentedText">text</span>]]

Related task: T186965: Output HTML should not contain `<p><style>...</style></p>`

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJul 30 2018, 4:05 PM
SerDIDG added a subscriber: SerDIDG.
Anomie added a subscriber: Anomie.Aug 16 2018, 3:20 PM

TemplateStyles generates a "general" marker (to, among other things, prevent T67258) that contains the style tags, with the actual content inside the style tags being hidden inside a "nowiki" marker (to prevent it from being mangled by Parser->doBlockLevels()).

Normally this is handled fine: Parser::internalParseHalfParsed() unstrips the "general" marker, does some stuff, and then unstrips the "nowiki" marker.

But in the case where the "general" marker is inside a link's text, the link is hidden by a LinkHolderArray marker. The first unstrip of "general" markers therefore doesn't see it. There's a second "general" unstrip, but that doesn't happen until after the "nowiki" unstrip so the contained "nowiki" marker never gets unstripped.

There are a few fixes I can think of, but I don't know whether any of them might break other assumptions.

  • Have LinkHolderArray unstrip general markers when replacing the link holders.
  • Have LinkHolderArray take an option to unstrip general markers when replacing the link holders, and use that option from Parser::internalParseHalfParsed().
  • Replace either the unstripNowiki or the second unstripGeneral call with unstripBoth.

Thanks to @Jonesey95's report at en:Template talk:Noitalic: The same thing is happening inside navboxes at en. Apparently, whether the noitalic is inside a link or not.

Edit: never mind, bug occurs if first instance of inner templatestyled template is in a link.

Aklapper removed a subscriber: Anomie.Oct 16 2020, 5:01 PM