-- This module returns the country name or the flag name for a country,-- based on the three-letter IOC/CGA/FINA alias.
--
local function stripToNil(text) -- If text is a string, return its trimmed content, or nil if empty. -- Otherwise return text (which may, for example, be nil). if type(text)
local function yes(parameter) -- Return true if parameter should be interpreted as "yes". return [parameter]end
local function getAlias(args) -- Return alias parameter, possibly modified for exceptional cases. local alias = stripToNil(args.alias) local games = stripToNil(args.games) local year = tonumber(args.year) local fullName = stripToNil(args.fullName) if fullName then year = tonumber(fullName:match('^%d+')) -- ignore args.year end if alias
'Commonwealth Games' then alias = 'ANG_CGF' end elseif alias
'Asian Indoor and Martial Arts Games' then alias = 'ART_AIMAG' end elseif alias
'World Championships in Athletics' or games
'European Athletics Championships' then alias = 'GBR_WCA' elseif games
2018 then alias = 'GBR_WCA' end end elseif alias
'Commonwealth Games' then alias = 'HKG_CGF' end elseif alias
2000 then alias = 'IOA_2000' end elseif alias
'MAS' then if year and year < 1963 then alias = 'MAL' else alias = 'MAS' end elseif alias
'MKD' then if year and year < 2019 then alias = 'MKD' else alias = 'MKD_2019' end elseif alias
'RUS' then if year and year
'Summer Olympics' then alias = 'ROC_2020' elseif games
2022 and games
'ROC' then if year and year
'Summer Olympics' then alias = 'ROC_Formosa' elseif year and (year
1968) and games
2020 and games
2022 and games
2020 and games
'Russian Olympic Committee athletes at the Olympics' then alias = 'ROC_2020' end end elseif alias
'SCG' then if year and year > 1992 and year < 2004 and games ~= 'Summer Paralympics' then alias = 'FR_YUG' end elseif alias
'COD' then if year and year < 1971 then alias = 'COK_COD' elseif year and year <= 1996 then alias = 'ZAI' else alias = 'COD' end elseif alias
1968 then alias = 'COK_COD' else alias = 'COK' end end return aliasend
local function getFlag(args, country) -- Return name of flag selected from country data (nil if none defined). local year = tonumber(args.year) local games = stripToNil(args.games) if games then local gdata = country[games] if gdata then if type(gdata)
'string' then return gdata[1] end end end for _, item in ipairs(country) do if type(item)
local data = mw.loadData('Module:Country alias/data')local function countryAlias(args) local alias = getAlias(args) local country = data.countries[alias] or data.countries[data.countryAliases[alias]] local function quit(message) return args.error or error(message) end if not country then return quit('Invalid country alias: ' .. tostring(alias)) end if yes(args.flag) then return getFlag(args, country) or quit('No flag defined for ' .. alias) else return country.name or quit('No name defined for ' .. alias) endend
local function flagIOC(frame) -- Implement which previously called this module three times. -- Returns
local function flagXYZ(frame) -- Implement and its variants which previously called this module three times. -- Returns one of four possible outputs: -- from flagIOC2:
'name' or dispType
'athlete' or dispType
'ROC' then fullName = 'Russian Olympic Committee athletes' dispName = 'ROC' if dispType
'name' then return ((' ') :gsub('',)) elseif dispType
'athlete' then return (('
') :gsub('',)) elseif dispTypereturn