Module:Team appearances list/sandbox
![]() | This is the module sandbox page for Module:Team appearances list (diff). |
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
This module implements {{Team appearances list}}. Check there for usage documentation.
Modules
- Module:Team appearances list • Module:Team appearances list/sandbox • different (diff)
- Module:Team appearances list/data • Module:Team appearances list/data/sandbox • different (diff)
- Module:Team appearances list/show • Module:Team appearances list/show/sandbox • same content
Module:Team appearances list is invoked by {{Team appearances list}} to display a horizontal list showing the years a specified team participated in a specified competition. Each year of attendance is wikilinked to a corresponding article, while years the team did not compete (absences) are shown as disabled.
The names of the competition and team must be specified. Optionally, information for a competition can be defined in Module:Team appearances list/data, and team information can be included:
begin_year
– The first year to be shown.end_year
– The last year to be shown.- Years the team did not attend the competition.
If begin_year
or end_year
are defined for a team, they set default values that can be overridden with parameters in the template.
If a team is defined for a particular competition, any absent years in the templace call are ignored (instead, the absences defined in the data module are used).
Module:Team appearances list/show is used for testing. It shows the results for all competition/team pairs defined in the data module. The results are displayed at Module talk:Team appearances list/show.
Changes should be performed in the sandbox modules, using the following for testing:
- {{Team appearances list/sandbox}} – Uses the sandbox main and data modules.
- Module talk:Team appearances list/show – Results for all competition/team pairs defined in the sandbox data module.
Errors
Parameters provided by the template are validated using the following rules.
Always: competition required : non-empty string team required : non-empty string If competition is defined in data module: begin_year optional : number from 1800 to 2100 inclusive end_year optional : as above (and end_year >= begin_year) else: begin_year required : as above end_year optional : as above interval required : number from 1 to 30 inclusive
An invalid parameter causes an error to be displayed and places the page in the hidden category Category:Pages with script errors.
--[[
Add your experimental module code here.
--]]
-- This module implements [[Template:Team appearances list]].
-- [SublimeLinter luacheck-globals:mw]
local p = {}
local compressSparseArray = require('Module:TableTools').compressSparseArray
local hlist = require('Module:List').horizontal
local valueUnion = require('Module:Set').valueUnion
local OMIT = "Module:Team appearances list/absences"
local COMPS = "Module:Team appearances list/competitions"
local all_omit = mw.loadData(OMIT)
local all_comps = mw.loadData(COMPS)
local COMPETITIONS = {
["All-Africa Games"] = {
1965, 1973, 1978, 1987, 1991, 1995, 1999, 2003, 2007, 2011, 2015},
-----Asian Games----
["Asian Games"] = {
1951, 1954, 1958, 1962, 1966, 1970, 1974, 1978, 1985, 1986, 1990, 1994,
1998, 2002, 2006, 2010, 2014},
["Asian Beach Games"] = {
2008, 2010, 2012, 2014, 2016},
["Asian Para Games"] = {
2010, 2014, 2018},
["Asian Youth Games"] = {
2009, 2013, 2021},
["Asian Winter Games"] = {
1986, 1990, 1996, 1999, 2003, 2007, 2011, 2017},
["East Asian Games"] = {
1993, 1997, 2001, 2005, 2009, 2013},
["South Asian Games"] = {
1984, 1985, 1987, 1989, 1991, 1993, 1995, 1999, 2004, 2006, 2010, 2016},
["Southeast Asian Games"] = {
1977, 1979, 1981, 1983, 1985, 1987, 1989, 1991, 1993, 1995, 1997, 1999,
2001, 2003, 2005, 2007, 2009, 2011, 2013, 2015, 2017},
["Southeast Asian Peninsular Games"] = {
1959, 1961, 1963, 1965, 1967, 1969, 1971, 1973, 1975},
["West Asian Games"] = {
1997, 2002, 2005, 2016},
-----Commonwealth Games-----
["Commonwealth Games"] = {
1930, 1934, 1938, 1950, 1954, 1958, 1962, 1966, 1970, 1974, 1978, 1982,
1986, 1990, 1994, 1998, 2002, 2006, 2010, 2014},
["Commonwealth Youth Games"] = {
2000, 2004, 2008, 2011, 2015, 2017},
-----European Games-----
["European Athletics Championships"] = {
1934, 1938, 1946, 1950, 1954, 1958, 1962, 1966, 1969, 1971, 1974, 1978,
1982, 1986, 1990, 1994, 1998, 2002, 2006, 2010, 2012, 2014, 2016},
["European Games"] = {
2015},
["Mediterranean Games"] = {
1951, 1955, 1959, 1963, 1967, 1971, 1975, 1979, 1983, 1987, 1991, 1993,
1997, 2001, 2005, 2009, 2013, 2017},
----- Olympics -----
["Summer Olympics"] = {
1896, 1900, 1904, 1908, 1912, 1920, 1924, 1928, 1932, 1936, 1948, 1952,
1956, 1960, 1964, 1968, 1972, 1976, 1980, 1984, 1988, 1992, 1996, 2000,
2004, 2008, 2012, 2016},
["Summer Paralympics"] = {
1960, 1964, 1968, 1972, 1976, 1980, 1984, 1988, 1992, 1996, 2000, 2004,
2008, 2012, 2016},
["Summer Youth Olympics"] = {
2010, 2014, 2018},
["Winter Olympics"] = {
1924, 1928, 1932, 1936, 1948, 1952, 1956, 1960, 1964, 1968, 1972, 1976,
1980, 1984, 1988, 1992, 1994, 1998, 2002, 2006, 2010, 2014},
["Winter Paralympics"] = {
1976, 1980, 1984, 1988, 1992, 1994, 1998, 2002, 2006, 2010, 2014},
["Winter Youth Olympics"] = {
2012, 2016},
----- Misc / World -----
["FEI World Equestrian Games"] = {
1990, 1994, 1998, 2002, 2006, 2010, 2014},
["Pan American Games"] = {
1951, 1955, 1959, 1963, 1967, 1971, 1975, 1979, 1983, 1987, 1991, 1995,
1999, 2003, 2007, 2011, 2015},
["Summer Universiade"] = {
1959, 1961, 1963, 1965, 1967, 1970, 1973, 1975, 1977, 1979, 1981, 1983,
1985, 1987, 1989, 1991, 1993, 1995, 1997, 1999, 2001, 2003, 2005, 2007,
2009, 2011, 2013, 2015, 2017},
["Winter Universiade"] = {
1960, 1962, 1964, 1966, 1968, 1972, 1978, 1981, 1983, 1985, 1987, 1989,
1991, 1993, 1995, 1997, 1999, 2001, 2003, 2005, 2007, 2009, 2011, 2013,
2015, 2017},
["World Aquatics Championships"] = {
1973, 1975, 1978, 1982, 1986, 1991, 1994, 1998, 2001, 2003, 2005, 2007,
2009, 2011, 2013, 2015},
["World Championships in Athletics"] = {
1983, 1987, 1991, 1993, 1995, 1997, 1999, 2001, 2003, 2005, 2007, 2009,
2011, 2013, 2015, 2017},}
function p._main(args)
local begin_year = args.begin_year and tonumber(args.begin_year)
local end_year = args.end_year and tonumber(args.end_year)
local appearances = {}
local absences = {}
for _, v in pairs(compressSparseArray(args)) do
absences[string.sub(v, 1, 4)] = mw.getCurrentFrame():expandTemplate{
title='Gray', args={v}}
end
local function processYear(y)
y = tostring(y)
if absences[y] then
table.insert(appearances, absences[y])
absences[y] = nil
else
table.insert(appearances, string.format(
'[[%s at the %s %s|%s]]', args.team, y, args.competition, y))
end
end
if COMPETITIONS[args.competition] then
for _, y in pairs(COMPETITIONS[args.competition]) do
if end_year and y > end_year then
break
elseif not begin_year or y >= begin_year then
processYear(y)
end
end
elseif not tonumber(args.interval) then
error('Interval is not a number: ' .. tostring(args.interval))
else
for y = begin_year, (end_year or os.date('%Y')+args.interval),
args.interval do
processYear(y)
end
end
return hlist(valueUnion(absences, appearances))
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {parentOnly=true})
return p._main(args)
end
return p