Content deleted Content added
m Archiving 1 discussion(s) from Module talk:Check for unknown parameters) (bot |
m Archiving 1 discussion(s) from Module talk:Check for unknown parameters) (bot |
||
(5 intermediate revisions by the same user not shown) | |||
Line 314:
Hello! I was brought here after a user posted to the Teahouse that they had an issue with an infobox template that resulted from non-breaking spaces being used in the parameter name. When previewing the edit, because of the non-breaking spaces it said it was an unknown parameter. Would it be possible to include some way to cue the user in that it may be due to non-breaking spaces, by either adding something that says "Check for non-breaking spaces" or by giving a unique error message if it detects there are non-breaking spaces in the parameter name? ― [[User:Blaze Wolf|<b style="background:#0d1125;color:#51aeff;padding:1q;border-radius:5q;">Blaze Wolf</b>]][[User talk:Blaze Wolf|<sup>Talk</sup>]]<sub title="Discord Username" style="margin-left:-22q;">Blaze Wolf#6545</sub> 02:03, 18 February 2022 (UTC)
:: Yes if it clearly mentions what is the issue not only new users also users who lave low experience in this CODING programs can catch the problem easily. <span style="color:DarkGray">...</span> [[User:२ तकर पेप्सी|<span style="color:Red">'''२ तकर'''</span><span style="color:Green">'''''पेप्सी'''''</span>]] <sub>[[User talk:२ तकर पेप्सी|'''<span style="color:SkyBlue">talk</span>''']]</sub> 02:13, 18 February 2022 (UTC)
== automatic fetch of template parameter names ==
For quite some time I have thought that manually curating a list of parameters that each template supports is rather a waste of editor time. Recently this extra maintenance was discussed at {{slink|Wikipedia:Village_pump_(technical)|Template:Infobox_dog_breed}} which caused me to wonder if there isn't a way to automate the supported-parameter list maintenance.
<s>I have hacked this module's sandbox ([[Module:Check_for_unknown_parameters/sandbox#L-53|lines 53–65]]) so that if given the template's name in new parameter {{para|template_name}}</s>, the module will read the unparsed content of the template and extract parameter names to fill <code>knownargs</code>.
{{tlx|Infobox dog breed/sandbox}} calls the sandbox version of this template with {{para|template_name|Template:Infobox dog breed/sandbox}} and all of the positional parameters have been removed. If you edit and preview [[Template:Infobox dog breed/testcases]] you can compare the sandbox to the live version.
If for some reason, a supported parameter isn't or can't be extracted from the template wikitext, positional parameters are still supported.
Alas, I know of no way for a module to get the name of the template that invokes it so I think that we are stuck with <s>{{para|template_name}}</s>. Is there a way avoid that parameter that I don't know about?
Keep? Discard?
—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) <s>23:19, 4 September 2022 (UTC)</s> {{small|strikeout 15:11, 5 September 2022 (UTC)}}
: To directly answer the question, you can use <code>frame:getParent():getTitle()</code> to get the name of the template. That said, the underlying idea was previously objected to at [[/Archive 1#Could this be automated?]] and [[/Archive 1#Blank usage]] [[User:Pppery|* Pppery *]] [[User talk:Pppery|<sub style="color:#800000">it has begun...</sub>]] 23:45, 4 September 2022 (UTC)
::(Do I need a self-troutslap? ahead). When {{button|Managing TemplateData}} in a template /doc page, the tool lists all missing (not-yet-TDdocumented) parameters. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 09:22, 5 September 2022 (UTC)
:::This discussion has nothing to do with [[WP:TemplateData]]. I did think about using TemplateData and a source for template parameter names but, because TemplateData are manually curated, using those data suffers the same issue as the manually curated list of positional parameter ins this module's invoke.
:::—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 15:11, 5 September 2022 (UTC)
::::Yeah I got that. Now, what I tried to point to: when opening the Manage TemplateData screen, TD ''automatically'' checks for all parameter names (and then lists those not yet in the /doc page, with an Add-All-These-to-/doc button). So, step 1 is an automated find-all-parameternames tool somehow. (And has nothing to do with step 2, the manual /doc page content). [[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 15:27, 5 September 2022 (UTC)
:::::That's javascript isn't it? As far as I know, there isn't a way for a lua module to interact with javascript.
:::::—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 16:42, 5 September 2022 (UTC)
::New hack to use <code>frame:getParent():getTitle()</code> when {{para|autofetch}} has any assigned value ([[Module:Check_for_unknown_parameters/sandbox#L-48|lines 48–59]]).
::
::At [[/Archive 1#Could this be automated?]] Editor [[User:Jonesey95|Jonesey95]] wrote:
:::{{tq|The module can't always determine which parameters are actually supported.}}
::::At the time of that writing, [[Module:Check for unknown parameters]] relied on a manually curated list of the template's supported parameters; still does, doesn't it? If there was/is a problem such that the module cannot always {{tq|determine which parameters are actually supported}} then that is a problem with the existing module that should be identified and fixed. That has nothing to do with auto-fetching parameter names from a template's wikitext.
::and:
:::{{tq|It sometimes fails to pick up valid parameters,...}}
::::Again, if the module is using a manually curated list of a template's parameter names and {{tq|fails to pick up valid parameters}} then that too is a problem with the existing module that should be identified and fixed. That has nothing to do with auto-fetching parameter names from a template's wikitext.
::and finishing that sentence:
:::{{tq|...and sometimes picks up parameters that are being tested for but are not actually supported.}}
::::That makes no sense to me; if a parameter is {{tq|being tested for}} that parameter is {{tq|actually supported}}. How is it that a {{tq|tested for}} parameter is not supported?
::One thing that I take from the above is that it is possible for parameters to be hidden in {{tag|!--}} tags which automatically makes any unique parameter name inside the html comment unsupported. To prevent those unsupported parameters from being included in the supported-parameter list, I have added a snippet of code to remove all html comments before fetching parameter names.
::
::At [[/Archive 1#Blank usage]], Editor [[User:Frietjes|Frietjes]] wrote:
:::{{tq|that would be expensive}} and {{tq|string parsing the infobox code every single time you use an infobox would be really expensive}}. The term ''expensive'', in templates and modules, has a specific meaning. This hack to the module does not increment the expensive parser function count (see the parser profiling data table when you preview [[Template:Infobox dog breed/testcases]]). Yes, I agree that auto-fetching parameter names every time a page with an infobox is parsed is not necessarily the ideal, but usually, there is only one infobox per article so the cost in processor time and memory usage is relatively small.
::—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 15:11, 5 September 2022 (UTC)
:::The basic case in which the "make a list of all of the parameters" script does not work is when the template consists solely of a module invocation. See, for example, {{tl|Track listing}}, which needed [https://en.wikipedia.org/w/index.php?title=Template%3ATrack_listing&type=revision&diff=1093596874&oldid=755296207 manual intervention]. – [[User:Jonesey95|Jonesey95]] ([[User talk:Jonesey95|talk]]) 16:05, 5 September 2022 (UTC)
::::Agreed; this module hack does not apply to that kind of template. Manually curated lists of parameters are not prohibited by this scheme because an editor must deliberately instruct the module to auto-fetch parameter names by intentionally setting {{para|autofetch|<{{var|something}}>}}. The existence of these invoke-only templates should not be used as grounds to prevent the scheme's implementation for use with generic wikitext templates.
::::—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 16:42, 5 September 2022 (UTC)
== Use from module ==
Is it possible to use this module directly from another module, or does it always need to be placed on a template page? — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 16:11, 30 December 2022 (UTC)
:@[[User:Frietjes|Frietjes]]: any chance you could help me with the above? — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 19:04, 8 January 2023 (UTC)
::Something like this should work for you: <syntaxhighlight lang="lua">
local validArgs = { ... }
local checkForUnknownParameters = require("Module:Check for unknown parameters")
local result = checkForUnknownParameters._check(validArgs, args)
</syntaxhighlight> [[User:Gonnym|Gonnym]] ([[User talk:Gonnym|talk]]) 11:41, 9 January 2023 (UTC)
::[[User:MSGJ|MSGJ]], see the end of [[Module:Rugby box]] for a simple example or [[Module:Infobox3cols]] or [[Module:Flag]] for more complicated examples. [[User:Frietjes|Frietjes]] ([[User talk:Frietjes|talk]]) 15:50, 9 January 2023 (UTC)
:::Thanks both, I will give it a try — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 12:10, 11 January 2023 (UTC)
Works great. I will add instructions to the documentation when I get time. Non-urgent feature request: it would be nice if I could specify which namespaces I want to check unknown parameters in. Easy enough to do locally of course, but would be tidier if it was in this module. — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 13:15, 11 January 2023 (UTC)
== Pagenames involved ==
For de-confusion, pagenames involved:
*{{redirect and target|format=report|Module:Check for unknown parameters}} -- has best documentation
*{{redirect and target|format=report|Module talk:Check for unknown parameters}}
*{{redirect and target|format=report|Template:Checks for unknown parameters/doc}} -- needs a check; transclusion advice 'Use this /doc in template documentation' is tested or applied?
*{{redirect and target|format=report|Template:Checks for unknown parameters}} -- has plural ''Checks ...''
*{{redirect and target|format=report|Template:Check for unknown parameters}}
*{{redirect and target|format=report|Template talk:Checks for unknown parameters}} -- was redlink; now talk central
*{{redirect and target|format=report|WP:CFUP}} -- ''R'' to the /doc, not create a templatename-redirect
*Not done (yet): [[Template:fcup]] as template ''R''?
-[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 07:37, 28 February 2023 (UTC)
== Feature request ==
Would it be possible to distinguish between ''unknown'' and ''deprecated'' parameters? It would be useful sometimes to track deprecated parameters in a different category, or with a different preview message. — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 20:17, 4 December 2023 (UTC)
:[[:Module:Check for deprecated parameters]]. – [[User:Jonesey95|Jonesey95]] ([[User talk:Jonesey95|talk]]) 16:06, 5 December 2023 (UTC)
::Thanks — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 17:42, 5 December 2023 (UTC)
== Error category should also be added in preview ==
If there is an error category for unknown parameters then it's only added in the rendered page, not previews which instead show a preview warning. That can be very confusing. Consider for example [[Copa Libertadores Femenina]] ([https://en.wikipedia.org/w/index.php?title=Copa_Libertadores_Femenina&oldid=1181533151 permanent link]) with [[:Category:Pages using flagicon template with unknown parameters]]. The page has 135 {{tl|flagicon}}. The unknown parameter is in <code><nowiki>{{flagicon|BRA|side=30px}}</nowiki></code> (should have said size). It's common to track down where a category is added by previewing different parts of the code. That fails here when the category is never added in preview. You can search for the preview warning in the preview but users may not know that. Previews can add things but shouldn't remove things. [[User:PrimeHunter|PrimeHunter]] ([[User talk:PrimeHunter|talk]]) 11:36, 9 December 2023 (UTC)
== 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>
:—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 12:59, 23 June 2024 (UTC)
::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).
:::::—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 22:00, 24 June 2024 (UTC)
|