This module is within the scope of WikiProject Templates, a group dedicated to improving the maintenance of Wikipedia's templates. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.TemplatesWikipedia:WikiProject TemplatesTemplate:WikiProject TemplatesTemplates
Lua patterns
Is it possible to add a function to use Lua patterns and also limit the number? For example, if the parameter |date= can be between |date1= and |date8= and using regexp1 = "date[%d]+" and something like reglimit1=8 to limit the allowed parameters? Gonnym (talk) 12:26, 23 June 2024 (UTC)[reply]
Why not write a specific pattern? regexp1="date[1-8]"
You could also look at the check at {{Interlinear}} for a fun example. It supports values of 1–99 for some parameters (actually 1 and higher, but I'm hoping nobody will put in more than 99 unnamed parameters). – Jonesey95 (talk) 19:43, 24 June 2024 (UTC)[reply]
The pattern [1-9][%d]* (should probably be written [1-9]%d*) is not limited to the range 1–99. %d* means 0 or more digits. So, as long as the first digit is not zero, any number of digits (within reason) will be accepted. If you want to actually limit the range to 1–99 you might use %f[%d][1-9]%d?$ where (right to left) $ anchors the pattern to the end of the parameter name string; %d? means 0 or 1 digits; [1-9] requires the first digit of the enumeration to be in the range 1–9; %f[%d] is the frontier pattern where the next character is a digit but the previous character is not a digit – in abc123 the pattern finds the boundary between c (parameter name) and 1 (first digit of the enumerator).
Done. Also added require ('strict') which will catch other globals. Keep an eye on Category:Pages with script errors to see if the addition reveals other globals.
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.
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.
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.