Module:Check for clobbered parameters: Difference between revisions

From NvWiki
Jump to navigation Jump to search
Rename: Reply
m 1 revision imported: Import modules used with Template:Infobox software
Line 1: Line 1:
{{WikiProject banner shell|
local p = {}
{{WikiProject Templates|module_for_template_maintenance=y}}
}}
== Preview warning and hatnotes moving to templatestyles ==


Page watchers may be interested in {{slink|MediaWiki talk:Common.css|Preview warning and hatnotes moving to TemplateStyles}} [[User:Izno|Izno]] ([[User talk:Izno|talk]]) 00:22, 29 April 2021 (UTC)
local function trim(s)
return s:match('^%s*(.-)%s*$')
end


== Preview? ==
local function isnotempty(s)
return s and s:match('%S')
end


Any chance of adding a {{param|preview}} option, in the same way as [[Module:Check for unknown parameters]]. Alternatively, add a link to the template being checked to the error message shown in preview mode. See the use made for preview in the {{TL|Infobox website}} template [[User:GhostInTheMachine|GhostInTheMachine]] <sup>[[User talk:GhostInTheMachine|talk to me]]</sup> 14:12, 23 October 2023 (UTC)
function p.check(frame)
local args = frame.args
local pargs = frame:getParent().args
local checknested = isnotempty(args['nested'])
local delimiter = isnotempty(args['delimiter']) and args['delimiter'] or ';'
local argpairs = {}
for k, v in pairs(args) do
if type(k) == 'number' then
local plist = mw.text.split(v, delimiter)
local pfound = {}
local count = 0
for ii, vv in ipairs(plist) do
vv = trim(vv)
if checknested and pargs[vv] or isnotempty(pargs[vv]) then
count = count + 1
table.insert(pfound, vv)
end
end
if count > 1 then
table.insert(argpairs, pfound)
end
end
end
local warnmsg = {}
local res = ''
local cat = ''
if args['cat'] and mw.ustring.match(args['cat'],'^[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]:') then
cat = args['cat']
end
local template = args['template'] and ' in ' .. args['template']  or ''
if #argpairs > 0 then
for i, v in ipairs( argpairs ) do
table.insert(
warnmsg,
mw.ustring.format(
'Using more than one of the following parameters%s: <code>%s</code>.',
template,
table.concat(v, '</code>, <code>')
)
)
if cat ~= '' then
res = res .. '[[' .. cat .. '|' .. (v[1] == '' and ' ' or '') .. v[1] .. ']]'
end
end
end
if #warnmsg > 0 then
res = require('Module:If preview')._warning({
table.concat(warnmsg, '<br>')
}) .. res
end
return res
end


== Rename ==
return p
 
Given that the categories and error messages all describe "conflicting" parameters, does it make sense to rename this module [[Module:Check for conflicting parameters]]? '''[[User:Zackmann08|<span style="color:#00d5ff">Zack</span><span style="color:#007F94">mann</span>]]''' (<sup>[[User_talk:Zackmann08|Talk to me]]</sup>/<sub>[[Special:Contributions/Zackmann08|<span style="color:orange">What I been doing</span>]]</sub>) 19:38, 15 December 2025 (UTC)
 
:[[wikt:clobber|clobber]] has a very specific meaning that kinda fits this module, but even the module's documentation [[Special:Diff/926362416|created by the original module's author]] has called it "conflicting parameters" since the beginning. The tracking category tree is under [[:Category:Conflicting parameters]] with most of it under {{clc|Infoboxes with conflicting parameters}}.
:So we have:
:# [[Module:Check for unknown parameters]] and {{cl|Unknown parameters}} – consistent.
:# [[Module:Check for deprecated parameters]] and {{cl|Deprecated parameters}}. A subcategory [[:Category:Anime and manga articles using obsolete and incorrect infobox parameters|Anime and manga articles using {{em|obsolete}} and incorrect infobox parameters]] calls them "obsolete", but otherwise the used terminology is fairly consistent.
:# [[Module:Check for clobbered parameters]] + [[:Category:Conflicting parameters]]
:Based on this, I support renaming to [[Module:Check for conflicting parameters]].
:''Side note'': we also have [[:Category:Articles using duplicate arguments in template calls]] and [[:Category:Pages using duplicate arguments in template calls]]. Both are defined by [[MediaWiki:Duplicate-args-category]], but they are for exact duplicates, not for the stuff this module checks like {{param|founders|{{param|founder|}}}} ([[Module:Check for clobbered parameters/doc#Example 1|example 1 in /doc]]). —⁠[[User:Andrybak|andrybak]] ([[User talk:Andrybak|talk]]) 20:33, 15 December 2025 (UTC)
::To be clear, I '''totally''' understand why it was called clobbered initially. I just think it would be helpful to keep consistent. Can the Module namespace support redirects? I've never tried that before... If you {{mlx|check for clobbered parameters|check}} after a move is decided upon, would that still work or will we have to change every call to this? '''[[User:Zackmann08|<span style="color:#00d5ff">Zack</span><span style="color:#007F94">mann</span>]]''' (<sup>[[User_talk:Zackmann08|Talk to me]]</sup>/<sub>[[Special:Contributions/Zackmann08|<span style="color:orange">What I been doing</span>]]</sub>) 20:44, 15 December 2025 (UTC)
::: MediaWiki automatically creates Module redirects, and they work as you'd expect. Example: {{No redirect|Module:Location map/data/Dili}}. —⁠[[User:Andrybak|andrybak]] ([[User talk:Andrybak|talk]]) 21:02, 15 December 2025 (UTC)
::::Stellar! Thanks. '''[[User:Zackmann08|<span style="color:#00d5ff">Zack</span><span style="color:#007F94">mann</span>]]''' (<sup>[[User_talk:Zackmann08|Talk to me]]</sup>/<sub>[[Special:Contributions/Zackmann08|<span style="color:orange">What I been doing</span>]]</sub>) 21:52, 15 December 2025 (UTC)
::<s>'''Rename''' but also make sure to replace the redirect.</s> This module, unlike Check for unknown parameters, should be temporarily until the parameters can be replaced. It would be good to go over every usage and see if the job was completed and remove the module or update the link. [[:Category:Infoboxes with conflicting parameters]] has too many empty categories. [[User:Gonnym|Gonnym]] ([[User talk:Gonnym|talk]]) 09:55, 17 December 2025 (UTC)
:::I don't think such parameters are meant to be removed from the wikitext of the templates. As far as I understand, these are regular maintenance categories, not aids in template refactoring. E.g. if someone adds {{para|founder}} by accident to a transclusion of a template not realizing that {{para|founders}} is already present. The corresponding categories are meant to be empty most of the time. In the particular example ([[Module:Check for clobbered parameters#Example 1]]), the two different parameters have slightly different effect: the plural parameter turns the label in the infobox into plural, which avoids having unsightly "Founder(s)" as the label.
:::Or am I misunderstanding something? —⁠[[User:Andrybak|andrybak]] ([[User talk:Andrybak|talk]]) 12:54, 17 December 2025 (UTC)
::::Andry is correct. It is [[:Category:Deprecated parameters]] that is meant to be short lived... '''[[User:Zackmann08|<span style="color:#00d5ff">Zack</span><span style="color:#007F94">mann</span>]]''' (<sup>[[User_talk:Zackmann08|Talk to me]]</sup>/<sub>[[Special:Contributions/Zackmann08|<span style="color:orange">What I been doing</span>]]</sub>) 15:30, 17 December 2025 (UTC)
:::::{{ping|Gonnym}} there are ''some'' cases where the conflicting params can/should be cleaned up. For example if you have {{param|website}} conflicting with {{param|homepage}} you could argue for cleaning up one but remember, the category being empty doesn't mean you can remove one of those parameters... There may be many uses of both. The category only populates if a transclusion uses '''both''' parameters. You would need to use [[Module:Check for deprecated parameters]] to deprecate one of those parameters and then remove all uses of it, converting them to use the other. For the record, I am doing that on Infoboxes that have lots of aliases. (See for example my current work on {{tl|Infobox venue}} -> {{clc|Category:Pages using infobox venue with deprecated parameters}}).
:::::There are also cases where you need to keep the category for conflicting params that cannot be deprecated. For example, on {{tl|Infobox organization}}, {{param|formation}}, {{param|established}}, {{param|founded_date}} & {{param|founded}} all conflict. But depending on which one you use, the label displays differently. This is '''not''' a case where you can deprecate 3 of them to end up with only 1 parameter accepted. (Though I guess you could deprecate {{param|founded_date}} in favor of {{param|founded}}). Hope that makes sense... {{smiley|christmas}} '''[[User:Zackmann08|<span style="color:#00d5ff">Zack</span><span style="color:#007F94">mann</span>]]''' (<sup>[[User_talk:Zackmann08|Talk to me]]</sup>/<sub>[[Special:Contributions/Zackmann08|<span style="color:orange">What I been doing</span>]]</sub>) 16:08, 17 December 2025 (UTC)
::::::If the only reason for this module is to do what you guys say, then this module and category system is completely pointless. If the template doesn't care if you write {{para|founder}} or {{para|founders}} then leave it alone. If, however, you want cleaner template code and want to get rid of the plural parameters (which makes complete sense), then such a category makes sense. [[User:Gonnym|Gonnym]] ([[User talk:Gonnym|talk]]) 16:55, 17 December 2025 (UTC)
:::::::I'm looking at [[Template:Infobox organization]]. The parameter paris in the like of <code>full_name; full name</code> are not conflicting. If they aren't meant to be replaced and one of them later removed, then everything here is wrong. The proposed name of the module, the tracking category, and even the tracking itself. [[User:Gonnym|Gonnym]] ([[User talk:Gonnym|talk]]) 16:58, 17 December 2025 (UTC)
::::::::As of [[Special:Diff/1328040937]], in [[Template:Infobox organization]] parameters <code>full_name</code> (with an underscore) and <code>full name</code> (with a space) are conflicting. The wikitext for their usage in the infobox is: <syntaxhighlight lang="wikitext" inline>{{#if:{{{full_name|}}}{{{full name|}}}|<div [...]>{{if empty|{{{full_name|}}}|{{{full name|}}}}}</div>}}</syntaxhighlight>. Per [[Template:If empty/doc]], parameter <code>full_name</code> "wins", it "clobbers" parameter <code>full name</code> if they happened to be both used at the same time, e.g. {{tlc|Infobox organization|full_name{{=}}foo|full name{{=}}bar}}.
::::::::Unlike earlier example with founder/founders, [[Template:Infobox organization]] doesn't care which of the two parameters is used, but it does care if both of them are used at the same time. The tracking helps fix such cases. —⁠[[User:Andrybak|andrybak]] ([[User talk:Andrybak|talk]]) 17:12, 17 December 2025 (UTC)
:::::::::{{ping|Gonnym}} I think you are misunderstanding how this code works... Remember, they are only conflicting (and only a trigger an error & tracking category) when BOTH parameters are used (even if one is blank). This is particularly useful and necessary when you are using a wrapper. Look at {{tl|Infobox social media personality}} for example where {{code|pseudonym}} is an alias of {{code|other_names}}. If you use one '''OR''' the other, there is no problem. But if both are supplied, '''even if one is blank''', then you get weird behavior. I'm not even sure off the top of my head which would "win" but without this warning, you could be supplying a param that is not displaying and have no clue why it is not displaying.
:::::::::Now using the example {{u|andrybak}} listed above with {{tl|Infobox organization}} I do agree that the ultimate goal should be to eliminate {{para|full name}} in favor of {{para|full_name}} (See [[MOS:INFOBOXNAME]]) but as someone who has done these cleanups many times, they are labor intensive and time consuming. When warranted (like I'm currently doing with {{tl|Infobox venue}}) they can certainly be done. But in the mean time, the conflicting param check is needed to ensure errors don't crop up.
:::::::::Final point... FWIW I am less concerned with the categories. There may be people who patrol these categories... I'm more a fan of patrolling [[CAT:UNKNOWN]] myself... The '''much''' more significant thing here (IMHO) is the preview warning that helps explain why information is not displaying correctly. '''[[User:Zackmann08|<span style="color:#00d5ff">Zack</span><span style="color:#007F94">mann</span>]]''' (<sup>[[User_talk:Zackmann08|Talk to me]]</sup>/<sub>[[Special:Contributions/Zackmann08|<span style="color:orange">What I been doing</span>]]</sub>) 20:08, 17 December 2025 (UTC)
::::::::::I see the word "conflicting" differently then. The example above is for me a sign to deprecate and fix, instead of track and do nothing (or even worse, manually fix and keep letting editors continue using). [[User:Gonnym|Gonnym]] ([[User talk:Gonnym|talk]]) 13:52, 21 December 2025 (UTC)
{{Outdent|::::::::::}}
[[User:Gonnym|Gonnym]], could you please clarify which of the three examples is "a sign to deprecate and fix": [[Template:Infobox venue]], [[Template:Infobox organization]], or [[Template:Infobox social media personality]]? —⁠[[User:Andrybak|andrybak]] ([[User talk:Andrybak|talk]]) 13:59, 21 December 2025 (UTC)
 
:I meant with {{para|full_name}} and {{para|full name}}. [[User:Gonnym|Gonnym]] ([[User talk:Gonnym|talk]]) 14:00, 21 December 2025 (UTC)
::Yes, that's why Zackmann wrote {{tq|1= the ultimate goal should be to eliminate {{para|full name}} in favor of {{para|full_name}}}} and I fully agree that one of them should be deprecated (quote from [[MOS:INFOBOXNAME]] for reference: {{tq|1=[[meta:Help:Parameters|Parameters]] in infoboxes should [...] use [[snake case]] (e.g., {{para|birth_date}}), not [[camel case]] }}). The deprecation just hasn't been done yet for this particular pair of parameters.
::[[User:Gonnym|Gonnym]], is the example with founder/founders clear? Are we on the same page about what "clobbered" and "conflicting" means in the scope of this module? —⁠[[User:Andrybak|andrybak]] ([[User talk:Andrybak|talk]]) 14:16, 21 December 2025 (UTC)
:::But that example is another example of deprecating and one being deleted. That style was the old way of doing plural before we got [[Template:Pluralize from text]]. [[User:Gonnym|Gonnym]] ([[User talk:Gonnym|talk]]) 14:21, 21 December 2025 (UTC)
::::Oh. I wasn't aware of [[Template:Pluralize from text]]. That's neat.
::::''Back on topic'': The "conflicting"/"clobbered" parameters are a pair of parameters that are used in the template as {{param|foo|{{param|bar|}}}} or {{param|bar|{{param|foo|}}}} or equivalent more complex constructions {{em|and}} both get passed at the transclusion site {{tlc|example|foo{{=}}one|bar{{=}}two}}. Their status as "conflicting"/"clobbered" applies {{em|regardless}} of their deprecation status. —⁠[[User:Andrybak|andrybak]] ([[User talk:Andrybak|talk]]) 14:30, 21 December 2025 (UTC)
:::::Back to the ''original'' topic... Is there any objection to renaming this module? '''[[User:Zackmann08|<span style="color:#00d5ff">Zack</span><span style="color:#007F94">mann</span>]]''' (<sup>[[User_talk:Zackmann08|Talk to me]]</sup>/<sub>[[Special:Contributions/Zackmann08|<span style="color:orange">What I been doing</span>]]</sub>) 15:37, 23 December 2025 (UTC)

Revision as of 16:56, 26 December 2025

Template:Module rating

This module may be appended to a template to check for uses of tuples of conflicting parameters.

Usage

Basic usage

{{#invoke:Check for clobbered parameters|check
|nested=1
|template=Some template name
|cat={{main other|Category:Pages using TEMPLATENAME with conflicting parameters}}
|arg1a; arg1b|arg2a; arg2b; arg2c|...|argNa; argNb}}

Here, (arg1a, arg1b), (arg2a, arg2b, arg2c), are tuples of the conflicting parameters.

By default, the module ignores blank parameters which is useful for {{if empty}} chains of parameters. For nested chains of parameters, use |nested=1 to consider blank parameters as well.

By default, the delimiter for the tuples is ; but this can be changed with |delimiter=.

The value of |template= is used to for the text of the preview warning message. When omitted, the module will use a generic message.

Example 1

{{Infobox
| above = {{{name|}}}

| label1 = Founder{{#if:{{{founders|}}}|s}}
| data1 = {{if empty| {{{founders|}}} | {{{founder|}}} }}

| label2 = Headquarters
| data2 = {{if empty| {{{headquarters|}}} | {{{hq|}}} | {{{location|}}} }}

}}<!-- 
  end infobox, start tracking
-->{{#invoke:Check for clobbered parameters|check
| template = Infobox example
| cat = {{main other|Category:Pages using infobox example with conflicting parameters}}
| founders; founder
| headquarters; hq; location
}}

Example 2

{{Infobox
| above = {{{name|}}}

| label1 = Founder(s)
| data1 = {{{founders|{{{founder|}}}}}}

| label2 = Headquarters
| data2 = {{{headquarters|{{{hq|{{{location|}}}}}}}}}

}}<!-- 
  end infobox, start tracking
-->{{#invoke:Check for clobbered parameters|check
| nested = 1
| template = Infobox example
| cat = {{main other|Category:Pages using infobox example with conflicting parameters}}
| founders; founder
| headquarters; hq; location
}}

See also


local p = {}

local function trim(s)
	return s:match('^%s*(.-)%s*$')
end

local function isnotempty(s)
	return s and s:match('%S')
end

function p.check(frame)
	local args = frame.args
	local pargs = frame:getParent().args
	local checknested = isnotempty(args['nested'])
	local delimiter = isnotempty(args['delimiter']) and args['delimiter'] or ';'
	local argpairs = {}
	
	for k, v in pairs(args) do
		if type(k) == 'number' then
			local plist = mw.text.split(v, delimiter)
			local pfound = {}
			local count = 0
			for ii, vv in ipairs(plist) do
				vv = trim(vv)
				if checknested and pargs[vv] or isnotempty(pargs[vv]) then
					count = count + 1
					table.insert(pfound, vv)
				end
			end
			if count > 1 then
				table.insert(argpairs, pfound)
			end
		end
	end
	
	local warnmsg = {}
	local res = ''
	local cat = ''
	if args['cat'] and mw.ustring.match(args['cat'],'^[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]:') then
		cat = args['cat']
	end
	local template = args['template'] and ' in ' .. args['template']  or ''
	if #argpairs > 0 then
		for i, v in ipairs( argpairs ) do
			table.insert(
				warnmsg,
				mw.ustring.format(
					'Using more than one of the following parameters%s: <code>%s</code>.',
					template,
					table.concat(v, '</code>, <code>')
				)
			)
			if cat ~= '' then
				res = res .. '[[' .. cat .. '|' .. (v[1] == '' and ' ' or '') .. v[1] .. ']]'
			end	
		end
	end
	
	if #warnmsg > 0 then
		res = require('Module:If preview')._warning({
			table.concat(warnmsg, '<br>')
		}) .. res
	end
	
	return res
end

return p