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