Community Wishlist Survey 2023/Archive/Add a LUA function to check whether given page is in given cat
Add a LUA function to check whether given page is in given cat
Outside the scope of Community Tech
- Problem: No way to check from a template or module whether a certain page is in a certain category. This is needed for some templates on wiktionary.
- Proposed solution: Add a LUA function to check whether given page is in given category. It will take two strings (name of category, name of page), and return a boolean revealing whether the page is in there, irrespective whether the category page is created (ie blue) or not (ie red)
- Who would benefit: Template and module contributors on wiktionary and probably even other wikis, consequently all users.
- More comments: There is a hacky extension for exactly this purpose, but it is not enabled on any WMF wiki. This is a trivial task, so a native implementation would be way simpler than bothering with another extension, and is thus preferable.
- Phabricator tickets:
- Proposer: Taylor 49 (talk) 10:05, 5 February 2023 (UTC)
Discussion
- When such a Lua method would reference a different page, that would mean the current page would have to be updated whenever the referenced page is edited in such a way that changes its categorization. That's a kind of change tracking we are not doing currently. When the Lua method would reference the current page, it would require an extra parser pass since categories can be added later on in the page source. I doubt either of those are feasible changes. --Tgr (talk) 19:06, 6 February 2023 (UTC)
- If it can be useful, for my own wiki I developed mw:Extension:CategoryToolbox that exposes
mw.ext.cattools.hasPage
in Lua to check whenever a page is inside a category. --Valerio Bozzolan (talk) 20:47, 6 February 2023 (UTC) - See phab:T50175.--GZWDer (talk) 23:36, 8 February 2023 (UTC)
- Per Tgr's comment, this is infeasible. Thanks for participating in the survey! JMcLeod (WMF) (talk) 19:45, 9 February 2023 (UTC)