Page MenuHomePhabricator

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

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

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.

To solve this question in central modules,

Which is entirely irrelevant to this task.

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?

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).

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

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>}}.

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.

@Agabi10 Did you give up on this patch? It looks really useful to me, and from the review comments it didn't look like there were any insurmountable problems (just maybe some documentable limitations due to the architecture context).

Aklapper added a subscriber: Agabi10.

@Agabi10: Removing task assignee as this open task has been assigned for more than two years - See the email sent to task assignee on Feburary 22nd, 2023.
Please assign this task to yourself again if you still realistically [plan to] work on this task - it would be welcome! :)
If this task has been resolved in the meantime, or should not be worked on by anybody ("declined"), please update its task status via "Add Action… 🡒 Change Status".
Also see https://www.mediawiki.org/wiki/Bug_management/Assignee_cleanup for tips how to best manage your individual work in Phabricator. Thanks!

@Agabi10 Did you give up on this patch? It looks really useful to me, and from the review comments it didn't look like there were any insurmountable problems (just maybe some documentable limitations due to the architecture context).

I second this, and the feature would be incredibly useful to notify obsolete parameters usage.

Change 928051 had a related patch set uploaded (by Ff300; author: Ff300):

[mediawiki/extensions/Scribunto@master] Add mw.addCategory function in Lua

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

Change 585684 abandoned by C. Scott Ananian:

[mediawiki/extensions/Scribunto@master] Create mw.addCategory function in Lua

Reason:

Abandoned in favor of I7d464846b3ccee284159d960dca7a5d49120be90

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

To give another use case, these categorizations would be very helpful for Module:Yesno (and for me, the frwiki variant):

  • Detect pages where a value that is valid, but not lowercase only, is used (to determine how much the "lower()" is useful, and if there are not many occurrences, correct them manually, for cleanliness)
  • Detect pages where adding a mw.text.trim() would have been useful (values coming from an unnamed template parameter)
  • Detect pages where an unrecognized string is supplied (this really should not happen, we should add a maintenance category for this)
  • Detect pages where values "t" or "f" are used (see talk) (and additionally on frwiki, the ambiguous "o"…) as I doubt about the usefulness of these values
  • A third parameter has been added to the frwiki variant, I am considering to remove this parameter, in favor of a new module (dedicated to values coming from template parameters), but exhaustively detecting the uses of this parameter is currently difficult.
  • Detect pages where the provided value is nil, as it is a problematic point (see talk), though, I'm afraid too many pages would be listed.

I think it would be uncontroversial to do this if it were also paired with a way of saying "evaluate this wikitext and ignore all categories added in the process". The reason I'm against it is that communities have built the latter and this would compromise that.