Module:Sports table/argcheck/sandbox explained
local a =
local categories =
local good_args =
local good_args_HA =
local good_args_PKOT =
local good_args_BDT =
local good_args_VB =
local ignored_args =
local col_names =
local col_names_HA =
local col_names_PKOT =
local col_names_BDT =
local col_names_VB =
local tracked_styles =
local warn = local track =
local function get_tracking_category(category, value) return '' .. value .. ''end
local function validate_table_values(args, category, bad_char, is_track) for _, v in ipairs(args) do v = mw.ustring.gsub(v, bad_char, '?') if v
then v = ' ' end if is_track then table.insert(track, get_tracking_category(category, v)) else table.insert(warn, get_tracking_category(category, v)) end endend
function a.check(targs, pargs) local teams = local missing_teams = local results = local missing_results = local orphaned_match_notes = local orphaned_results = local orphaned_names = local orphaned_notes = local ignored = local possibly_ignored = local unknown = local mstyle = mw.ustring.gsub(targs['style'] or , '[%s_]+', ' ') mstyle = tracked_styles[mstyle] if mstyle
nil then return warn, track elseif mstyle
'HA' then for k, v in pairs(good_args_HA) do good_args[k] = v ~= 0 and v or nil end for k, v in pairs(col_names_HA) do col_names[k] = v ~= 0 and v or nil end if targs['only_fa_totals'] then col_names['pf'] = 1 col_names['gf'] = 1 col_names['pa'] = 1 col_names['ga'] = 1 end elseif mstyle
'PKOT' then for k, v in pairs(good_args_PKOT) do good_args[k] = v ~= 0 and v or nil end for k, v in pairs(col_names_PKOT) do col_names[k] = v ~= 0 and v or nil end elseif mstyle
'BDT' then for k, v in pairs(good_args_BDT) do good_args[k] = v ~= 0 and v or nil end for k, v in pairs(col_names_BDT) do col_names[k] = v ~= 0 and v or nil end elseif mstyle
'VB' then for k, v in pairs(good_args_VB) do good_args[k] = v ~= 0 and v or nil end for k, v in pairs(col_names_VB) do col_names[k] = v ~= 0 and v or nil end end -- Alternative syntax for team list if targs['team_order'] and targs['team_order'] ~= then local tlist = mw.text.split(targs['team_order'], '%s*[;,]%s*') for k, tname in ipairs(tlist) do if tname ~= then targs['team' .. k] = tname end end end -- Limited tracking if we are only showing part of the table if targs['showteam'] then local top_pos = tonumber(targs['highest_pos']) or 1 local bottom_pos = tonumber(targs['lowest_pos']) or 0 local N = top_pos - 1 while targs['team' .. N + 1] ~= nil and (bottom_pos < top_pos or N < bottom_pos) do N = N + 1 teams[targs['team' .. N]] = 1 if teams[targs['showteam']] then return warn, track end end 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 local multiref = 1 local hth_local_table = mw.text.split(targs['hth_' .. v], '%s*,%s*') if (#hth_local_table > 1) then for _, hth_loc in ipairs(hth_local_table) do multiref = multiref * (targs['hth_' .. hth_loc] and 1 or 0) end else multiref = 0 end if multiref > 0 then for _, hth_loc in ipairs(hth_local_table) do targs['hth_' .. hth_loc] = end elseif targs['hth_' .. targs['hth_' .. v]] then targs['hth_' .. targs['hth_' .. v]] = end targs['hth_' .. v] = end elseif k:find('^result%d+$') or k:find('^.*_result%d+$') then local pre = mw.ustring.gsub(k, '^(.*)result%d+$', '%1') results[v] = 1 targs[k] = if targs[pre .. 'col_' .. v] or targs[pre .. 'text_' .. v] or targs[pre .. 'note_res_' .. v] then -- Great! if targs[pre .. 'col_' .. v] then targs[pre .. 'col_' .. v] = end if targs[pre .. 'text_' .. v] then targs[pre .. 'text_' .. v] = end if targs[pre .. 'note_res_' .. v] then local multiref = 1 local note_res_local_table = mw.text.split(targs[pre .. 'note_res_' .. v], '%s*,%s*') if (#note_res_local_table > 1) then for _, note_res_loc in ipairs(note_res_local_table) do multiref = multiref * (targs[pre .. 'note_res_' .. note_res_loc] and 1 or 0) end else multiref = 0 end if multiref > 0 then for _, note_res_loc in ipairs(note_res_local_table) do targs[pre .. 'note_res_' .. note_res_loc] = end elseif targs[pre .. 'note_res_' .. targs[pre .. 'note_res_' .. v]] then targs[pre .. 'note_res_' .. targs[pre .. 'note_res_' .. v]] = end targs[pre .. 'note_res_' .. v] = end if targs[pre .. 'res_col_header'] then targs[pre .. 'res_col_header'] = 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 if targs['note_' .. v] then targs['note_' .. v] = end -- Great! else table.insert(orphaned_match_notes, m) end end end end
local possible_missing_winpoints = 0 for k,v in pairs(targs) do if v and v ~= then if type(k)
'string' then if k:find('^adjust_points_') then local p = mw.ustring.gsub(k, '^adjust_points_', ) if (tonumber(v) or 0) ~= 0 then local pdiff = (tonumber(targs['win_' .. p] or 0) or 0) + tonumber(v) if pdiff
0 then possible_missing_winpoints = possible_missing_winpoints + 1 else possible_missing_winpoints = possible_missing_winpoints - 1 end end end if (good_args[k] or k:find('^split[%d]+$')) then -- Great! elseif k
'showteam' then -- Great! if teams[v] ~= 1 then table.insert(missing_teams, v) end elseif (ignored_args[k] or k:find('^att_')) then table.insert(ignored, k) elseif col_names[mw.ustring.gsub(k, '^([A-Za-z3-5]*)_.*$', '%1')] then -- Great! elseif col_names[mw.ustring.gsub(k, '^([A-Za-z3-5]*)_.*$', '%1')] then -- Great! elseif k:find('^match[%d]*_.*_.*$') then local t1 = mw.ustring.gsub(k, '^match[%d]*_(.*)_(.*)$', '%1') local t2 = mw.ustring.gsub(k, '^match[%d]*_(.*)_(.*)$', '%2') if teams[t1]
nil then table.insert(missing_teams, t1) end if teams[t2]
nil then table.insert(missing_teams, t2) end elseif k:find('^result_.*_.*$') then local t1 = mw.ustring.gsub(k, '^result[%d]*_(.*)_(.*)$', '%1') local t2 = mw.ustring.gsub(k, '^result[%d]*_(.*)_(.*)$', '%2') if teams[t1]
nil then table.insert(missing_teams, t1) end if teams[t2]
nil then table.insert(missing_teams, t2) end elseif (k:find('^name_') or k:find('^short_')) then table.insert(orphaned_names, k) elseif (k:find('^note_') or k:find('^hth_')) then if (k
'hth_ABC' and v
'H2H note') then table.insert(warn, get_tracking_category(categories.ignored_parameters, 'hth_ABC')) elseif (k
'note_ABC' and v
'Team note') then table.insert(warn, get_tracking_category(categories.ignored_parameters, 'note_ABC')) elseif (k
'note_res_AAA' and v
'Result note') then table.insert(warn, get_tracking_category(categories.ignored_parameters, 'note_res_AAA')) else table.insert(orphaned_notes, k) end elseif (k:find('^col_') or k:find('^text_')) then table.insert(orphaned_results, k) elseif pargs[k] and pargs[k] ~= then if tonumber(k) then k = k .. ' = ' .. v end table.insert(possibly_ignored, k) else if tonumber(k) then k = k .. ' = ' .. v end table.insert(unknown, k) end end end end
local bad_char = '[^A-Za-z0-9_%(%)%- ]' validate_table_values(unknown, categories.unknown_parameters, bad_char, false) validate_table_values(missing_teams, categories.missing_teams, bad_char, false) validate_table_values(missing_results, categories.missing_results, bad_char, false) validate_table_values(orphaned_results, categories.orphaned_results, bad_char, false) validate_table_values(orphaned_names, categories.orphaned_names, '[^A-Za-z0-9_ ]', false) validate_table_values(orphaned_notes, categories.orphaned_notes, bad_char, false) validate_table_values(orphaned_match_notes, categories.orphaned_match_notes, bad_char, false) validate_table_values(ignored, categories.ignored_parameters, bad_char, false) validate_table_values(possibly_ignored, categories.possibly_ignored_parameters, bad_char, true)
if possible_missing_winpoints > 1 then table.insert(track, get_tracking_category(categories.possible_incorrect_winpoints, possible_missing_winpoints)) end return warn, trackend
return a