Page MenuHomePhabricator

Add Lua function to read out previous section heading
Open, Needs TriagePublicFeature

Description

Problem: Ca 99% of templates in wiktionary need a language code. The same code must be fed separately into every single template call. This is junk work, and brings risk of wrong codes. This applies to a lesser degree to the word class too. Also, templates intended to be invoked from certain sections only cannot check whether they are used correctly.

Proposed solution: Add a LUA function to read out previous section heading of specified level. The most interesting levels are 2 and 3. Level 2 requested below ==Swedish== (at any distance until a different level 2 heading or higher level appears) would return "Swedish". Level 3 requested below === Subordinator === would return "Subordinator". If no heading of requested level has been passed or a higher level heading (lower number of equal signs "=") appared since the last one, then return empty string or type "nil".

Who would benefit: All contributors of wiktionary, template editors on wiktionary, to a lesser degree also all other wikis.

Details and previous discussion: https://meta.wikimedia.org/wiki/Community_Wishlist_Survey_2023/Wiktionary/Add_LUA_function_to_read_out_previous_section_heading

Event Timeline

The translation between language code and language name (discussed at meta page linked above) is already available elsewhere on every decent wiktionary. This is about reading out the RAW heading and nothing else.

Aklapper changed the subtype of this task from "Task" to "Feature Request".Mar 14 2023, 11:17 AM

(For future reference, please use the feature request form (linked from the top of the task creation page) to create feature requests, and fill in the sections in the template. Thanks!)

Aklapper renamed this task from Add LUA function to read out previous section heading to Add Lua function to read out previous section heading.Mar 14 2023, 11:17 AM

Scribunto takes extra steps to avoid modules accessing any part of the wikitext outside of the current {{#invoke:}} call (in particular, to avoid one module call passing data to the other one). In light of this, I find it quite unlikely that this feature will be ever implemented…

Looks like T122934 is relevant and would help with this. Unfortunately, there's been no movement on that task recently.

Indeed T122934 adresses same problem, but this one offers a simpler and cleaner solution avoiding the need for extra code like {{#sectionproperty: declare | lang=en}}.

Particularly @TTO interesting comment: T122934#1921615

in particular, to avoid one module call passing data to the other one

I am not yet fully convinced that this is needed, still this function "read out previous section heading" can be implemented in a way not allowing intermodule communication, namely by accepting only headings consisting of raw wikitext, ie ignoring those brewed by templates and modules.

I also greatly prefer T122934 (or something similar) to this hacky workaround.

I also greatly prefer T122934 (or something similar) to this hacky workaround.

Why is this hacky? The page https://en.wiktionary.org/w/index.php?oldid=35650095&action=edit linked from there:

==English==
{{wikipedia}}

===Pronunciation===
* {{enPR|go͝od}}, {{IPA|/ɡʊd/|lang=en}}
* {{audio|En-us-good.ogg|Audio (US)|lang=en}}
* {{audio|En-uk-good.ogg|Audio (UK)|lang=en}}
* {{rhymes|ʊd|lang=en}}

===Etymology 1===
From {{etyl|enm|en}} {{m|enm|good}}, from {{etyl|ang|en}}

could become with this proposal "Add Lua function to read out previous section heading":

==English==
{{wikipedia}}

===Pronunciation===
* {{enPR|go͝od}}, {{IPA|/ɡʊd/}}
* {{audio|En-us-good.ogg|Audio (US)}}
* {{audio|En-uk-good.ogg|Audio (UK)}}
* {{rhymes|ʊd}}

===Etymology 1===
From {{etyl|enm}} {{m|enm|good}}, from {{etyl|ang}}

quite an improvement, isn't it?

How would this code look if "helped" by T122934?

PS: On Esperanto wiktionary the template "audio" is smarter than here, it reads out the langcode from the filename "En-us-good.ogg" ;-) Still in many cases this is not possible, also if this one gets implemented then the template can compare langcode from the filename "En-us-good.ogg" against langcode from the L2 heading.

It would be also quite useful for us CheckUsers in WP:FR

It could be of course limited to plain text, ie accept things like

==English==

or

==User:Supervandal==

but ignore things like

=={{lang-en}}==

or

=={{user7|Supervandal}}==

so that the old argument "must not allow to pass information between module invokes" cannot come into way.

and for liste rcu this is the same thing

Can it at all work with Parsoid's non-linear parsing?

I also greatly prefer T122934 (or something similar) to this hacky workaround.

Why is this hacky? The page https://en.wiktionary.org/w/index.php?oldid=35650095&action=edit linked from there:

It isn't hacky at all: invoke isolation already has a massive carve-out for nested templates, so I don't see how this would be any different.