Module:Sandbox/ProcrastinatingReader/three: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
 
(16 intermediate revisions by the same user not shown)
Line 209:
for x, p in pairs( td_params ) do for y, alias in ipairs( p.aliases or {} ) do
p['primary'] = x
td_params[x] = p
all_aliases[alias] = p
if tonumber(alias) then all_aliases[tonumber(alias)] = p end
end end
 
mw.logObject(all_aliases)
-- handle undeclared and deprecated
local already_seen = {}
Line 254 ⟶ 253:
if table_name == 'duplicate' then
local primary_param = tp_param['primary']
local primaryData = res[table_name][primary_param] or {}
if not primaryData then
primaryData = {}
table.insert(primaryData, already_seen[tp_param])
end
table.insert(primaryData, p_name)
res[table_name][primary_param] = primaryData
Line 272 ⟶ 275:
res['empty-required'][p_name] = ''
end
end
end
-- add the first usage of alias to 'duplicate params'
if res['duplicate'] then
for _, alias in ipairs( alreadyseen ) do
is_alias = is_alias or not util.empty( t_args[alias] )
end
end
Line 315 ⟶ 311:
end
 
local replace_macros = function( error_type, s, param_names )
function concat_and_escape( t ), sep )
local ssep = table.concat(sep t,or ', ' )
local s = table.concat( t, sep )
return ( mw.ustring.gsub( s, '%%', '%%%%' ) )
end
Line 325 ⟶ 322:
for k, v in pairs( param_names ) do
table.insert( k_ar, k )
table.insertif type(v) kv_ar, k ..== ': table' .. v)then
v = table.concat(v, ', ')
end
if res[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, 'paramname', concat_and_escape( k_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 338 ⟶ 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 '' )