Module:Sports table/argcheck
Appearance
![]() | The rating is either invalid or not specified. Please remove the {{Module rating}} template or specify a valid rating. |
Usage
{{#invoke:Sports table/argcheck|function_name}}
local a = {}
local good_args = {
['away_goals_header'] = 1,
['bonus_header'] = 1,
['class_rules'] = 1,
['draw_header'] = 1,
['drawpoints'] = 1,
['for_against_style'] = 1,
['group_header'] = 1,
['hide_played'] = 1,
['highest_pos'] = 1,
['loss_before_draw'] = 1,
['loss_before_tie'] = 1,
['losspoints'] = 1,
['lowest_pos'] = 1,
['matches_style'] = 1,
['matches_text'] = 1,
['match_col_width'] = 1,
['note_header_res'] = 1,
['only_pld_pts'] = 1,
['postitle'] = 1,
['perc_first'] = 1,
['pts_first'] = 1,
['ranking_style'] = 1,
['result_prefix'] = 1,
['rounds_won'] = 1,
['rwpoints'] = 1,
['section'] = 1,
['short_style'] = 1,
['show_GB'] = 1,
['show_away_goals'] = 1,
['show_bonus_points'] = 1,
['show_class_rules'] = 1,
['show_draw'] = 1,
['show_groups'] = 1,
['show_limit'] = 1,
['show_matches'] = 1,
['show_positions'] = 1,
['show_status'] = 1,
['showteam'] = 1,
['sortable_table'] = 1,
['source'] = 1,
['start_date'] = 1,
['stack_footer'] = 1,
['status_order'] = 1,
['status_pos'] = 1,
['style'] = 1,
['team_header'] = 1,
['team_order'] = 1,
['teamwidth'] = 1,
['template_name'] = 1,
['title'] = 1,
['transcludesection'] = 1,
['update'] = 1,
['use_goal_average'] = 1,
['use_goal_diff'] = 1,
['use_goal_percentage'] = 1,
['use_goal_ratio'] = 1,
['use_point_percentage'] = 1,
['use_tie'] = 1,
['winpoints'] = 1
}
local col_names = {
['adjust_points'] = 1,
['away_goals'] = 1,
['draw'] = 1,
['hdraw'] = 1,
['adraw'] = 1,
['loss'] = 1,
['hloss'] = 1,
['aloss'] = 1,
['PKloss'] = 1,
['OTloss'] = 1,
['gf'] = 1,
['hgf'] = 1,
['agf'] = 1,
['ga'] = 1,
['hga'] = 1,
['aga'] = 1,
['group'] = 1,
['pf'] = 1,
['hpf'] = 1,
['apf'] = 1,
['pa'] = 1,
['hpa'] = 1,
['apa'] = 1,
['matches'] = 1,
['pos'] = 1,
['rw'] = 1,
['short'] = 1,
['solid_cell'] = 1,
['startpoints'] = 1,
['status'] = 1,
['win'] = 1,
['hwin'] = 1,
['awin'] = 1,
['PKwin'] = 1,
['OTwin'] = 1,
}
local tracked_styles = {
['football'] = 1,
['WDL'] = 1,
['WL'] = 1,
['WDLHA'] = 1,
['WDL OT'] = 1,
['WDL_OT'] = 1,
['WLHA'] = 1,
['WL OT'] = 1,
['WL_OT'] = 1,
['WL PK'] = 1,
['WL_PK'] = 1
}
function a.check(targs)
local teams = {}
local missing_teams = {}
local results = {}
local missing_results = {}
local orphaned_match_notes = {}
local unknown = {}
if tracked_styles[args['style'] or ''] == nil then
return {}
end
-- Step 1: Generate a team and result list
for k,v in pairs(targs) do
if type(k) == 'string' then
if k:find('^team%d$') then
teams[v] = 1
targs[k] = ''
if targs['name_' .. v] then
-- Great!
targs['name_' .. v] = ''
else
table.insert(missing_teams, v)
end
if targs['note_' .. v] then
targs['note_' .. v] = ''
end
if targs['hth_' .. v] then
targs['hth_' .. v] = ''
end
elseif k:find('^result%d$') then
results[v] = 1
targs[k] = ''
if targs['col_' .. v] or targs['text_' .. v] or targs['note_res_' .. v] then
-- Great!
if targs['col_' .. v] then
targs['col_' .. v] = ''
end
if targs['text_' .. v] then
targs['text_' .. v] = ''
end
if targs['note_res_' .. v] then
targs['note_res_' .. v] = ''
end
else
table.insert(missing_results, v)
end
elseif k:find('^match[%d]*_.*_.*_note$') then
local m = mw.ustring.gsub(k, '^(match[%d]*_.*_.*)_note$', '%1')
targs[k] = ''
if targs[m] then
-- Great!
else
table.insert(orphaned_match_notes, m)
end
end
end
end
for k,v in pairs(targs) do
if v and v~= '' then
found_arg = 0
if type(k) == 'string' then
if found_arg == 0 and (good_args[k] or k:find('^split[^%d][%d]*$')) then
-- Great!
found_arg = 1
end
if found_arg == 0 and k:find('^[A-Za-z]*_.*$') then
local p = mw.ustring.gsub(k, '^([A-Za-z]*)_.*$', '%1')
if col_names[p] then
-- Great!
found_arg = 1
end
end
if found_arg == 0 and k:find('^[A-Za-z]*_[A-Za-z]*_.*$') then
p = mw.ustring.gsub(k, '^([A-Za-z]*_[A-Za-z]*)_.*$', '%1')
if col_names[p] then
-- Great!
found_arg = 1
end
end
if found_arg == 0 and k:find('^match[%d]*_.*_.*$') then
local t1 = mw.ustring.gsub(k, '^match[%d]*_(.*)_(.*)$', '%1')
local t2 = mw.ustring.gsub(k, '^match[%d]*_(.*)_(.*)$', '%2')
found_arg = 1
if teams[t1] == nil or teams[t2] == nil then
if teams[t1] == nil then
table.insert(missing_teams, t1)
end
if teams[t2] == nil then
table.insert(missing_teams, t2)
end
end
end
if found_arg == 0 and k:find('^result_.*_.*$') then
local t1 = mw.ustring.gsub(k, '^result[%d]*_(.*)_(.*)$', '%1')
local t2 = mw.ustring.gsub(k, '^result[%d]*_(.*)_(.*)$', '%2')
found_arg = 1
if teams[t1] == nil or teams[t2] == nil then
if teams[t1] == nil then
table.insert(missing_teams, t1)
end
if teams[t2] == nil then
table.insert(missing_teams, t2)
end
end
end
end
if found_arg == 0 then
table.insert(unknown, k)
end
end
end
local res = {}
for k,v in ipairs(unknown) do
v = mw.ustring.gsub('[^A-Za-z0-9_ ]', '?')
if v == '' then v = ' ' end
table.insert(res, '[[Category:Pages using sports table with unknown parameters|' .. v .. ']]')
end
for k,v in ipairs(missing_teams) do
v = mw.ustring.gsub('[^A-Za-z0-9_ ]', '?')
if v == '' then v = ' ' end
table.insert(res, '[[Category:Pages using sports table with missing teams|' .. v .. ']]')
end
for k,v in ipairs(missing_results) do
v = mw.ustring.gsub('[^A-Za-z0-9_ ]', '?')
if v == '' then v = ' ' end
table.insert(res, '[[Category:Pages using sports table with missing results|' .. v .. ']]')
end
for k,v in ipairs(orphaned_notes) do
v = mw.ustring.gsub('[^A-Za-z0-9_ ]', '?')
if v == '' then v = ' ' end
table.insert(res, '[[Category:Pages using sports table with orphaned notes|' .. v .. ']]')
end
for k,v in ipairs(orphaned_match_notes) do
v = mw.ustring.gsub('[^A-Za-z0-9_ ]', '?')
if v == '' then v = ' ' end
table.insert(res, '[[Category:Pages using sports table with orphaned match notes|' .. v .. ']]')
end
return res
end
return a