Module:Sports table: Difference between revisions

Content deleted Content added
No edit summary
fix text color in dark mode; this generally works but may cause problems, in which case revert or try specifying a different CSS value
 
(47 intermediate revisions by 7 users not shown)
Line 2:
-- See documentation for details
 
require('Module:No globalsstrict')
 
local p = {}
Line 19:
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
iflocal tsection = frame:getParent(Args).args['transcludesection'] andor Argsframe:getParent().args['section']) or ''
and local Args['transcludesection']bsection ~= Argsframe.args['section'] thenor ''
if( tsection ~= '' and bsection ~= '' ) then
return ''
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 mw.title.getCurrentTitle().textbaselink == baselink'Module:Excerpt' then baselink = '' end
if mw.title.getCurrentTitle().fullText == baselink then baselink = '' end
local template_name = Args['template_name']
or local template_name = (baselink ~= '' and (':' .. baselink .. (table_anchor ~= '' and '#' .. table_anchor or '')))
or ''
 
Line 46 ⟶ 54:
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/sandbox')
-- Random value used for uniqueness
Line 62 ⟶ 70:
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 78 ⟶ 100:
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='lower-alpha', res_head_note} }
Line 89 ⟶ 111:
-- Alternative syntax for team list
if Args['team_order'] and Args['team_order'] ~= '' then
local team_order_offset = (tonumber(Args['team_order_start']) or 1) - 1
local tlist = mw.text.split(Args['team_order'], '%s*[;,]%s*')
for k, tname in ipairs(tlist) do
if tname ~= '' then
Args['team' .. (k + team_order_offset)] = tname
end
end
Line 106 ⟶ 129:
team_list[Args['team'..N_teams]] = N_teams -- team X entry is position i
end
 
-- Optional totals
-- Show all stats in table or just matches played and points
local pld_pts_valtotal_row_name = Args['only_pld_pts'] or 'noSPORTS_TABLE_TOTAL'
if yesno(Args['show_totals'] or 'no') then
local full_table
N_teams = N_teams+1
local show_class_rules = yesno(Args['show_class_rules'] or 'yes') and true or false
Args['team' .. N_teams] = total_row_name
-- True if par doesn't exist, false otherwise
Args['name_' .. total_row_name] = 'Total'
-- First convert to lower case if it is a string
Args['result' .. N_teams] = total_row_name
pld_pts_val = string.lower(pld_pts_val)
Args['col_' .. total_row_name] = '#eee'
if yesno(pld_pts_val) then
team_list[N_teams] = Args['team' .. N_teams]
full_table = false
team_list[Args['team'..N_teams]] = N_teams
elseif pld_pts_val=='no_hide_class_rules' then
full_table = true
show_class_rules = false
else
full_table = true
end
 
-- Show position
local position_col = yesno(Args['show_positions'] or 'yes') and true or false
Line 131 ⟶ 150:
-- Show match_table or not
local match_table = yesno(Args['show_matches'] or 'no') and true or false
local p_matches = match_table and require('Module:Sports results')
(style_def == 'Chess' and require('Module:Sports results/'..style_def) or require('Module:Sports results'))
-- Custom position column label or note
Line 143 ⟶ 163:
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', brackets=1, 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
Line 149 ⟶ 175:
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
 
-- Add a table anchor
if table_anchor ~= '' then
table.insert(t, '<span class="anchor" id="' .. table_anchor .. '"></span>\n')
end
 
Line 156 ⟶ 197:
-- 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
Line 199 ⟶ 240:
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[respre..'result'..ii] and Args[respre..'text_' .. Args[respre..'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
Line 229 ⟶ 272:
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 'inherit'
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 302 ⟶ 352:
end
end
end
-- Only add brackets/dash and bolding if it exist
if not status_let_first then
if t_status.position == 'before' then
Line 314 ⟶ 364:
-- 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,'|- class="sortbottom"\n') -- New row
else
table.insert(t,'|- \n') -- New row
end
if position_col then
table.insert(t,'! scope="row"| style="text-align: center;'..ii_fw..bg_col..'"| '..pos_num..'\n') -- Position number
end
if full_table and group_col then
Line 328 ⟶ 382:
team_string = team_name..note_string..status_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)
-- 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)
Line 368 ⟶ 422:
-- Get background colour
bg_col = nil
 
if Args[respre..'result'..ii] then
bg_col = result_col[Args[respre..'col_'..result_local]] or Args[respre..'col_'..result_local] or 'inherit'
if bg_col == 'background-color:inherit'.. then bg_col = bg_col .. ';' --color: Full style taginherit'
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 = '', '', ''
Line 434 ⟶ 492:
-- Insert match row if needed
if match_table then
local legs = tonumber(Args['legs']) or 1
-- Add empty cell
table.insert(t,'| style="background-color:white;color:black;border-top:white;border-bottom:white;"| \n')
-- Now include note to match results if needed
Line 443 ⟶ 502:
-- Nothing
else
for l=1,legs do
local match_note = Args['match_'..team_code_ii..'_'..team_code_jj..'_note']
local m = (legs == 1) and 'match_' or 'match' .. l .. '_'
if match_note then
local match_note = Args[m..team_code_ii..'_'..team_code_jj..'_note']
notes_exist = true
--if Onlymatch_note when it existthen
notes_exist = true
-- First check for existence of reference for note
-- Only when it exist
if not (Args['note_'..match_note] or Args['match_'..match_note..'_note']) then
-- It'sFirst thecheck entryfor existence of reference for note
if not (Args['note_'..match_note] or Args[m..match_note..'_note']) then
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)
-- It's the entry
note_id_list[team_code_ii..'_'..team_code_jj] = note_id
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
 
-- Now append this to the match result string
Args['match_'..team_code_ii..'_'..team_code_jj] = (Args['match_'..team_code_ii..'_'..team_code_jj] or '')..note_string
end
end
Line 477 ⟶ 539:
-- Add rest of match row
t = p_matches.row(t,Args,N_teams,team_list,ii,ii_show,legs)
end
Line 489 ⟶ 551:
-- 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
Line 500 ⟶ 563:
-- Date updating
local matches_text = Args['matches_text'] or 'match(es)'
if string.lower(update)=='complete' or hide_footer then
-- Do nothing
elseif update=='' then
Line 507 ⟶ 570:
elseif string.lower(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..'. ')
Line 518 ⟶ 581:
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)
table.insert(t_footer,'Source: '..source)
if class_rules and full_table and show_class_rules then
end
table.insert(t_footer,'<br>Rules for classification: '..class_rules)
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
Line 543 ⟶ 609:
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,'Notes:')
-- As reflist size text
t_footer = '<div class="reflistsports-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="reflistsports-table-notes">'..table.concat(t_footer)..'</div>'
end
Line 572 ⟶ 640:
-- Generate tracking
if not Args['notracking'] then
local getTracking = require('Module:Sports table/argcheck/sandbox').check
local warning_categories, tracking_categories = getTracking(Args, frame:getParent().args)
Args = getArgs(frame, {frameOnly = true})
if #warning_categories > 0 then
Args['showteam'] = frame:getParent().args['showteam']
local tracking_categories = getTracking(Args)
if #tracking_categories > 0 then
if frame:preprocess( "{{REVISIONID}}" ) == "" then
for k=1,#tracking_categorieswarning_categories do
tracking_categorieswarning_categories[k] = mw.ustring.gsub(tracking_categorieswarning_categories[k], '^%[%[Category:Pages using sports table with (.*)|(.*)%]%]$', '<div style="color:red">Warning: %1 = %2</div>')
end
end
end
for k=1,#tracking_categories do
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