Content deleted Content added
copy parameter validation |
No edit summary |
||
(21 intermediate revisions by the same user not shown) | |||
Line 208:
-- allow for aliases
for x, p in pairs( td_params ) do for y, alias in ipairs( p.aliases or {} ) do
td_params[x] = p
all_aliases[alias] = p
if tonumber(alias) then all_aliases[tonumber(alias)] = p end
end end
-- handle undeclared and deprecated
local already_seen = {}
Line 241 ⟶ 240:
table_name = tp_param.deprecated and hasval and 'deprecated'
or tp_param.deprecated and noval and 'empty-deprecated'
or not compatible( tp_param.type, value ) and 'incompatible'
or not series and already_seen[tp_param] and hasval and 'duplicate'
if hasval and table_name ~= 'duplicate' then
already_seen[tp_param] =
end
end
Line 250 ⟶ 251:
if table_name then
res[table_name] = res[table_name] or {}
local primary_param = tp_param['primary']
local primaryData = res[table_name][primary_param]
if not primaryData then
primaryData = {}
table.insert(primaryData, already_seen[tp_param])
end
table.insert(primaryData, p_name)
res[table_name][primary_param] = primaryData
else
res[table_name][p_name] = value
end
end
end
--
for p_name, param in pairs( td_params ) do
if param.required and util.empty( t_args[p_name] ) then
Line 300 ⟶ 311:
end
local replace_macros = function( error_type, s, param_names )
function concat_and_escape( t
local s = table.concat( t, sep )
return ( mw.ustring.gsub( s, '%%', '%%%%' ) )
end
Line 310 ⟶ 322:
for k, v in pairs( param_names ) do
table.insert( k_ar, k )
v = table.concat(v, ', ')
end
if error_type == 'duplicate' then
table.insert( kv_ar, v)
else
table.insert( kv_ar, k .. ': ' .. v)
end
end
s = mw.ustring.gsub( s, 'paramname', concat_and_escape( k_ar ) ) ▼
s = mw.ustring.gsub( s, 'paramandvalue', concat_and_escape( kv_ar ) )▼
▲ s = mw.ustring.gsub( s, 'paramandvalue', concat_and_escape( kv_ar, ' AND ' ) )
if mw.getCurrentFrame():preprocess( "{{REVISIONID}}" ) ~= "" then
s = mw.ustring.gsub( s, "<div.*<%/div>", "", 1 )
Line 323 ⟶ 344:
local report_params = function( key, param_names )
local res = replace_macros( key, options[key], param_names )
res = frame:preprocess(res or '')
report = report .. ( res or '' )
|