---- This module checks whether any of a given set of input criteria are valid CSD criteria.-- It is also possible to specify pre-defined or custom sets of CSD criteria to check against.--
local p =
function critMatch(s,test_values) -- returns true if s matches one of the table of test_values if type(test_values)
value then return true end end else error("the second parameter passed to critMatch must be a table",2) endend
function p.check(frame) -- the main CSD check function
-- get arguments local args; if frame
-- define variables local input_values = ; local test_criteria = ; local all_criteria = ; local tag_criteria = ; local notice_criteria = ;
-- build tables of input values and test criteria for k,v in pairs(args) do v = mw.ustring.upper(v);
-- insert positional parameter values into input_values if type(k)
-- insert critn parameter values into test_criteria elseif mw.ustring.match(k,"^crit[1-9]%d*$") then if critMatch(v,all_criteria) then -- check to make sure the criteria are valid table.insert(test_criteria,v) end end end
-- work out which set of CSD criteria to check against local criteria_set = if next(test_criteria) then -- if any test criteria are specified, use those regardless of the "set" parameter criteria_set = test_criteria; elseif args["set"]
"notice" then criteria_set = notice_criteria; else criteria_set = all_criteria; end
-- check the input values against the criteria set and output "yes" if there is a match for i,v in ipairs(input_values) do if critMatch(v,criteria_set) then return "yes" end endend
return p