We are using this module on Module:WikiProject banner. We first check if Category:Pages using WikiProject PROJECT with unknown parameters exists and if not, then we use Category:WikiProject templates with unknown parameters instead. The problem is that this is causing thousands of links to non-existent categories to be recorded, which can be seen in Special:WantedPages. My suggestion is as follows. The module can accept an additional argument called fallback
which is a category which will be used if the one specified in unknown
does not exist. In this way we can check existence of that category only when unknown parameters are discovered, not in every single case. — Martin (MSGJ · talk) 14:19, 4 September 2024 (UTC)Reply
- What is it that I'm missing? If the problem is caused by something that happens in Module:WikiProject banner, that is where the fix should be applied. Adding miscellaneous one-off patches to this module is not a good idea. When you switch to the default category, you know that the preferred category does not exist so why link to it? Link to the preferred category only when it exists.
- —Trappist the monk (talk) 15:35, 4 September 2024 (UTC)Reply
- I'll try and explain better. Or you can look at the code at around Module:WikiProject banner#L-831. We have to check existence before calling this module. Checking existence adds a link to the page. Therefore every transclusion of {{WikiProject Lepidoptera}} is generating a link to Category:Pages using WikiProject Lepidoptera with unknown parameters which is not so good. I would prefer to only check if the category exists if there are some unknown parameters. That check can only happen in this module. Or perhaps you have a better idea — Martin (MSGJ · talk) 21:02, 4 September 2024 (UTC)Reply
- I haven't taken any real time to study the code (it has taken me more time to write this than I spent looking at the code) but Module:Check for unknown parameters line 113 appears to return a concatenated string of unknown parameters (apparently without delimiters). If there are no unknowns then the
table.concat(res)
returns an empty string. So, it looks like p._check(args, pargs)
returns:
nil
when either of args
and pargs
is not a table
empty string
when there are no unknown parameters
- some sort of list of unknown parameters
- If this is true then you should be checking the returned value from
require('Module:Check for unknown parameters')._check(parameters, parent_args)
before you fiddle about with categories.
- —Trappist the monk (talk) 22:22, 4 September 2024 (UTC)Reply
- Great, thanks. I'll look into that — Martin (MSGJ · talk) 08:55, 5 September 2024 (UTC)Reply
- Yes that works. Unfortunately it means that I need to call the module twice: the second time after deciding which category to use. But this will only happen if there are any unknown parameters so will not affect performance unduly. — Martin (MSGJ · talk) 09:06, 5 September 2024 (UTC)Reply
- Add comments to your code. When you are crushed by a steamroller while jaywalking Main Street, whoever comes after you to maintain that module can then know why you did what you did.
- —Trappist the monk (talk) 11:48, 5 September 2024 (UTC)Reply