پودمان:Team appearances list
این پودمان آمادهٔ استفادهٔ عمومی ارزیابی شدهاست. این پودمان به مرحلهای رسیدهاست که حفره و اشکال در آن وجود ندارد و امکان استفاده از آن هرکجا که لازم است وجود دارد. بهتر است از ویکیپدیا:تمرین و نمونههای آزمایشی الگو جای آزمون و خطا استفاده شود. |
This module implements {{Team appearances list}}. Check there for usage documentation.
Modules[ویرایش]
خطا
ناتوان در خواندن ویکیمتن از «پودمان:Team appearances list/show/تمرین».
پودمان:Team appearances list is invoked by {{Team appearances list}} to display a ویکیپدیا:شیوهنامه/دسترسیپذیری 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 پودمان: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).
پودمان: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 رده:صفحههای دارای خطاهای اسکریپتی.
-- This module implements [[Template:Team appearances list]].
local p = {}
local lang = mw.getContentLanguage() -- to convert numbers to persian
local num_con = require('Module:Numeral converter').convert
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.
if not data_competitions then
frame = frame or mw.getCurrentFrame()
local sandbox = mw.ustring.find(frame:getTitle(), 'تمرین', 1, true) and '/تمرین' or ''
local datamod = mw.loadData('پودمان:Team appearances list/data' .. sandbox)
data_competitions = datamod.competitions
data_old_names = datamod.old_names
end
end
local function strip_to_nil(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) == 'string' then
text = mw.ustring.match(text, '(%S.-)%s*$')
end
return text
end
local function make_options(args)
-- Return table of options from validated args or throw error.
local options = {}
local function valid_integer(name, min, max, is_optional)
local arg = args[name]
if arg == nil or arg == '' then
if is_optional then
return nil
end
error('پارامتر ' .. name .. ' وارد نشدهاست')
end
arg = tonumber(num_con('en', arg))
if type(arg) ~= 'number' then
error('پارامتر ' .. name .. ' رقم نیست')
end
if math.floor(arg) ~= arg then
error('پارامتر ' .. name .. ' عدد صحیح نیست')
end
if not (min <= arg and arg <= max) then
error('پارامتر ' .. name .. ' معتبر نیست')
end
return arg
end
local function valid_text(name)
local arg = args[name]
if arg == nil or arg == '' then
error('پارامتر ' .. name .. ' وارد نشدهاست')
end
if type(arg) ~= 'string' then
error('پارامتر ' .. name .. ' رشته نیست')
end
return arg
end
options.competition = valid_text('competition')
options.team = valid_text('team')
-- Check ROC/TPE
if options.team=='جمهوری چین' then
local pageYear = mw.getContentLanguage():parseFormattedNumber(mw.ustring.match(mw.title.getCurrentTitle().text, '[%d]+')) -- mw.title.getCurrentTitle().text:match('^%d+')
if pageYear and pageYear > 1950 and pageYear < 1980 then
options.team = 'چین تایپه'
end
end
-- end of ROC/TPE check
options.competitions = data_competitions[options.competition] or data_competitions[data_old_names[options.competition]]
local begin_optional
if options.competitions then
begin_optional = true
else
options.interval = valid_integer('interval', 1, 30)
end
options.begin_year = valid_integer('begin_year', 1800, 2100, begin_optional)
options.end_year = valid_integer('end_year', 1800, 2100, true)
if options.begin_year and options.end_year then
if options.begin_year > options.end_year then
error('مقدار پارامتر end_year نباید پیش از مقدار begin_year باشد')
end
end
options.disqualified_year = valid_integer('disqualified_year', 1800, 2100, true)
return options
end
local function extract_range(text)
-- Return first (if text is a single year), or first, last if a range.
-- The returned values are numbers.
-- Return nothing if text is invalid.
local year = mw.getContentLanguage():parseFormattedNumber(mw.ustring.match(text, '^(%d+)$'))
if year then
if #year == 4 then
return mw.getContentLanguage():parseFormattedNumber(year)
end
return
end
local first, dash, last = mw.getContentLanguage():parseFormattedNumber(mw.ustring.match(text, '^(%d+)(%D+)(%d+)$'))
if not (first and #first == 4) then
return
end
dash = strip_to_nil(dash)
if not (dash == '-' or dash == '–') then
return
end
if #last ~= 4 then
if #last == 2 then
last = mw.ustring.sub(first, 1, 2) .. last
else
return
end
end
first = mw.getContentLanguage():parseFormattedNumber(first)
last = mw.getContentLanguage():parseFormattedNumber(last)
if first < last then
return first, last
elseif first == last then
return first
end
end
local function competition_absences(data)
-- Return two tables with absent years and absent year ranges.
-- Parameter data is an array of strings from template parameters, or
-- numbers or strings from built-in data.
-- Parameters that are blank or not numbers or strings are ignored.
local absent_years, absent_ranges = {}, {}
for _, item in ipairs(data) do
if type(item) == 'number' then
absent_years[item] = true
else
item = strip_to_nil(item)
if type(item) == 'string' then
local first, last = extract_range(item)
if not first then
error('سال ' .. item .. ' نامعتبر است')
end
if last then
table.insert(absent_ranges, {first, last})
else
absent_years[first] = true
end
end
end
end
return absent_years, absent_ranges
end
local function competition_information(args)
-- Return four tables with competition and team information:
-- * List of competition years that the team attended or could have attended.
-- * Table of disqualified 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)
local absences
local comp_years = {}
local begin_year = options.begin_year
local end_year = options.end_year
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
for _, y in ipairs(competitions) do
if y > end_year then
break
elseif y >= begin_year then
table.insert(comp_years, y)
end
end
else
end_year = end_year or (os.date('!*t').year + options.interval)
for y = begin_year, end_year, options.interval do
table.insert(comp_years, y)
end
end
local disqualified_years = {}
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" or inputName=="مسابقات جهانی دو و میدانی" then
if year <= 2017 then
return "مسابقات قهرمانی جهان دو و میدان"
else
return "مسابقات جهانی دو و میدانی"
end
elseif (inputName=="British Empire Games"
or inputName=="British Empire and Commonwealth Games"
or inputName=="British Commonwealth Games"
or inputName=="Commonwealth Games"
or inputName=="بازیهای کشورهای همسود"
or inputName=="بازیهای مشترکالمنافع"
or inputName=="بازیهای امپراتوری بریتانیا"
or inputName=="بازیهای امپراتوری بریانیا و مشترکالمنافع") then
if year <= 1950 then
return "بازیهای امپراتوری بریتاینا"
elseif year <= 1966 then
return "بازیهای امپراتوری بریتانیا و کشورهای همسود"
elseif year <= 1974 then
return "بازیهای کشورهای همسود بریتانیا"
else
return "بازیهای کشورهای همسود"
end
elseif inputName=="Southeast Asian Peninsular Games" or inputName=="Southeast Asian Games" or inputName == "بازیهای شبهجزیرههای آسیای جنوب شرقی" then
if year <= 1975 then
return "بازیهای شبهجزیرههای آسیای جنوب شرقی"
else
return "بازیهای آسیای جنوب شرقی"
end
elseif inputName=="Asian Indoor Games" or inputName=="Asian Indoor and Martial Arts Games" or inputName == "بازیهای آسیایی داخل سالن" then
if year <= 2009 then
return "بازیهای آسیایی داخل سالن"
else
return "بازیهای آسیایی داخل سالن و هنرهای رزمی"
end
elseif inputName=="Southern Cross Games" or inputName=="South American Games" or inputName == "بازیهای آمریکای جنوبی" then
if year <= 1982 then
return "بازیهای چندورزشی جنوبی"
else
return "بازیهای آمریکای جنوبی"
end
elseif inputName=="All-Africa Games" or inputName=="African Games" or inputName == "بازیهای آفریقایی" then
if year <= 2011 then
return "بازیهای سراسری آفریقا"
else
return "بازیهای آفریقایی"
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" or inputName == "اسواتینی" or inputName == "سوازیلند" then
if year < 2018 or year == 2018 and comp == 'Commonwealth Games' then
return "سوازیلند"
else
return "اسواتینی"
end
elseif inputName=="Southern Rhodesia" or inputName=="Rhodesia" or inputName=="Zimbabwe" or inputName == "رودزیای جنوبی" or inputName == "رودزیا" or inputName == "زیمبابوه" then
if year < 1980 then
if (comp=="British Empire Games"
or comp=="British Empire and Commonwealth Games"
or comp=="British Commonwealth Games"
or comp=="Commonwealth Games"
or comp=="بازیهای امپراتوری بریتانیا"
or comp=="بازیهای مشترکالمنافع"
or comp=="بازیهای کشورهای همسود") then
return "رودزیای جنوبی"
elseif comp=="Summer Olympics" or comp=="Summer Paralympics" or comp=="بازیهای المپیک تابستانی" or comp=="بازیهای پارالمپیک تابستانی" then
return "رودزیا"
end
else
return "زیمبابوه"
end
elseif (inputName=="Republic of China"
or inputName=="Formosa"
or inputName=="Taiwan"
or inputName=="Chinese Taipei"
or inputName=="جمهوری چین"
or inputName=="فرموسا"
or inputName=="فورموسا"
or inputName=="تایوان"
or inputName=="چین تایپه") then
if year <= 1956 or year == 1972 or year == 1976 then
return "جمهوری چین"
elseif year==1960 then
return "جمهوری چین (فورموسا)"
elseif year==1964 or year==1968 then
return "تایوان"
elseif year > 1976 then
return "چین تایپه"
end
elseif inputName=="Northern Rhodesia" or inputName=="Zambia" or inputName=="روزیای شمالی" or inputName=="زامبیا" then
if year <= 1964 then
return "روزیای شمالی"
else
return "زامبیا"
end
elseif inputName=="Aden" or inputName=="South Arabia" or inputName=="Federation of South Arabia" or inputName=="عدن" or inputName=="عربستان جنوبی" or inputName=="فدراسیون عربستان جنوبی" then
if year < 1966 then
return "عدن"
else
return "عربستان جنوبی"
end
elseif inputName=="British Guiana" or inputName=="Guyana" or inputName=="گویان بریتانیا" or inputName=="گویان" then
if year < 1966 then
return "گویان بریتانیا"
else
return "گویان"
end
elseif inputName=="Tanzania" or inputName=="Tanganyika" or inputName=="تانزانیا" or inputName=="تانگانیکا" then
if year < 1966 then
return "تانگانیکا"
else
return "تانزانیا"
end
elseif inputName=="Ceylon" or inputName=="Sri Lanka" or inputName=="سیلان" or inputName=="سریلانکا" then
if year <= 1972 then
return "سیلان"
else
return "سریلانکا"
end
elseif inputName=="British Honduras" or inputName=="Belize" or inputName=="هندوراس بریتانیا" or inputName=="بلیز" then
if year <= 1973 then
return "هندوراس بریتاینا"
else
return "بلیز"
end
elseif inputName=="Dahomey" or inputName=="Benin" or inputName=="داهومی" or inputName=="بنین" then
if year <= 1975 then
return "داهومی"
else
return "بنین"
end
elseif inputName=="Upper Volta" or inputName=="Burkina Faso" or inputName=="ولتای علیا" or inputName=="بورکینافاسو" then
if year <= 1983 then
return "ولتای علیا"
else
return "بورکینافاسو"
end
elseif inputName=="Burma" or inputName=="Myanmar" or inputName=="برمه" or inputName=="میانمار" then
if year < 1990 then
return "برمه"
else
return "میانمار"
end
elseif inputName=="Germany" or inputName=="West Germany" or inputName=="آلمان" or inputName=="آلمان غربی" then
if comp == "Summer Paralympics" or comp == "Winter Paralympics" or comp == "بازیهای پارالمپیک تابستانی" or comp == "بازیهای پارالمپیک زمستانی" then
if year < 1992 then
return "آلمان غربی"
else
return "آلمان"
end
end
elseif inputName=="Democratic Republic of the Congo" or inputName=="Zaire" or inputName=="جمهوری دموکراتیک کنگو" or inputName=="زئیر" then
if year >= 1984 and year <=1996 then
return "زئیر"
else
return "جمهوری دموکراتیک کنگو"
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"
or inputName=="ورزشکاران مستقل در بازیهای المپیک"
or inputName=="شرکتکنندگان مستقل در بازیهای المپیک"
or inputName=="ورزشکاران مستقل المپیک") then
if year == 1992 or year==2014 then
return "شرکتکنندگان مستقل المپیک"
elseif year == 2000 then
return "ورزشکاران انفرادی المپیک"
elseif year == 2012 or year==2016 then
return "ورزشکاران مستقل المپیک"
elseif year == 2018 then
return "ورزشکاران المپیک اهل روسیه"
elseif year == 2020 or year==2022 then
return "ورزشکاران کمیته المپیک روسیه"
else
return inputName
end
elseif inputName=="Serbia and Montenegro" or inputName=="FR Yugoslavia" or inputName=="صربستان و مونتهنگرو" or inputName=="جمهوری فدرال یوگسلاوی" then
if year < 2004 then
if comp == "Mediterranean Games" or comp == "بازیهای مدیترانه" then
return "جمهوری فدرال یوگسلاوی"
else
return "یوگسلاوی"
end
else
return "صربستان و مونتهنگرو"
end
elseif (inputName=="Refugee Olympic Team"
or inputName=="IOC Refugee Olympic Team"
or inputName=="تیم پناهندگان در بازیهای المپیک"
or inputName=="تیم پناهندگان") then
if year == 2016 then
return "تیم پناهندگان"
elseif year == 2020 then
return "تیم پناهندگان کمیته بینالمللی المپیک"
else
return inputName
end
elseif (inputName=="Independent Paralympic Participants"
or inputName=="Individual Paralympic Athletes"
or inputName=="Independent Paralympic Athletes"
or inputName=="RPC"
or inputName=="Neutral Paralympic Athletes"
or inputName=="ورزشکاران بیطرف المپیک") then
if year == 1992 then
return "شرکتکنندگان بیطرف پارالمپیک"
elseif year == 2000 then
return "ورزشکاران انفرادی پارالمپیک"
elseif year==2016 then
return "ورزشکاران مستفل پارالمپیک"
elseif year==2018 then
return "ورزشکاران بیطرف پارالمپیک"
elseif year == 2020 or year==2022 then
return "ورزشکاران کمیته پارالمپیک روسیه"
else
return inputName
end
elseif inputName=="North Macedonia" or inputName=="Macedonia" or inputName=="مقدونیه شمالی" or inputName=="مقدونیه" then
if year < 2019 then
return "مقدونیه"
else
return "مقدونیه شمالی"
end
elseif inputName=="Malaysia" or inputName=="Malaya" or inputName=="مالزی" or inputName=="مالایا" then
if year < 1963 then
return "مالایا"
else
return "مالزی"
end
end
return inputName
end
function p._main(args)
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
return true
end
for _, range in ipairs(absent_ranges) do
if range[1] <= y and y <= range[2] then
return true
end
end
return false
end
local appearances = {}
local absent_first, absent_last
for i = 1, #competitions + 1 do -- +1 to handle any trailing absences
local y = competitions[i]
if y and is_absent(y) then
if absent_first then
absent_last = y
else
absent_first = y
end
else
if absent_first then
table.insert(appearances,
'<span style="color:gray">' ..
(absent_last and (lang:formatNum(absent_first, {noCommafy=true}) .. '–' .. lang:formatNum(absent_last, {noCommafy=true})) or lang:formatNum(absent_first, {noCommafy=true})) ..
'</span>')
absent_first, absent_last = nil, nil
end
if y then
local display = tostring(lang:formatNum(y, {noCommafy=true}))
if y > current_year then
display = '<i>' .. display .. '</i>'
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 == 'مسابقات جهانی اسکی آلپاین' then
table.insert(appearances, mw.ustring.format(
'[[%s در %s %s|%s]]',
teamOut, compName, lang:formatNum(y, {noCommafy=true}), display
))
else
table.insert(appearances, mw.ustring.format(
'[[%s در %s %s|%s]]',
teamOut, compName, lang:formatNum(y, {noCommafy=true}), display
))
end
end
end
end
return hlist(appearances)
end
function p.main(frame)
load_data(frame)
return p._main(frame.args['team'] and frame.args or frame:getParent().args)
end
return p