Module:Team appearances list: Difference between revisions

m
1 revision imported
m (Protected "Module:Team appearances list": Highly visible template: via RfPP ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite)))
 
m (1 revision imported)
 
(2 intermediate revisions by 2 users not shown)
Line 4:
 
local data_competitions
local data_old_names
local function load_data(frame)
-- Load data module (or its sandbox) and set variables from its exported data.
Line 11 ⟶ 12:
local datamod = mw.loadData('Module:Team appearances list/data' .. sandbox)
data_competitions = datamod.competitions
data_old_names = datamod.old_names
end
end
Line 58 ⟶ 60:
options.competition = valid_text('competition')
options.team = valid_text('team')
options.competitions = data_competitions[options.competition] or data_competitions[data_old_names[options.competition]]
local begin_optional
if options.competitions then
Line 72 ⟶ 74:
end
end
options.disqualified_year = valid_integer('disqualified_year', 1800, 2100, true)
return options
end
Line 138 ⟶ 141:
 
local function competition_information(args)
-- Return threefour tables with informationcompetition forand theteam specified competitioninformation:
-- * List of competition years that the team attended or could have attended.
-- * Table of absentdisqualified years. (the team was absent, but there is an
-- article regarding the absent year).
-- * Table of absent years (when the team did not attend).
-- * List of pairs of years (absent for each year in range, inclusive).
local options = make_options(args)
Line 149 ⟶ 154:
local competitions = options.competitions
if competitions then
absences = competitions[options.team] or competitions[data_old_names[options.team]]
begin_year = begin_year or (absences and absences.begin_year) or 0
end_year = end_year or (absences and absences.end_year) or 9999
Line 165 ⟶ 170:
end
end
local disqualified_years = {}
return comp_years, competition_absences(absences or args)
if options.disqualified_year then
-- Input currently only allows entry of a single disqualified year.
-- However processing works for any number of such years.
disqualified_years[options.disqualified_year] = true
end
return comp_years, disqualified_years, competition_absences(absences or args)
end
 
local function gameName(year, inputName)
-- Modifies output of display being sent back to the hlist
-- for games that have had a name change but are still considered
-- the same competition.
if inputName=="World Athletics Championships" or inputName=="World Championships in Athletics" then
if year <= 2017 then
return "World Championships in Athletics"
else
return "World Athletics Championships"
end
elseif (inputName=="British Empire Games"
or inputName=="British Empire and Commonwealth Games"
or inputName=="British Commonwealth Games"
or inputName=="Commonwealth Games") then
if year <= 1950 then
return "British Empire Games"
elseif year <= 1966 then
return "British Empire and Commonwealth Games"
elseif year <= 1974 then
return "British Commonwealth Games"
else
return "Commonwealth Games"
end
elseif inputName=="Southeast Asian Peninsular Games" or inputName=="Southeast Asian Games" then
if year <= 1975 then
return "Southeast Asian Peninsular Games"
else
return "Southeast Asian Games"
end
elseif inputName=="Asian Indoor Games" or inputName=="Asian Indoor and Martial Arts Games" then
if year <= 2009 then
return "Asian Indoor Games"
else
return "Asian Indoor and Martial Arts Games"
end
elseif inputName=="Southern Cross Games" or inputName=="South American Games" then
if year <= 1982 then
return "Southern Cross Games"
else
return "South American Games"
end
elseif inputName=="All-Africa Games" or inputName=="African Games" then
if year <= 2011 then
return "All-Africa Games"
else
return "African Games"
end
else
return inputName
end
end
 
local function teamName(year, inputName, comp)
-- Modifies output of display being sent back to the hlist
-- for games that have had a name change but are still considered
-- the same competition.
if inputName=="Eswatini" or inputName=="Swaziland" then
if year < 2018 or year == 2018 and comp == 'Commonwealth Games' then
return "Swaziland"
else
return "Eswatini"
end
elseif inputName=="Upper Volta" or inputName=="Burkina Faso" then
if year <= 1983 then
return "Upper Volta"
else
return "Burkina Faso"
end
elseif inputName=="Democratic Republic of the Congo" or inputName=="Zaire" then
if year >= 1984 and year <=1996 then
return "Zaire"
else
return "Democratic Republic of the Congo"
end
elseif (inputName=="Individual Olympic Athletes"
or inputName=="Independent Olympic Athletes"
or inputName=="Independent Olympic Participants"
or inputName=="Olympic Athletes from Russia"
or inputName=="ROC") then
if year == 1992 or year==2014 then
return "Independent Olympic Participants"
elseif year == 2000 then
return "Individual Olympic Athletes"
elseif year == 2012 or year==2016 then
return "Independent Olympic Athletes"
elseif year == 2018 then
return "Olympic Athletes from Russia"
elseif year == 2020 or year==2022 then
return "ROC"
else
return inputName
end
elseif (inputName=="Independent Paralympic Participants"
or inputName=="Individual Paralympic Athletes"
or inputName=="Independent Paralympic Athletes"
or inputName=="RPC") then
if year == 1992 then
return "Independent Paralympic Participants"
elseif year == 2000 then
return "Individual Paralympic Athletes"
elseif year==2016 then
return "Independent Paralympic Athletes"
elseif year == 2020 or year==2022 then
return "RPC"
else
return inputName
end
elseif inputName=="North Macedonia" or inputName=="Macedonia" then
if year < 2019 then
return "Macedonia"
else
return "North Macedonia"
end
elseif inputName=="Malaysia" or inputName=="Malaya" then
if year < 1963 then
return "Malaya"
else
return "Malaysia"
end
else
return inputName
end
end
 
Line 171 ⟶ 306:
load_data() -- in case this function is called by another module
local hlist = require('Module:List').horizontal
local competitions, disqualified_years, absent_years, absent_ranges = competition_information(args)
local current_year = os.date('!*t').year
local function is_absent(y)
if absent_years[y] then
Line 202 ⟶ 338:
end
if y then
local display = tostring(y)
table.insert(appearances, string.format(
if y > current_year then
'[[%s at the %d %s|%d]]',
display = '<i>' .. display .. '</i>'
args.team, y, args.competition, y
))end
if disqualified_years[y] then
display = '<del>' .. display .. '</del>'
end
local compName = gameName(y, args.competition)
local teamOut = teamName(y, args.team, args.competition)
if compName == 'FIS Alpine World Ski Championships' then
table.insert(appearances, string.format(
'[[%s at the %s %d|%s]]',
teamOut, compName, y, display
))
else
table.insert(appearances, string.format(
'[[%s at the %d %s|%s]]',
teamOut, y, compName, display
))
end
end
end
Line 211 ⟶ 363:
return hlist(appearances)
end
 
function p.main(frame)
load_data(frame)