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.