יחידה:ParamValidator: הבדלים בין גרסאות בדף

יותר מדויק
כמקובל
שורה 169: שורה 169:
-- if second parameter is nil, only tempalte page will be searched for templatedata.
-- if second parameter is nil, only tempalte page will be searched for templatedata.
function calculateViolations( frame, subpages )
function calculateViolations( frame, subpages )
-- used for parameter type validy test. keyed by TD 'type' string. values are function(val) returning bool.
-- used for parameter type validy test. keyed by TD 'type' string. values are function(val) returning bool.
local type_validators = {  
local type_validators = {  
שורה 199: שורה 198:
-- handle undeclared and deprecated
-- handle undeclared and deprecated
local already_seen = {}
local already_seen = {}
local series = frame.args['series']
for p_name, value in pairs( t_args ) do
for p_name, value in pairs( t_args ) do
local tp_param, noval, numeric, table_name = td_params[p_name] or all_aliases[p_name], util.empty( value ), tonumber( p_name )
local tp_param, noval, numeric, table_name = td_params[p_name] or all_aliases[p_name], util.empty( value ), tonumber( p_name )
local hasval = not noval
local hasval = not noval


if not tp_param and frame.args['series'] then -- 2nd chance. check to see if series
if not tp_param and series then -- 2nd chance. check to see if series
for s_name, p in pairs(td_params) do  
for s_name, p in pairs(td_params) do  
if mw.ustring.match( p_name, '^' .. s_name .. '%d+' .. '$') then td_param = p end -- don't bother breaking. td always correct.
if mw.ustring.match( p_name, '^' .. s_name .. '%d+' .. '$') then  
-- mw.log('found p_name '.. p_name .. '  s_name:' .. s_name, ' p is:', p) debugging series support
tp_param = p  
end -- don't bother breaking. td always correct.
end
end
end
end
שורה 220: שורה 223:
or tp_param.deprecated and noval and 'empty-deprecated'  
or tp_param.deprecated and noval and 'empty-deprecated'  
or not compatible( tp_param.type, value ) and 'incompatible'  
or not compatible( tp_param.type, value ) and 'incompatible'  
or already_seen[tp_param] and hasval and 'duplicate'
or not series and already_seen[tp_param] and hasval and 'duplicate'
already_seen[tp_param] = hasval
already_seen[tp_param] = hasval