Page MenuHomePhabricator

ParsoidExtensionAPI: Provide a new method for extensions to access enclosing template parameters
Open, Needs TriagePublic

Description

See discussion in https://www.mediawiki.org/w/index.php?title=Topic:Xqalap62gl5lw6nf&topic_showPostId=xqeqg1irns773udq&fromnotif=1#flow-post-xqeqg1irns773udq

Consider a template {{my-template}arg1}arg2 .. |argn}} whose implementation includes an extension tag: <ext>... value-of-arg1 .. value-of-arg2 .. </ext>. So, the extension's tag handler might need access to enclosing transclusion's parameters.

We should either pass these through the sourceToDom API method or provide a separate method for extensions to query.

Event Timeline

An attempt at this was started in,
https://github.com/wikimedia/mediawiki-services-parsoid/commit/55da3090d0e7faa49e40a5bce0f68634fea5fc83

but was reverted because of T301948, T302007, and T301986
https://github.com/wikimedia/mediawiki-services-parsoid/commit/61f39cdee96985ec6ef99067bada1113011d1c8c

This is going to depend on T301080 because Parsoid currently collapses all the frames so only template arguments from the first level of the expansion are available. Extension tags nested a few templates deep wouldn't see the right arguments.

Your memory and history is much better than mine even though I wrote those patches originally!! :-)

One proposal is for all parsing to take place in the context of a "data object", which would include both explicit (typed) parameters as well as a "data object", possible associated via wikibase query or some such. Some notes:

  • T348722 has a proposal by Tim Starling for attaching data to the <section>
    • T230658 proposes syntax for “section attributes”, potentially something similar could use used to set section data ala Tim’s proposal?
  • SMW and {{#set}} are discussed in T122934#9196348

Goals:

  • avoid “from point of definition” behavior for {{#set}}-type data declarations.
  • Avoid exposing entire frame stack implicitly to templates; instead pass data explicitly so dependencies are manageable.

Thanks @Alex44019 and @cscott for raising this one. I remember discussing it with the team a while back, but the Parsoid extension API was considerably less fleshed out back then.