Page MenuHomePhabricator

Section-scope declarations for Wiktionary template invocations
Open, Needs TriagePublic


On Wiktionary several important templates require a language to be specified, but the language is always the language of the word being defined, i.e. the <h2> section. For example, look at the {{ux}} invocations on wikt:good. It has been requested that a mechanism be provided to make these templates aware of the section they are in, so that the language does not need to be specified in every invocation.

They asked for Extension:Variables, but I think it would be better to use a new extension which provides an immutable, scoped declaration, which would be more compatible with asynchronous construction of the DOM tree. Perhaps:

{{#sectionproperty: declare | lang=en}}

would attach a property called "lang" to the current (most deeply nested) <section> tag, then any instances of

{{#sectionproperty: get | lang}}

within the same section would retrieve that property. Declarations would be required to be at the top level of the preprocessor parse tree, after the section start but before any other template invocations or property fetches, so that declarations would be effectively available anywhere in the section while still allowing a single pass preprocessor. A nested section would inherit the properties of its parent section. Parsoid would need to track property declarations, serialize them and send them to the MW preprocessor for each template invocation within the relevant section.

Event Timeline

tstarling raised the priority of this task from to Needs Triage.
tstarling updated the task description. (Show Details)
tstarling added a project: Parsing-Team.
tstarling added a subscriber: tstarling.
Restricted Application added subscribers: StudiesWorld, Aklapper. · View Herald TranscriptJan 5 2016, 10:53 PM
cscott added a subscriber: cscott.Jan 6 2016, 6:32 PM

Possibly related: T114454 -- "handlebars" style templates have a context object they pass down through nested invocations.

Rua added a subscriber: Rua.Jan 6 2016, 7:36 PM
Rua added a comment.Jan 6 2016, 7:39 PM

In the request thread, I mentioned the alternative of letting templates and modules access the full "tree" of headings they are nested in. For Wiktionary's purposes, custom variables aren't strictly needed, it's only necessary that templates and modules have some way to figure out what L2 header they appear under.

TTO added a subscriber: TTO.EditedJan 8 2016, 1:31 PM
@tstarling wrote:

the current (most deeply nested) <section> tag

As far as I can see, the preprocessor XML doesn't generate <section> tags, and neither does Parsoid. Were you thinking of T114072?

I think the #sectionproperty that Tim is suggesting is (1) very difficult to implement in our current parser, and (2) beyond Wiktionary's needs.

I hacked up a working (though imperfect) implementation of CodeCat's suggestion. It's a magic word {{#section:N}} that returns the text of the most recent level N heading. See

, based on e2278426eab5.

Pengo added a subscriber: Pengo.Jan 9 2016, 10:38 PM

As far as I can see, the preprocessor XML doesn't generate <section> tags, and neither does Parsoid. Were you thinking of T114072?

Yes, this task would be implemented after T114072, which is pretty close to a sure thing.

Rua added a comment.Jan 14 2016, 12:05 AM

That seems like a change that could take a while, though. Would TTO's proposal work in the interim?

Aryamanarora added a subscriber: Aryamanarora.
Danny_B added a subscriber: Danny_B.
Rua added a comment.Aug 4 2016, 10:16 PM

What is the status on this?

jberkel added a subscriber: jberkel.Aug 5 2016, 8:14 PM

Like CodeCat, I'm also interested: what is the status on this?

See also this link:

In the linked discussion, another user is basically asking the same. This voted and approved project would be a great help to us in the English Wiktionary. Thank you.

The status is that someone needs to work on T114072 first - see T122934#1929650 :)