Page MenuHomePhabricator

Support subst: of transclusion blocks through the parseFragment API
Closed, ResolvedPublic

Description

Summary from IRC discussion:

Parsoid will provide a way for clients to flag that they want a transclusion to be substituted, subst=true – if this is set to true, then when VE (or other clients)
call Parsoid's parseFragment API it will drop the top-level transclusion's typeof:mwTransclusion and about:#mw-t\d wrapper, and instead push it down to each
of the nested transclusions (if any exist). (Default assumption is set to false.)

This will only implement subst: equivalence, not safesubst: yet, which is left for future-us to worry about later.)


Version: unspecified
Severity: normal

Event Timeline

bzimport raised the priority of this task from to High.Nov 22 2014, 3:48 AM
bzimport set Reference to bz71161.

This specific approach doesn't work since Parsoid calls the MW API to get expanded wikitext => all nested transclusions are expanded. However, we can call the action=parse API with onlypst=true and process the result in the Parsoid pipeline normally.

We can also retrieve the template wikitext and then parse that with top-level parameters defined. Nested transclusions will then hit expandtemplates as usual.

Ah yes, that would work as well if we implement the arg-substitution logic for transclusions (or revive it from the codebase if we have since removed it). We should figure out which approach is simpler to implement/maintain. My gut sense is that the onlypst=true one is simpler.

In either case, we hit the MW api + parse the result.

gerritbot subscribed.

Change 186015 had a related patch set uploaded (by Marcoil):
WIP T73161: Support subst: of transclusion blocks

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

Patch-For-Review

The current patch only works if {{subst:…}} is explicitly set in the template we want to transclude:

$ curl http://localhost:8000/enwiki/Main_Page -d wt="{{subst:echo|foo}}" -d subst=true

<p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"subst:echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</p>

It doesn't work exactly as requested in the bug's description, if I understood it correctly the desired behavior was to transclude the top-level template regardless of it having 'subst:' prepended:

$ curl http://localhost:8000/enwiki/Main_Page -d wt="{{echo|foo}}" -d subst=true

<p about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"dsr":[0,12,0,0],"pi":[[{"k":"1","spc":["","","",""]}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>{{echo|foo}}</p>

This is due to the way action=parse treats subst, but also has the advantage that more than one template (or even the whole page) can be sent for substitution. Is this behavior acceptable?

There's also the matter that the result is marked as being transcluded text, but that's necessary for correctly round-tripping into wikitext. If that's not necessary, then we could have the transcluded text just be inserted into the document without any special markers.

There's also the matter that the result is marked as being transcluded text, but that's necessary for correctly round-tripping into wikitext. If that's not necessary, then we could have the transcluded text just be inserted into the document without any special markers.

There is no roundtripping requirement here. Clients (in this case VE) want the HTML that they can use which when serialized will generate the subst-ed wikitext. So, for {{subst:echo|{{echo|foo}} [[bar]] }}, you should generate DOM output as if you had parsed "{{echo|foo}} [[bar]]"

I've just pushed a newer patch at https://gerrit.wikimedia.org/r/186015. This one doesn't need clients to manually insert 'subst:' in the template, all top-level templates passed will be subst'ed.

It also generates the correct ouput for embedded transclusions:

$ echo "{{echo|{{echo|foo}} [[bar]]}} {{t2demo|a|b}}" | node parse --subst --normalize

<p>foo <a href="Bar" title="Bar">bar</a> start-a-middle-b-end</p>

Change 208993 had a related patch set uploaded (by Marcoil):
T73161: Support subst: of transclusion blocks

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

Change 186015 abandoned by Marcoil:
T73161: Support subst: of transclusion blocks

Reason:
Discarded in favor of simpler way in https://gerrit.wikimedia.org/r/208993.

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

Change 208993 merged by jenkins-bot:
T73161: Support subst: of transclusion blocks

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

Arlolra subscribed.

Change 855565 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] ParsoidHandler: remove subst feature from wt2html

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

Change 855565 merged by jenkins-bot:

[mediawiki/core@master] ParsoidHandler: remove subst feature from wt2html

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