-- Module to build tables for standings in Sports-- See documentation for details
require('strict')
local p =
-- Helper functionslocal function isnotblank(s) return s and s:match('^%s*(.-)%s*$') ~= end
local function firstnonblank(s1,s2) if (s1 and s1:match('^%s*(.-)%s*$') ~= ) then return s1 elseif (s2 and s2:match('^%s*(.-)%s*$') ~= ) then return s2 end return nilend -- Main functionfunction p.main(frame) -- Declare locals local Args = frame.args local Pargs = frame:getParent.args local ii_start, ii_end, N_rows_res = 0 local text_field_result local notes_exist = false local t = local t_footer = local t_return = local team_list = local jj, jjj -- Exit early if we are using section transclusion for a different section if(isnotblank(Pargs['transcludesection']) and isnotblank(Args['section'])) then if(Pargs['transcludesection'] ~= Args['section']) then return end end
-- Get the custom start point for the table (most will start by default at 1 local top_pos = tonumber(Args['highest_pos']) or 1 local N_teams = top_pos - 1 -- Default to 0 at start, but higher number needed to skip certain entries -- Load modules local yesno = require('Module:Yesno') -- Load style and (sub) modules local style_def = Args['style'] or 'WLT' -- Historically 'football' exists as style, this is now forwarded to WDL if style_def
'no_hide_class_rules' then full_table = true hide_class_rules = true else full_table = true end -- Show groups or note local show_groups_val = firstnonblank(Pargs['show_groups'], Args['show_groups']) or 'no' local group_col = false if yesno(show_groups_val) then group_col = true end -- Show match_table or not local show_matches_val = firstnonblank(Pargs['show_matches'], Args['show_matches']) or 'no' local match_table = false if yesno(show_matches_val) then match_table = true end -- Custom position column label or note local pos_label = Args['postitle'] or if pos_label
-- Get VTE button text (but only for non-empty text) local template_name = Args['template_name'] or local VTE_text = if template_name~= then VTE_text = frame:expandTemplate end
-- Write column headers t_return = p_style.header(t,Args,p_sub,pos_label,group_col,VTE_text,full_table,results_header_txt) if match_table then -- Add empty column header t_return.count = t_return.count+1 table.insert(t_return.tab_text,'! scope="row" class="unsortable" style="background-color:white;border-top:white;border-bottom:white;line-width:3pt;"| \n') -- Add rest of header t_return = p_matches.header(t_return,Args,p_sub,N_teams,team_list) end t = t_return.tab_text local N_cols = t_return.count -- Determine what entries go into table -- Find out which team to show (if any) local ii_show = team_list[firstnonblank(Pargs['showteam'], Args['showteam'])] -- nil if non-existant -- Start and end positions to show local n_to_show = tonumber(Args['show_limit']) or N_teams -- Check for "legal value", if not legal (or non declared), then show all local check_n = ((n_to_show>=(N_teams-top_pos+1)) or (n_to_show<=1) or (n_to_show~=math.floor(n_to_show))) -- Also check whether there is a valid ii_show if check_n or (not ii_show) then ii_start = top_pos ii_end = N_teams else -- It's a proper integer between top_pos+1 and N_teams-1 -- If it is in the middle show the same number above and below -- If it is in the top or bottom, show the exact number -- How many to show on the side local n_show_side = math.floor(n_to_show/2) if (ii_show-top_pos+1)<=n_show_side then -- Top team ii_start = top_pos ii_end = top_pos+n_to_show-1 elseif ii_show>=(N_teams+1-n_show_side) then -- Bottom team ii_start = N_teams+1-n_to_show ii_end = N_teams else -- Normal case ii_start = ii_show-n_show_side ii_end = ii_show+n_show_side end end -- For results column local new_res_ii = ii_start -- Pre-check for existence of column for ii = ii_start, ii_end do if Args['result'..ii] then results_defined = true end end -- Remove results header if it is unused if full_table and not results_defined then -- First get it as one string, then use string replace to replace that header by empty string local t_str = tostring(table.concat(t)) t_str = mw.ustring.gsub(t_str, results_header_txt, ) N_cols = N_cols-1 -- There is actually one column less t = table.insert(t, t_str) end -- Write rows local team_name, team_code_ii, team_code_jj, pos_num, group_txt, note_local local note_string, note_local, note_local_num, note_id local note_id_list = local hth_id_list = for ii = ii_start, ii_end do -- First get code team_code_ii = team_list[ii] -- Now read values pos_num = Args['pos_'..team_code_ii] or ii group_txt = Args['group_'..team_code_ii] or ' ' team_name = Args['name_'..team_code_ii] or team_code_ii note_local = Args['note_'..team_code_ii] or nil -- Does it need a promotion/qualification/relegation tag local result_local = Args['result'..ii] or nil local bg_col = nil -- Get local background colour if result_local then bg_col = result_col[Args['col_'..result_local]] or Args['col_'..result_local] or 'white' bg_col = 'background-color:'..bg_col..';' -- Full style tag end if not bg_col then bg_col = 'background-color:transparent;' end -- Becomes default if undefined -- Bold this line or not local ii_fw = ii
'before' then status_string = '
'..string.lower(status_string)..' - ' else status_string = ' ('..status_string..')' end end end -- Now build the rows table.insert(t,'|- \n') -- New row table.insert(t,'! scope="row" style="text-align: center;'..ii_fw..bg_col..'"| '..pos_num..'\n') -- Position number if full_table and group_col then table.insert(t,'| style="'..ii_fw..bg_col..'" |'..group_txt..'\n') -- Group number/name end -- Build the team string order based on status position local team_string if t_status.positionnew_res_ii then -- First check how many rows you need for this N_rows_res = 1 jjj = ii+1 result_local = Args['result'..ii] or local cont_loop = true while (jjj<=ii_end) and cont_loop do if Args['split'..tostring(jjj-1)] then cont_loop = false new_res_ii = jjj else res_jjj = Args['result'..jjj] or if result_local
jj then -- Nothing else local match_note = Args['match_'..team_code_ii..'_'..team_code_jj..'_note'] if match_note then notes_exist = true -- Only when it exist -- First check for existence of reference for note if not Args['note_'..match_note] then -- It's the entry note_string = frame:expandTemplate else -- Check for existence elsewhere note_local_num = team_list[match_note] if note_id_list[match_note] or ((note_local_num >= ii_start) and (note_local_num <= ii_end)) then -- It exists note_id = '"table_note_'..match_note..rand_val..'"' -- Identifier note_string = frame:extensionTag else -- Now define the identifier for this note_id = '"table_note_'..match_note..rand_val..'"' -- Add random end for unique ID note_id_list[match_note] = note_id -- Call refn template note_string = frame:expandTemplate end end
-- Now append this to the match result string Args['match_'..team_code_ii..'_'..team_code_jj] = Args['match_'..team_code_ii..'_'..team_code_jj]..note_string end end end -- Add rest of match row t = p_matches.row(t,Args,N_teams,team_list,ii,ii_show) end -- Now, if needed, insert a split (solid line to indicate split in standings, but only when it is not at the last shown position) if Args['split'..ii] and (ii then -- Empty parameter table.insert(t_footer,'Updated to '..matches_text..' played on unknown. ') elseif string.lower(update) 'complete')) then table.insert(t_footer,stack_string) end table.insert(t_footer,'Source: '..source) if class_rules and full_table and (not hide_class_rules) then table.insert(t_footer,' '..table.concat(t_footer)..' ' t_footer = t_footer..frame:expandTemplate else -- As reflist size text t_footer = ' '..table.concat(t_footer)..' ' end -- Add footer to main text table table.insert(t,t_footer) return table.concat(t)end return p'complete' then -- Do nothing elseif update
'future' then -- Future start date table.insert(t_footer,'First '..matches_text..' will be played on '..start_date..'. ') else table.insert(t_footer,'Updated to '..matches_text..' played on '..update..'. ') end -- Stack footer or not local stack_footer_val = firstnonblank(Pargs['stack_footer'], Args['stack_footer']) or 'no' local footer_break = false if yesno(stack_footer_val) then footer_break = true end -- Variable for linebreak local stack_string = '
' if footer_break and (not (string.lower(update)
Rules for classification: '..class_rules) end -- Now for the named status local status_exist = false local status_string = local curr_letter for jjj = 1,mw.ustring.len(t_status.letters) do curr_letter = mw.ustring.upper(mw.ustring.sub(t_status.letters,jjj,jjj)) if t_status.called[curr_letter] then if (footer_break and status_exist) then status_string = status_string..stack_string end if t_status.position 'before' then status_string = status_string..'
'..string.lower(curr_letter)..' - '..t_status.code[curr_letter]..'; ' else status_string = status_string..'('..curr_letter..') '..t_status.code[curr_letter]..'; ' end status_exist = true end end -- Now end it with a point instead (if it contains entries the '; ' needs to be removed) if status_exist then status_string = '
'..mw.ustring.sub(status_string,1,mw.ustring.len(status_string)-2)..'.' table.insert(t_footer,status_string) end -- Add notes (if applicable) if notes_exist then table.insert(t_footer,'
Notes:') -- As reflist size text t_footer = '