Module talk:Check for unknown parameters: Difference between revisions
→Suggested enhancement: new section |
m Archiving 1 discussion(s) to Module talk:Check for unknown parameters/Archive 1) (bot |
||
(7 intermediate revisions by 2 users not shown) | |||
Line 14: | Line 14: | ||
| minthreadstoarchive=1 |
| minthreadstoarchive=1 |
||
}} |
}} |
||
== Lua patterns == |
|||
Is it possible to add a function to use Lua patterns and also limit the number? For example, if the parameter {{para|date}} can be between {{para|date1}} and {{para|date8}} and using <code>regexp1 = "date[%d]+"</code> and something like <code>reglimit1=8</code> to limit the allowed parameters? [[User:Gonnym|Gonnym]] ([[User talk:Gonnym|talk]]) 12:26, 23 June 2024 (UTC) |
|||
:Why not write a specific pattern? <syntaxhighlight lang="lua" inline="1">regexp1 = "date[1-8]"</syntaxhighlight> |
|||
⚫ | |||
::Didn't even cross my mind to do that for some reason. I'll try that out, thanks! [[User:Gonnym|Gonnym]] ([[User talk:Gonnym|talk]]) 13:01, 23 June 2024 (UTC) |
|||
::@[[User:Trappist the monk|Trappist the monk]] doesn't work. Tested it on [[TNA Impact!]] by using the /sandbox version in preview. [[User:Gonnym|Gonnym]] ([[User talk:Gonnym|talk]]) 13:06, 23 June 2024 (UTC) |
|||
:::Nevermind, got it to work without the quotes of course. I'll update the /doc here. [[User:Gonnym|Gonnym]] ([[User talk:Gonnym|talk]]) 13:09, 23 June 2024 (UTC) |
|||
::::You could also look at the check at {{tl|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). – [[User:Jonesey95|Jonesey95]] ([[User talk:Jonesey95|talk]]) 19:43, 24 June 2024 (UTC) |
|||
:::::The pattern <code>[1-9][%d]*</code> (should probably be written <code>[1-9]%d*</code>) is not limited to the range 1–99. <code>%d*</code> 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 <code>%f[%d][1-9]%d?$</code> where (right to left) <code>$</code> anchors the pattern to the end of the parameter name string; <code>%d?</code> means 0 or 1 digits; <code>[1-9]</code> requires the first digit of the enumeration to be in the range 1–9; <code>%f[%d]</code> is the frontier pattern where the next character is a digit but the previous character is not a digit – in <code>abc123</code> the pattern finds the boundary between <code>c</code> (parameter name) and <code>1</code> (first digit of the enumerator). |
|||
⚫ | |||
== Protected edit request on 29 August 2024 == |
== Protected edit request on 29 August 2024 == |
||
Line 38: | Line 26: | ||
{{see also|Module_talk:WikiProject banner}} |
{{see also|Module_talk:WikiProject banner}} |
||
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 <code>fallback</code> which is a category which will be used if the one specified in <code>unknown</code> 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 <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 14:19, 4 September 2024 (UTC) |
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 <code>fallback</code> which is a category which will be used if the one specified in <code>unknown</code> 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 <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 14:19, 4 September 2024 (UTC) |
||
: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'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 {{tl|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 <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 21:02, 4 September 2024 (UTC) |
|||
:::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#L-113|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 <syntaxhighlight lang="lua" inline="1">table.concat(res)</syntaxhighlight> returns an empty string. So, it looks like <syntaxhighlight lang="lua" inline="1">p._check(args, pargs)</syntaxhighlight> returns: |
|||
::::<code>nil</code> when either of <code>args</code> and <code>pargs</code> is not a table |
|||
::::<code>''empty string''</code> 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 <syntaxhighlight lang="lua" inline="1">require('Module:Check for unknown parameters')._check(parameters, parent_args)</syntaxhighlight> before you fiddle about with categories. |
|||
⚫ | |||
::::Great, thanks. I'll look into that — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 08:55, 5 September 2024 (UTC) |
|||
::::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 <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 09:06, 5 September 2024 (UTC) |
|||
:::::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. |
|||
:::::—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 11:48, 5 September 2024 (UTC) |
Latest revision as of 20:03, 23 September 2024
Module:Check for unknown parameters is permanently protected from editing because it is a heavily used or highly visible module. Substantial changes should first be proposed and discussed here on this page. If the proposal is uncontroversial or has been discussed and is supported by consensus, editors may use {{edit protected}} to notify an administrator to make the requested edit.
|
This module was considered for merging on 2019 December 30. The result of the discussion was "no consensus". |
This is the talk page for discussing improvements to the Check for unknown parameters module. |
|
Archives: 1Auto-archiving period: 3 months |
This module does not require a rating on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | ||||||||
|
Protected edit request on 29 August 2024
[edit]This edit request has been answered. Set the |answered= or |ans= parameter to no to reactivate your request. |
On Module:Check_for_unknown_parameters#L-94, please replace the undefined variable preview
with preview_text
. That expression is always going to evaluate to true and so will never reach the third expression. Awesome Aasim 17:57, 29 August 2024 (UTC)
- 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. - —Trappist the monk (talk) 18:08, 29 August 2024 (UTC)
Suggested enhancement
[edit]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)
- 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)
- 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)
- 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 likep._check(args, pargs)
returns:nil
when either ofargs
andpargs
is not a tableempty 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)
- Great, thanks. I'll look into that — Martin (MSGJ · talk) 08:55, 5 September 2024 (UTC)
- 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)
- 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)
- 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
- 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)