Page MenuHomePhabricator

Allow Scribunto code to add a category without changing output
Open, Needs TriagePublic

Description

Sometimes Lua module is used with some obsolete parameters, and wants to create a category for all pages that use it in obsolete way. Other times Lua might simply want to add a category to the page. Regardless, adding "[[category:xxx]]" to the output is not ideal because there are many cases when it breaks final wiki markup (e.g. in the middle of the html atribute text.

I think there should be a frame::addCategory()

Event Timeline

Yurik created this task.Jun 10 2016, 5:50 PM
Restricted Application added subscribers: Zppix, Aklapper. · View Herald TranscriptJun 10 2016, 5:50 PM
Rical added a subscriber: Rical.Sep 6 2017, 2:52 PM

To solve this question in central modules, I collect all categories in a table.
Then, just before return the wikitext, I place them after this wikitext.

Anomie added a comment.Sep 6 2017, 3:22 PM

To solve this question in central modules,

Which is entirely irrelevant to this task.

Rical added a comment.Sep 6 2017, 5:07 PM

To delay categories at the end of the wikitext is a simple way.
If this way answer the question, is this task needed?

How frame::addCategory() can solve the question if it is in the same place in the html page?

Anomie added a comment.Sep 6 2017, 5:27 PM

That way is not the answer to the question. The method would probably be mw.addCategory() rather than being on the frame object, and would call $parserOutput->addCategory() rather than doing anything to the wikitext.

Collecting categories in a table as you go, and spitting the table out at the end of your output, is a workaround, and probably one of the most elegant workarounds, absent any other tools. Having some tool specifically for the job is probably preferable though (especially since it means editors don't have to be aware of the problem and its potential workarounds).

Od1n awarded a token.Nov 10 2019, 4:36 PM
Od1n added a subscriber: Od1n.
Agabi10 claimed this task.Apr 3 2020, 7:15 AM

Change 585684 had a related patch set uploaded (by Agabi10; owner: Agabi10):
[mediawiki/extensions/Scribunto@master] Create mw.addCategory function in Lua

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

Od1n added a comment.EditedApr 3 2020, 2:25 PM

Could anyone think of any issues, to have categories but without their code in the final wikitext?

On a related note, this makes me think we could have a similar method in parser functions, i.e. {{#addcategory:<category name>|<optional sort key>}}.

Pppery added a subscriber: Pppery.EditedApr 4 2020, 12:28 AM

Could anyone think of any issues, to have categories but without their code in the final wikitext?

Yes, it causes problems like T88797. Furthermore, Template:suppress categories exists and (obviously) cannot suppress categories added via a side channel.

That's correct. The template wouldn't be able to suppress those categories, but it's totally different of T88797, because the generated categories are controlled by the module author in this case and the categorization could be easily suppressed in the code with a parameter. Anyway using this function is completely optional, while the error category isn't.