Module:Sports table: Difference between revisions

Content deleted Content added
m matches → match(es)
fix text color in dark mode; this generally works but may cause problems, in which case revert or try specifying a different CSS value
 
(141 intermediate revisions by 10 users not shown)
Line 2:
-- See documentation for details
 
require('Module:No globalsstrict')
 
local p = {}
 
-- Main function
function p.main(frame)
-- Declare locals
local ArgsgetArgs = framerequire('Module:Arguments').argsgetArgs
local N_teams,Args ii_start,= ii_endgetArgs(frame, N_rows_res{parentFirst = 0true})
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
local table_anchor = mw.ustring.gsub(Args['section'] and 'sports-table-' .. Args['section'] or '', ' ', '_')
-- Exit early if we are using section transclusion for a different section
local tsection = frame:getParent().args['transcludesection'] or frame:getParent().args['section'] or ''
local bsection = frame.args['section'] or ''
if( tsection ~= '' and bsection ~= '' ) then
if( tsection ~= bsection ) then
return ''
end
end
 
local templatestyles = frame:extensionTag{
name = 'templatestyles', args = { src = 'Module:Sports table/styles.css' }
}
-- Edit links if requested
local baselink = frame:getParent():getTitle()
if baselink == 'Module:Excerpt' then baselink = '' end
if mw.title.getCurrentTitle().fullText == baselink then baselink = '' end
local template_name = (baselink ~= '' and (':' .. baselink .. (table_anchor ~= '' and '#' .. table_anchor or '')))
or ''
 
-- Get the custom start point for the table (most will start by default at 1)
local top_pos = tonumber(Args['highest_pos']) or 1
-- Get the custom end point for the table (unrestricted if bottom_pos is < top_pos)
local bottom_pos = tonumber(Args['lowest_pos']) or 0
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 'WDL'
-- Historically 'football' exists as style, this is now forwarded to WDL
if style_def == 'football' then style_def = 'WDL' end
local p_style = require('Module:Sports table/'..style_def)
local p_sub = require('Module:Sports table/sub')
-- Random value used for uniqueness
Line 24 ⟶ 62:
-- Declare colour scheme
local result_col = {}
result_col = {green1='#CCFFCCBBF3BB', green2='#E6FFE6CCF9CC', green3='#F3FFF3DDFCDD', green4='#F9FFF9EEFFEE',
blue1='#CCCCFFBBF3FF', blue2='#E6E6FFCCF9FF', blue3='#F3F3FFDDFCFF', blue4='#F9F9FFEEFFFF',
yellow1='#FFFFCCFFFFBB', yellow2='#FFFFE6FFFFCC', yellow3='#FFFFF3FFFFDD', yellow4='#FFFFF9FFFFEE',
red1='#FFCCCCFFBBBB', red2='#FFE6E6FFCCCC', red3='#FFF3F3FFDDDD', red4='#FFF9F9FFEEEE',
black1='#CCCCCCBBBBBB', black2='#E6E6E6CCCCCC', black3='#F3F3F3DDDDDD', black4='#F9F9F9EEEEEE'},
orange1='#FEDCBA', orange2='#FEEAD5',
white1='inherit',['']='inherit'
}
-- Show all stats in table or just matches played and points
local full_table = true
local hide_results = yesno(Args['hide_results'] or 'no')
local hide_footer = yesno(Args['hide_footer'] or 'no')
local pld_pts_val = string.lower(Args['only_pld_pts'] or 'no')
local show_class_rules = yesno(Args['show_class_rules'] or 'yes') and true or false
-- True if par doesn't exist, false otherwise
if yesno(pld_pts_val) then
full_table = false
elseif pld_pts_val=='no_hide_class_rules' then
full_table = true
show_class_rules = false
end
-- Declare results column header
Line 34 ⟶ 89:
results_header = {Q='Qualification', QR='Qualification or relegation',
P='Promotion', PQR='Promotion, qualification or relegation',
PR='Promotion or relegation', RPQ='RelegationPromotion or qualification'},
R='Relegation'}
local results_defined = false -- Check whether this would be needed
-- Possible prefix for result fields
local respre = (Args['result_prefix'] or '') .. '_'
respre = (respre == '_') and '' or respre
-- Now define line for column header (either option or custom)
local local_res_header = results_header[Args[respre..'res_col_header']] or Args[respre..'res_col_header'] or ''
-- Check whether it includes a note
local res_head_note = Args['note_header_res']
local res_head_note_text = ''
if full_table and res_head_note then
notes_exist = true
res_head_note_text = frame:expandTemplate{ title = 'efn', args = { group='Table_noteslower-alpha', res_head_note} }
end
local results_header_txt = '! scope="col" |'..local_res_header..res_head_note_text..'\n'
-- DeclareGet status optionsoption
local t_status = p_style.status(Args)
local status_code, status_called = {}
-- ------------------------------------------------------------
-- Alternative syntax for team list
-- NOTE: If you add to status_code, also add to status_called and status_letters!!
if Args['team_order'] and Args['team_order'] ~= '' then
-- Or functionality will be compromised
local team_order_offset = (tonumber(Args['team_order_start']) or 1) - 1
-- ------------------------------------------------------------
local tlist = mw.text.split(Args['team_order'], '%s*[;,]%s*')
status_code = { A='Advances to a further round', C='Champion', D='Disqualified',
for k, tname in ipairs(tlist) do
E='Eliminated', H='Group host', O='Play-off winner', P='Promoted', Q='Qualified to the phase indicated',
if tname ~= '' then
R='Relegated', T='Qualified, but not yet to the particular phase indicated'}
Args['team' .. (k + team_order_offset)] = tname
status_called = { A=false, C=false, D=false, E=false, H=false, O=false, P=false,
end
Q=false, R=false, T=false}
end
local status_letters = 'ACDEHOPQRT'
end
-- Read in number of consecutive teams (ignore entries after skipping a spot)
while Args['team'..N_teams+1] ~= nil and (bottom_pos < top_pos or N_teams < bottom_pos) do
N_teams = N_teams+1
-- Sneakily add it twice to the team_list parameter, once for the actual
Line 69 ⟶ 129:
team_list[Args['team'..N_teams]] = N_teams -- team X entry is position i
end
 
-- Optional totals
local total_row_name = 'SPORTS_TABLE_TOTAL'
if yesno(Args['show_totals'] or 'no') then
N_teams = N_teams+1
Args['team' .. N_teams] = total_row_name
Args['name_' .. total_row_name] = 'Total'
Args['result' .. N_teams] = total_row_name
Args['col_' .. total_row_name] = '#eee'
team_list[N_teams] = Args['team' .. N_teams]
team_list[Args['team'..N_teams]] = N_teams
end
 
-- Show position
local position_col = yesno(Args['show_positions'] or 'yes') and true or false
-- Show groups or note
local group_col = yesno(Args['show_groups'] or 'no') and true or false
 
-- Show match_table or not
local match_table = yesno(Args['show_matches'] or 'no') and true or false
local p_matches = match_table and
(style_def == 'Chess' and require('Module:Sports results/'..style_def) or require('Module:Sports results'))
-- Show all stats in table or just matches played and points
local full_table = not Args['only_pld_pts'] -- True if par doesn't exist, false otherwise
-- Custom position column label or note
local pos_label = Args['postitle'] or '<abbr title="Position">Pos</abbr>'
if pos_labelposition_col == ''false then pos_label = nil end
-- If empty (or undeclared) then default
-- Show status or not
pos_label = '<abbr title="Position">Pos</abbr>'
local show_status = yesno(Args['show_status'] or 'yes') and true or false
end
 
-- Get VTE button text (but only for non-empty text)
local template_name = Args['template_name']
local VTE_text = ''
if (template_name ~= '') then
VTE_text = require('Module:Navbar')._navbar({
VTE_text = frame:expandTemplate{ title = 'navbar', args = { mini=1, style='float:right', template_name} }
template_name,
mini=1,
style='float:right',
brackets=1
})
-- remove the next part if https://en.wikipedia.org/w/index.php?oldid=832717047#Sortable_link_disables_navbar_links?
-- is ever fixed
if yesno(Args['sortable_table'] or 'no') then
VTE_text = mw.ustring.gsub(VTE_text, '<%/?abbr[^<>]*>', ' ')
end
end
-- Add source to title if specified and possible
local title_source = false
if Args['title'] and Args['title_source'] then
Args['title'] = Args['title'] .. Args['title_source']
title_source = true
elseif Args['table_header'] and Args['table_header_source'] then
Args['table_header'] = Args['table_header'] .. Args['table_header_source']
title_source = true
end
 
-- WriteAdd columna headerstable anchor
if table_anchor ~= '' then
local team_width = Args['teamwidth'] or '190'
table.insert(t, '{|<span class="wikitableanchor" styleid="text-align:center;' .. table_anchor .. '"></span>\n') -- Open table
table.insert(t,'! scope="col" width=28|'..pos_label..'\n') -- Position col
table.insert(t,'! scope="col" width='..team_width..'|Team'..VTE_text..'\n') -- Team col
table.insert(t,'! scope="col" width=28|<abbr title="Played">Pld</abbr>\n') -- Matches played col
if full_table then
table.insert(t,'! scope="col" width=28|<abbr title="Won">W</abbr>\n') -- Win col
table.insert(t,'! scope="col" width=28|<abbr title="Drawn">D</abbr>\n') -- Draw col
table.insert(t,'! scope="col" width=28|<abbr title="Lost">L</abbr>\n') -- Loss col
table.insert(t,'! scope="col" width=28|<abbr title="Goals for">GF</abbr>\n') -- Goal for col
table.insert(t,'! scope="col" width=28|<abbr title="Goals against">GA</abbr>\n') -- Goal against col
table.insert(t,'! scope="col" width=28|<abbr title="Goal difference">GD</abbr>\n') -- Goal difference col
end
 
table.insert(t,'! scope="col" width=28|<abbr title="Points">Pts</abbr>\n') -- Points col
-- Write column headers
if full_table then
t_return = p_style.header(t,Args,p_sub,pos_label,group_col,VTE_text,full_table,results_header_txt)
table.insert(t,results_header_txt) -- Result col
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;color:black;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,tonumber(Args['legs']) or 1)
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[Args['showteam'] or nil] -- 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 = 1top_pos
ii_end = N_teams
else
-- It's a proper integer between 2top_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 = 1top_pos
ii_end = top_pos+n_to_show-1
elseif ii_show>=(N_teams+1-n_show_side) then
-- Bottom team
Line 137 ⟶ 237:
end
-- Get custom options for in table
local win_points = tonumber(Args['winpoints']) or 3
local draw_points = tonumber(Args['drawpoints']) or 1
local loss_points = tonumber(Args['losspoints']) or 0
-- For results column
local new_res_ii = ii_start
-- Pre-check for existence of column
if not hide_results then
for ii = ii_start, ii_end do
for ii = ii_start, ii_end do
if Args['result'..ii] then results_defined = true end
if Args[respre..'result'..ii] and Args[respre..'text_' .. Args[respre..'result'..ii]] then results_defined = true end
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 hth_string, hth_local, hth_local_num, hth_id
local note_id_list = {}
local hth_id_list = {}
Line 159 ⟶ 264:
team_code_ii = team_list[ii]
-- Now read values
local pos_num = Args['pos_'..team_code_ii] or ii
local team_namegroup_txt = Args['name_group_'..team_code_ii] or team_code_ii' '
local winsteam_name = tonumber(Args['win_name_'..team_code_ii]) or 0team_code_ii
local drawsnote_local = tonumber(Args['draw_note_'..team_code_ii]) or 0nil
local losses = tonumber(Args['loss_'..team_code_ii]) or 0
local gfor = tonumber(Args['gf_'..team_code_ii]) or 0
local gaig = tonumber(Args['ga_'..team_code_ii]) or 0
local s_pts = tonumber(Args['startpoints_'..team_code_ii]) or 0
local note_local = Args['note_'..team_code_ii] or nil
local hth_local = Args['hth_'..team_code_ii] or nil
-- Then calculate some values
local matches = wins + draws + losses
local gdiff = gfor - gaig
local points = win_points*wins + draw_points*draws + loss_points*losses + s_pts
-- Does it need a promotion/qualification/relegation tag
local result_local = Args[respre..'result'..ii] or nil
local bg_col = nil
 
-- Get local background colour
if result_local then
bg_col = result_col[Args[respre..'col_'..result_local]] or Args[respre..'col_'..result_local] or 'whiteinherit'
if bg_col == 'background-color:inherit'.. then bg_col = bg_col .. 'background-color:inherit;' --color: Full styleinherit' tag
else
end
if not bg_col then bg_col = 'background-color:transparent'..bg_col..';color:black;' end -- Becomes defaultFull ifstyle undefinedtag
end
end
if not bg_col then bg_col = 'background-color:transparent; color: inherit;' end -- Becomes default if undefined
-- Bold this line or not
local ii_fw = ii == ii_show and 'font-weight: bold;' or 'font-weight: normal;'
if yesno(Args['show_totals'] or 'no') and team_code_ii == total_row_name then
ii_fw = 'font-weight: bold;'
end
-- Check whether there is a note or not, if so get text ready for it
Line 203 ⟶ 305:
-- Call refn template
note_string = frame:expandTemplate{ title = 'efn', args = { group='Table_noteslower-alpha', name=note_id, note_local} }
else
-- Option 2
Line 221 ⟶ 323:
-- Call refn template
note_string = frame:expandTemplate{ title = 'efn', args = { group='Table_noteslower-alpha', name=note_id, Args['note_'..note_local]} }
end
end
else
note_string = '';
end
-- Check whether there is a head-to-head note or not, if so get text ready for it the same way as for the notes
if hth_local and full_table then
-- Set global check for notes to true
notes_exist = true
if not Args['hth_'..hth_local] then
-- Option 1
-- Now define the identifier for this
hth_id = '"table_hth_'..team_code_ii..rand_val..'"' -- Add random end for unique ID if more tables are present on article (which might otherwise share an ID)
hth_id_list[team_code_ii] = hth_id
-- Call refn template
hth_string = frame:expandTemplate{ title = 'efn', args = { group='Table_notes', name=hth_id, hth_local} }
else
-- Option 2
hth_local_num = team_list[hth_local]
if hth_id_list[hth_local] or ((hth_local_num >= ii_start) and (hth_local_num <= ii_end)) then
-- Option 2a
hth_id = '"table_hth_'..hth_local..rand_val..'"'
hth_string = frame:extensionTag{ name = 'ref', args = { group = 'lower-alpha', name = hth_id} }
else
-- Option 2b
hth_id = '"table_hth_'..hth_local..rand_val..'"' -- Add random end for unique ID
hth_id_list[hth_local] = hth_id
-- Call refn template
hth_string = frame:expandTemplate{ title = 'efn', args = { group='Table_notes', name=hth_id, Args['hth_'..hth_local]} }
end
end
else
hth_string = '';
end
-- Insert status when needed
local status_string = ''
local status_local = show_status and Args[respre .. 'status_'..team_code_ii] or nil
local status_let_first = true
local curr_letter
Line 269 ⟶ 341:
curr_letter = mw.ustring.upper(mw.ustring.sub(status_local,jjj,jjj))
-- See whether it exist
if status_codet_status.code[curr_letter] then
-- Depending on whether it is the first letter of not
if status_let_first then
status_string = curr_letter
status_calledt_status.called[curr_letter] = true
status_let_first = false
else
status_string = status_string..', '..curr_letter
status_calledt_status.called[curr_letter] = true
end
end
end
-- Only add brackets/dash and bolding if it exist
if not status_let_first then status_string = ' <span style="font-weight:bold">('..status_string..')</span>' end
if t_status.position == 'before' then
status_string = '<span style="font-weight:bold">'..string.lower(status_string)..' &ndash;</span> '
else
status_string = ' <span style="font-weight:bold">('..status_string..')</span>'
end
end
end
-- Now build the rows
if yesno(Args['show_totals'] or 'no') and team_code_ii == total_row_name then
table.insert(t,'|- \n') -- New row
table.insert(t,'!|- scopeclass="rowsortbottom" style="text-align: center;'..ii_fw..bg_col..'"| '..pos_num..'\n') -- PositionNew numberrow
else
table.insert(t,'| style="text-align: left; white-space:nowrap;'..ii_fw..bg_col..'"| '..team_name..note_string..status_string..'\n')-- Team (with possible note)
table.insert(t,'|- style="'..ii_fw..bg_col..'" |'..matches..'\n') -- PlayedNew row
end
if full_table then
if position_col then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..wins..'\n') -- Won
table.insert(t,'| style="text-align: center;'..ii_fw..bg_col..'"| |'..drawspos_num..'\n') -- DrawnPosition number
end
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..losses..'\n') -- Lost
if full_table and group_col then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..gfor..'\n') -- GF
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..gaiggroup_txt..'\n') -- GAGroup number/name
-- For goal difference insert + or &minus; as needed
table.insert(t,'| style="'..ii_fw..bg_col..'" |')
if gdiff>0 then
table.insert(t,'+'..gdiff)
elseif gdiff == 0 then
table.insert(t,0)
else
table.insert(t,'&minus;'..-gdiff)
end
table.insert(t,'\n')
end
-- Build the team string order based on status position
-- Add &minus; for negative point totals
local team_string
table.insert(t,'| style="font-weight: bold;'..bg_col..'" | ')
if points<0t_status.position == 'before' then
team_string = status_string..team_name..note_string
table.insert(t,'&minus;'..-points..hth_string)
else
team_string = team_name..note_string..status_string
table.insert(t,points..hth_string)
end
table.insert(t,'! scope="row" style="text-align: left; white-space:nowrap;'..ii_fw..bg_col..'"| '..team_string..'\n')-- Team (with possible note)
table.insert(t,'\n')
-- Call to subfunction
t_return = p_style.row(frame,t,Args,p_sub,notes_exist,hth_id_list,full_table,rand_val,team_list,team_code_ii,ii_start,ii_end,ii_fw,bg_col,N_teams,ii,ii_show)
t = t_return.t
notes_exist = t_return.notes_exist
hth_id_list = t_return.hth_id_list
-- Now check what needs to be added inside the results column
Line 323 ⟶ 396:
N_rows_res = 1
jjj = ii+1
result_local = Args[respre..'result'..ii] or ''
local cont_loop = true
while (jjj<=ii_end) and cont_loop do
Line 330 ⟶ 403:
new_res_ii = jjj
else
res_jjj = Args[respre..'result'..jjj] or ''
if result_local == res_jjj then
N_rows_res = N_rows_res+1
Line 349 ⟶ 422:
-- Get background colour
bg_col = nil
 
if Args['result'..ii] then
if Args[respre..'result'..ii] then
bg_col = result_col[Args['col_'..result_local]] or Args['col_'..result_local] or 'white'
bg_col = result_col[Args[respre..'col_'..result_local]] or Args[respre..'col_'..result_local] or 'inherit'
bg_col = 'background-color:'..bg_col..';' -- Full style tag
if bg_col == 'inherit' then bg_col = bg_col .. '; color: inherit'
else
bg_col = 'background-color:'..bg_col..';color:black;' -- Full style tag
end
end
if not bg_col then bg_col = 'background-color:transparent; color: inherit;' end -- Becomes default if undefined
-- Check for notes
local note_res_string, note_ref, note_text = '', '', ''
if Args['note_res_'..result_local] then
notes_exist = true
local note_res_local = Args['note_res_'..result_local]
note_id = '"table_note_res_'..result_local..rand_val..'"' -- Identifier
-- Split the note_res_local into a table if all the entries are valid
-- Check whether it exists or not
local multiref = 1
if note_id_list[note_local] then
local note_res_local_table = mw.text.split(note_res_local, '%s*,%s*')
-- It exists already
if (#note_res_local_table > 1) then
note_res_string = frame:extensionTag{ name = 'ref', args = { group = 'lower-alpha', name = note_id} }
for k, note_res_loc in ipairs(note_res_local_table) do
multiref = multiref * (Args['note_res_' .. note_res_loc] and 1 or 0)
end
else
--multiref It= doesn't exist yet0
end
note_res_string = frame:expandTemplate{ title = 'efn', args = { group='Table_notes', name=note_id, Args['note_res_'..result_local]} }
 
-- Split failed, so make a single entry table with hth_local inside
if multiref < 1 then
note_res_local_table = { note_res_local }
end
 
for k,note_res_local in ipairs(note_res_local_table) do
if not Args['note_res_'..note_res_local] then
-- It does not point to another result note
note_ref = respre..'res_'..result_local
note_id = '"table_note_res_'..result_local..rand_val..'"' -- Identifier
note_text = note_res_local
else
-- It does point to another result note
note_ref = respre..'res_'..note_res_local
note_id = '"table_note_res_'..note_res_local..rand_val..'"' -- Identifier
note_text = Args['note_res_'..note_res_local]
end
-- Check whether it is already printed
if not note_id_list[note_ref] then
-- Print it
note_id_list[note_ref] = note_id
note_res_string = note_res_string .. frame:expandTemplate{ title = 'efn', args = { group='lower-alpha', name=note_id, note_text} }
else
-- Refer to it
note_res_string = note_res_string .. frame:extensionTag{ name = 'ref', args = { group = 'lower-alpha', name = note_id} }
end
end
else
note_res_string = ''
end
-- Get text
local text_result = Args[respre..'text_'..result_local] or ''
if text_result:match('fbmulticomp') then
ii_fw = 'padding:0;' .. ii_fw
if text_result:match('fbmulticompefn') then
notes_exist = true
end
end
text_field_result = '| style="'..ii_fw..bg_col..'" rowspan="'..tostring(N_rows_res)..'" |'..text_result..note_res_string..'\n'
-- See whether it is needed (only when blank for all entries)
Line 379 ⟶ 490:
end
-- Insert match row if needed
-- 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<ii_end)match_table then
local legs = tonumber(Args['legs']) or 1
if full_table then
-- Add empty cell
table.insert(t,'|- style="background-color:'..result_col['black1']..'; line-height:3pt;"\n')
table.insert(t,'| style="background-color:white;color:black;border-top:white;border-bottom:white;"| \n')
if results_defined then
-- With results column
-- Now include note to match results if needed
table.insert(t,'||||||||||||||||||||||\n')
for jj=top_pos,N_teams do
team_code_jj = team_list[jj]
if ii == jj then
-- Nothing
else
--for Nol=1,legs results columndo
local m = (legs == 1) and 'match_' or 'match' .. l .. '_'
table.insert(t,'||||||||||||||||||||\n')
local match_note = Args[m..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] or Args[m..match_note..'_note']) then
-- It's the entry
note_id = '"table_note_'..team_code_ii..'_'..team_code_jj..rand_val..'"' -- Add random end for unique ID if more tables are present on article (which might otherwise share an ID)
note_id_list[team_code_ii..'_'..team_code_jj] = note_id
note_string = frame:expandTemplate{ title = 'efn', args = { group='lower-alpha', name=note_id, match_note} }
else
-- Check for existence elsewhere
note_local_num = team_list[match_note] or ii_end + 1
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{ name = 'ref', args = { group = 'lower-alpha', name = note_id} }
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{ title = 'efn', args = { group='lower-alpha', name=note_id, Args['note_'..match_note]} }
end
end
 
-- Now append this to the match result string
Args[m..team_code_ii..'_'..team_code_jj] = (Args[m..team_code_ii..'_'..team_code_jj] or '')..note_string
end
end
end
else
table.insert(t,'|- style="background-color:'..result_col['black1']..'; line-height:3pt;"\n')
table.insert(t,'||||||||\n')
end
-- Add rest of match row
t = p_matches.row(t,Args,N_teams,team_list,ii,ii_show,legs)
end
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)
-- Remove results header if it is unused
if full_tableArgs['split'..ii] and not results_defined(ii<ii_end) then
-- Base size on N_cols (it needs 2*N_cols |)
-- First get it as one string, then use string replace to replace that header by empty string
table.insert(t,'|- style="background-color:'..result_col['black1']..'; line-height:3pt;"\n')
local t_str = tostring(table.concat(t))
table.insert(t,string.rep('|',2*N_cols)..'\n')
t_str = mw.ustring.gsub( t_str, results_header_txt, '' )
t = {}end
table.insert(t, t_str)
end
-- Close table
table.insert(t, '|}\n')
-- Get info for footer
local update = Args['update'] or 'unknown'
local start_date = Args['start_date'] or 'unknown'
local source = Args['source'] or (title_source == true and '')
or frame:expandTemplate{ title = 'citation needed', args = { reason='No source parameter defined', date=os.date('%B %Y') } }
local class_rules = Args['class_rules'] or nil
-- Create footer text
-- Date updating
if update~='complete' and update~='' then
local matches_text = Args['matches_text'] or 'match(es)'
table.insert(t_footer,'Updated to match(es) played on '..update..'. ')
if string.lower(update)=='complete' or hide_footer then
-- Do nothing
elseif update=='' then
-- Empty parameter
table.insert(t_footer,'Updated to '..matches_text..' played on unknown. ')
elseif string.lower(update)=='future' then
-- Future start date
table.insert(t_footer,'First '..matches_text..' will be played: '..start_date..'. ')
else
table.insert(t_footer,'Updated to '..matches_text..' played on '..update..'. ')
end
table.insert(t_footer,'Source: '..source)
-- Stack footer or not
if class_rules and full_table then
local footer_break = yesno(Args['stack_footer'] or 'no') and true or false
table.insert(t_footer,'<br>Rules for classification: '..class_rules)
-- Variable for linebreak
local stack_string = '<br>'
if footer_break and (not (string.lower(update)=='complete')) and not hide_footer then table.insert(t_footer,stack_string) end
if source ~= '' and not hide_footer then
table.insert(t_footer,'Source: '..source)
end
if class_rules and full_table and show_class_rules and not hide_footer then
if (#t_footer > 0) then table.insert(t_footer,'<br>') end
table.insert(t_footer,'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(status_letterst_status.letters) do
curr_letter = mw.ustring.upper(mw.ustring.sub(status_letterst_status.letters,jjj,jjj))
if status_calledt_status.called[curr_letter] then
if (footer_break and status_exist) then
status_string = status_string..'<span style="font-weight:bold">('..curr_letter..')</span> '..status_code[curr_letter]..'; '
status_string = status_string..stack_string
end
if t_status.position == 'before' then
status_string = status_string..'<span style="font-weight:bold">'..string.lower(curr_letter)..' &ndash;</span> '..t_status.code[curr_letter]..'; '
else
status_string = status_string..'<span style="font-weight:bold">('..curr_letter..')</span> '..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 and not hide_footer then
if (#t_footer > 0) then table.insert(t_footer,'<br>') end
status_string = '<br>'..mw.ustring.sub(status_string,1,mw.ustring.len(status_string)-2)..'.'
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
if (#t_footer > 0) then table.insert(t_footer,'<br>Notes:') end
table.insert(t_footer,frame'Notes:expandTemplate{ title = 'notelist', args = { group='Table_notes' } })
-- As reflist size text
t_footer = '<div class="sports-table-notes">'..table.concat(t_footer)..'</div>'
t_footer = t_footer..frame:expandTemplate{ title = 'notelist', args = { group='lower-alpha'} }
else
-- As reflist size text
t_footer = '<div class="sports-table-notes">'..table.concat(t_footer)..'</div>'
end
-- Embed within small tags
t_footer = '<div style="font-size:85%;">'..table.concat(t_footer)..'</div>'
-- Add footer to main text table
table.insert(t,t_footer)
-- Rewrite anchor links
return table.concat(t)
for k=1,#t do
if t[k]:match('%[%[#[^%[%]]*%|') then
t[k] = mw.ustring.gsub(t[k], '(%[%[)(#[^%[%]]*%|)', '%1' .. baselink .. '%2')
end
end
-- Generate tracking
if not Args['notracking'] then
local getTracking = require('Module:Sports table/argcheck').check
local warning_categories, tracking_categories = getTracking(Args, frame:getParent().args)
if #warning_categories > 0 then
if frame:preprocess( "{{REVISIONID}}" ) == "" then
for k=1,#warning_categories do
warning_categories[k] = mw.ustring.gsub(warning_categories[k], '^%[%[Category:Pages using sports table with (.*)|(.*)%]%]$', '<div style="color:red">Warning: %1 = %2</div>')
end
end
end
for k=1,#warning_categories do
table.insert(t, warning_categories[k])
end
for k=1,#tracking_categories do
table.insert(t, tracking_categories[k])
end
if(Args['showteam'] == nil) then
local getWarnings = require('Module:Sports table/totalscheck').check
local total_warnings = getWarnings(Args, team_list, ii_start, ii_end)
if #total_warnings > 0 then
if frame:preprocess( "{{REVISIONID}}" ) == "" then
for k=1,#total_warnings do
table.insert(t, '<div style="color:green">Possible problem: ' .. total_warnings[k] .. '</div>')
end
end
end
end
else
table.insert(t, '[[Category:Pages using sports table with notracking]]')
end
if Args['float'] then
return frame:expandTemplate{ title = 'stack begin', args = {clear = 'true', margin = '1', float = Args['float']} }
.. templatestyles .. '\n' .. table.concat(t) .. frame:expandTemplate{ title = 'stack end'}
end
 
return templatestyles .. '\n' .. table.concat(t)
end