پودمان: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:

Errors ویرایش

Parameters provided by the template are validated using the following rules.

Always:    competition   required : non-empty string    team          required : non-empty stringIf 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 persianlocal num_con = require('Module:Numeral converter').convertlocal data_competitionslocal data_old_nameslocal function load_data(frame)-- Load data module (or its sandbox) and set variables from its exported data.if not data_competitions thenframe = 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.competitionsdata_old_names = datamod.old_namesendendlocal 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' thentext = mw.ustring.match(text, '(%S.-)%s*$')endreturn textendlocal 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 == '' thenif is_optional thenreturn nilenderror('پارامتر ' .. name .. ' وارد نشده‌است')endarg = tonumber(num_con('en', arg))if type(arg) ~= 'number' thenerror('پارامتر ' .. name .. ' رقم نیست')endif math.floor(arg) ~= arg thenerror('پارامتر ' .. name .. ' عدد صحیح نیست')endif not (min <= arg and arg <= max) thenerror('پارامتر ' .. name .. ' معتبر نیست')endreturn argendlocal function valid_text(name)local arg = args[name]if arg == nil or arg == '' thenerror('پارامتر ' .. name .. ' وارد نشده‌است')endif type(arg) ~= 'string' thenerror('پارامتر ' .. name .. ' رشته نیست')endreturn argendoptions.competition = valid_text('competition')options.team = valid_text('team')-- Check ROC/TPEif options.team=='جمهوری چین' thenlocal 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 thenoptions.team = 'چین تایپه'endend-- end of ROC/TPE checkoptions.competitions = data_competitions[options.competition] or data_competitions[data_old_names[options.competition]]local begin_optionalif options.competitions thenbegin_optional = trueelseoptions.interval = valid_integer('interval', 1, 30)endoptions.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 thenif options.begin_year > options.end_year thenerror('مقدار پارامتر end_year نباید پیش از مقدار begin_year باشد')endendoptions.disqualified_year = valid_integer('disqualified_year', 1800, 2100, true)return optionsendlocal 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 thenif #year == 4 thenreturn mw.getContentLanguage():parseFormattedNumber(year)endreturnendlocal first, dash, last = mw.getContentLanguage():parseFormattedNumber(mw.ustring.match(text, '^(%d+)(%D+)(%d+)$'))if not (first and #first == 4) thenreturnenddash = strip_to_nil(dash)if not (dash == '-' or dash == '–') thenreturnendif #last ~= 4 thenif #last == 2 thenlast = mw.ustring.sub(first, 1, 2) .. lastelsereturnendendfirst = mw.getContentLanguage():parseFormattedNumber(first)last = mw.getContentLanguage():parseFormattedNumber(last)if first < last thenreturn first, lastelseif first == last thenreturn firstendendlocal 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) doif type(item) == 'number' thenabsent_years[item] = trueelseitem = strip_to_nil(item)if type(item) == 'string' thenlocal first, last = extract_range(item)if not first thenerror('سال ' .. item .. ' نامعتبر است')endif last thentable.insert(absent_ranges, {first, last})elseabsent_years[first] = trueendendendendreturn absent_years, absent_rangesendlocal 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 absenceslocal comp_years = {}local begin_year = options.begin_yearlocal end_year = options.end_yearlocal competitions = options.competitionsif competitions thenabsences = competitions[options.team] or competitions[data_old_names[options.team]]begin_year = begin_year or (absences and absences.begin_year) or 0end_year = end_year or (absences and absences.end_year) or 9999for _, y in ipairs(competitions) doif y > end_year thenbreakelseif y >= begin_year thentable.insert(comp_years, y)endendelseend_year = end_year or (os.date('!*t').year + options.interval)for y = begin_year, end_year, options.interval dotable.insert(comp_years, y)endendlocal 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] = trueendreturn comp_years, disqualified_years, competition_absences(absences or args)endlocal 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=="مسابقات جهانی دو و میدانی" thenif year <= 2017 thenreturn "مسابقات قهرمانی جهان دو و میدان"elsereturn "مسابقات جهانی دو و میدانی"endelseif (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=="بازی‌های امپراتوری بریانیا و مشترک‌المنافع") thenif year <= 1950 thenreturn "بازی‌های امپراتوری بریتاینا"elseif year <= 1966 thenreturn "بازی‌های امپراتوری بریتانیا و کشورهای همسود"elseif year <= 1974 thenreturn "بازی‌های کشورهای همسود بریتانیا"elsereturn "بازی‌های کشورهای همسود"endelseif inputName=="Southeast Asian Peninsular Games" or inputName=="Southeast Asian Games" or inputName == "بازی‌های شبه‌جزیره‌های آسیای جنوب شرقی" thenif year <= 1975 thenreturn "بازی‌های شبه‌جزیره‌های آسیای جنوب شرقی"elsereturn "بازی‌های آسیای جنوب شرقی"endelseif inputName=="Asian Indoor Games" or inputName=="Asian Indoor and Martial Arts Games" or inputName == "بازی‌های آسیایی داخل سالن" thenif year <= 2009 thenreturn "بازی‌های آسیایی داخل سالن"elsereturn "بازی‌های آسیایی داخل سالن و هنرهای رزمی"endelseif inputName=="Southern Cross Games" or inputName=="South American Games" or inputName == "بازی‌های آمریکای جنوبی" thenif year <= 1982 thenreturn "بازی‌های چندورزشی جنوبی"elsereturn "بازی‌های آمریکای جنوبی"endelseif inputName=="All-Africa Games" or inputName=="African Games" or inputName == "بازی‌های آفریقایی" thenif year <= 2011 thenreturn "بازی‌های سراسری آفریقا"elsereturn "بازی‌های آفریقایی"endelsereturn inputNameendendlocal 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 == "سوازیلند" thenif year < 2018 or year == 2018 and comp == 'Commonwealth Games' thenreturn "سوازیلند"elsereturn "اسواتینی"endelseif inputName=="Southern Rhodesia" or inputName=="Rhodesia" or inputName=="Zimbabwe" or inputName == "رودزیای جنوبی" or inputName == "رودزیا" or inputName == "زیمبابوه" thenif year < 1980 thenif (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=="بازی‌های کشورهای همسود") thenreturn "رودزیای جنوبی"elseif comp=="Summer Olympics" or comp=="Summer Paralympics" or comp=="بازی‌های المپیک تابستانی" or comp=="بازی‌های پارالمپیک تابستانی" thenreturn "رودزیا"endelsereturn "زیمبابوه"endelseif (inputName=="Republic of China"or inputName=="Formosa"or inputName=="Taiwan"or inputName=="Chinese Taipei"or inputName=="جمهوری چین"or inputName=="فرموسا"or inputName=="فورموسا"or inputName=="تایوان"or inputName=="چین تایپه") thenif year <= 1956 or year == 1972 or year == 1976 thenreturn "جمهوری چین"elseif year==1960 thenreturn "جمهوری چین (فورموسا)"elseif year==1964 or year==1968 thenreturn "تایوان"elseif year > 1976 thenreturn "چین تایپه"endelseif inputName=="Northern Rhodesia" or inputName=="Zambia" or inputName=="روزیای شمالی" or inputName=="زامبیا" thenif year <= 1964 thenreturn "روزیای شمالی"elsereturn "زامبیا"endelseif inputName=="Aden" or inputName=="South Arabia" or inputName=="Federation of South Arabia" or inputName=="عدن" or inputName=="عربستان جنوبی" or inputName=="فدراسیون عربستان جنوبی" thenif year < 1966 thenreturn "عدن"elsereturn "عربستان جنوبی"endelseif inputName=="British Guiana" or inputName=="Guyana" or inputName=="گویان بریتانیا" or inputName=="گویان" thenif year < 1966 thenreturn "گویان بریتانیا"elsereturn "گویان"endelseif inputName=="Tanzania" or inputName=="Tanganyika" or inputName=="تانزانیا" or inputName=="تانگانیکا" thenif year < 1966 thenreturn "تانگانیکا"elsereturn "تانزانیا"endelseif inputName=="Ceylon" or inputName=="Sri Lanka" or inputName=="سیلان" or inputName=="سری‌لانکا" thenif year <= 1972 thenreturn "سیلان"elsereturn "سری‌لانکا"endelseif inputName=="British Honduras" or inputName=="Belize" or inputName=="هندوراس بریتانیا" or inputName=="بلیز" thenif year <= 1973 thenreturn "هندوراس بریتاینا"elsereturn "بلیز"endelseif inputName=="Dahomey" or inputName=="Benin" or inputName=="داهومی" or inputName=="بنین" thenif year <= 1975 thenreturn "داهومی"elsereturn "بنین"endelseif inputName=="Upper Volta" or inputName=="Burkina Faso" or inputName=="ولتای علیا" or inputName=="بورکینافاسو" thenif year <= 1983 thenreturn "ولتای علیا"elsereturn "بورکینافاسو"endelseif inputName=="Burma" or inputName=="Myanmar" or inputName=="برمه" or inputName=="میانمار" thenif year < 1990 thenreturn "برمه"elsereturn "میانمار"endelseif inputName=="Germany" or inputName=="West Germany" or inputName=="آلمان" or inputName=="آلمان غربی" thenif comp == "Summer Paralympics" or comp == "Winter Paralympics" or comp == "بازی‌های پارالمپیک تابستانی" or comp == "بازی‌های پارالمپیک زمستانی" thenif year < 1992 thenreturn "آلمان غربی"elsereturn "آلمان"endendelseif inputName=="Democratic Republic of the Congo" or inputName=="Zaire" or inputName=="جمهوری دموکراتیک کنگو" or inputName=="زئیر" thenif year >= 1984 and year <=1996 thenreturn "زئیر"elsereturn "جمهوری دموکراتیک کنگو"endelseif (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=="ورزشکاران مستقل المپیک") thenif year == 1992 or year==2014 thenreturn "شرکت‌کنندگان مستقل المپیک"elseif year == 2000 thenreturn "ورزشکاران انفرادی المپیک"elseif year == 2012 or year==2016 thenreturn "ورزشکاران مستقل المپیک"elseif year == 2018 thenreturn "ورزشکاران المپیک اهل روسیه"elseif year == 2020 or year==2022 thenreturn "ورزشکاران کمیته المپیک روسیه"elsereturn inputNameendelseif inputName=="Serbia and Montenegro" or inputName=="FR Yugoslavia" or inputName=="صربستان و مونته‌نگرو" or inputName=="جمهوری فدرال یوگسلاوی" thenif year < 2004 thenif comp == "Mediterranean Games" or comp == "بازی‌های مدیترانه" thenreturn "جمهوری فدرال یوگسلاوی"elsereturn "یوگسلاوی"endelsereturn "صربستان و مونته‌نگرو"endelseif (inputName=="Refugee Olympic Team" or inputName=="IOC Refugee Olympic Team"or inputName=="تیم پناهندگان در بازی‌های المپیک"or inputName=="تیم پناهندگان") thenif year == 2016 thenreturn "تیم پناهندگان"elseif year == 2020 thenreturn "تیم پناهندگان کمیته بین‌المللی المپیک"elsereturn inputNameendelseif (inputName=="Independent Paralympic Participants" or inputName=="Individual Paralympic Athletes" or inputName=="Independent Paralympic Athletes"or inputName=="RPC"or inputName=="Neutral Paralympic Athletes"or inputName=="ورزشکاران بی‌طرف المپیک") thenif year == 1992 thenreturn "شرکت‌کنندگان بی‌طرف پارالمپیک"elseif year == 2000 thenreturn "ورزشکاران انفرادی پارالمپیک"elseif year==2016 thenreturn "ورزشکاران مستفل پارالمپیک"elseif year==2018 thenreturn "ورزشکاران بی‌طرف پارالمپیک"elseif year == 2020 or year==2022 thenreturn "ورزشکاران کمیته پارالمپیک روسیه"elsereturn inputNameendelseif inputName=="North Macedonia" or inputName=="Macedonia" or inputName=="مقدونیه شمالی" or inputName=="مقدونیه" thenif year < 2019 thenreturn "مقدونیه"elsereturn "مقدونیه شمالی"endelseif inputName=="Malaysia" or inputName=="Malaya" or inputName=="مالزی" or inputName=="مالایا" thenif year < 1963 thenreturn "مالایا"elsereturn "مالزی"endendreturn inputNameendfunction p._main(args)load_data()  -- in case this function is called by another modulelocal hlist = require('Module:List').horizontallocal competitions, disqualified_years, absent_years, absent_ranges = competition_information(args)local current_year = os.date('!*t').yearlocal function is_absent(y)if absent_years[y] thenreturn trueendfor _, range in ipairs(absent_ranges) doif range[1] <= y and y <= range[2] thenreturn trueendendreturn falseendlocal appearances = {}local absent_first, absent_lastfor i = 1, #competitions + 1 do  -- +1 to handle any trailing absenceslocal y = competitions[i]if y and is_absent(y) thenif absent_first thenabsent_last = yelseabsent_first = yendelseif absent_first thentable.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, nilendif y thenlocal display = tostring(lang:formatNum(y, {noCommafy=true}))if y > current_year thendisplay = '<i>' .. display .. '</i>'endif disqualified_years[y] thendisplay = '<del>' .. display .. '</del>'endlocal compName = gameName(y, args.competition)local teamOut = teamName(y, args.team, args.competition)if compName == 'مسابقات جهانی اسکی آلپاین' thentable.insert(appearances, mw.ustring.format('[[%s در %s %s|%s]]',teamOut, compName, lang:formatNum(y, {noCommafy=true}), display))elsetable.insert(appearances, mw.ustring.format('[[%s در %s %s|%s]]',teamOut, compName, lang:formatNum(y, {noCommafy=true}), display))endendendendreturn hlist(appearances)endfunction p.main(frame)load_data(frame)return p._main(frame.args['team'] and frame.args or frame:getParent().args)endreturn p