Modul:Country alias: Versiyalar orasidagi farq

Oʻzbekcha Vikipediyadan import qilindi.
 
flagXYZ tezyurar satr ulanishiga (string concatenation) o'tkazildi va optimallashtirildi
 
( Bitta oraliq tahrir bir xil foydalanuvchi tomonidan koʻrsatilmagan)
Qator 196: Qator 196:


local data = mw.loadData('Module:Country alias/data')
local data = mw.loadData('Module:Country alias/data')
local aliasCache = {}
local function countryAlias(args)
local function countryAlias(args)
local cacheKey = tostring(args.alias) .. '_' .. tostring(args.year) .. '_' .. tostring(args.games) .. '_' .. tostring(args.flag)
if aliasCache[cacheKey] then
return aliasCache[cacheKey]
end
local alias = getAlias(args)
local alias = getAlias(args)
local country = data.countries[alias] or data.countries[data.countryAliases[alias]]
local country = data.countries[alias] or data.countries[data.countryAliases[alias]]
Qator 205: Qator 210:
return quit('Invalid country alias: ' .. tostring(alias))
return quit('Invalid country alias: ' .. tostring(alias))
end
end
local res
if yes(args.flag) then
if yes(args.flag) then
return getFlag(args, country) or quit('No flag defined for ' .. alias)
res = getFlag(args, country) or quit('No flag defined for ' .. alias)
else
else
return country.name or quit('No name defined for ' .. alias)
res = country.name or quit('No name defined for ' .. alias)
end
end
aliasCache[cacheKey] = res
return res
end
end


Qator 245: Qator 253:


local function flagXYZ(frame)
local function flagXYZ(frame)
-- Implement {{flagIOC2}} and its variants which previously called this module three times.
local args = (frame.args and frame.args[1] and frame.args) or frame:getParent().args
-- Returns one of four possible outputs:
-- from flagIOC2: <flag> <country link> <athletes>, with the third value optional
-- from flagIOC2team: <flag> <country link> <country alias>
-- from flagIOC2athlete: <flag> <athlete(s)> <country alias/link>
-- from flagIOC2medalist: <athlete(s)><br><flag> <country link>
local args = frame:getParent().args
local dispType = stripToNil(frame.args['type'])
local dispType = stripToNil(frame.args['type'])
local code=''
local code=''
Qator 257: Qator 259:
local athletes=''
local athletes=''
if dispType == 'athlete-O' then
if dispType == 'athlete-O' then
-- Implement [[Template:FlagIOCathlete]].
dispType = 'athlete'
dispType = 'athlete'
args[3] = (args[3] or '') .. 'Olimpiada'
args[3] = (args[3] or '') .. 'Olimpiada'
Qator 270: Qator 271:
games = stripToNil(args[3]) or error('Parameter 3 should be a competition name')
games = stripToNil(args[3]) or error('Parameter 3 should be a competition name')
end
end
 
local parms = {
local parms = {
alias = code,
alias = code,
Qator 285: Qator 286:
if dispType == 'team' then dispType = 'name' end
if dispType == 'team' then dispType = 'name' end
end
end
 
local flag = countryAlias(parms)
local disp = dispName or fullName
if dispType == 'name' then
if dispType == 'name' then
return (('[[Fayl:{flag}|22x20px|border|alt=|link=]]&nbsp;[[{name} {games}|{dispName}]]{athletes}')
local ath = athletes and ('&nbsp;<span style="font-size:90%;">(' .. athletes .. ')</span>') or ''
:gsub('{(%w+)}', {
return '[[Fayl:' .. flag .. '|22x20px|border|alt=|link=]]&nbsp;[[' .. fullName .. ' ' .. games .. '|' .. disp .. ']]' .. ath
athletes = athletes and
('&nbsp;<span style="font-size:90%;">(' .. athletes .. ')</span>') or
'',
flag = countryAlias(parms),
games = games,
name = fullName,
dispName = dispName or fullName,
}))
elseif dispType == 'team' then
elseif dispType == 'team' then
return (('[[Fayl:{flag}|22x20px|border|alt=|link=]]&nbsp;[[{name} {games}|{dispName}]]{alias}')
return '[[Fayl:' .. flag .. '|22x20px|border|alt=|link=]]&nbsp;[[' .. fullName .. ' ' .. games .. '|' .. disp .. ']]&nbsp;<span style="font-size:90%;">(' .. code .. ')</span>'
:gsub('{(%w+)}', {
alias = ('&nbsp;<span style="font-size:90%;">(' .. code .. ')</span>'),
flag = countryAlias(parms),
games = games,
name = fullName,
dispName = dispName or fullName,
}))
elseif dispType == 'athlete' then
elseif dispType == 'athlete' then
return (('[[Fayl:{flag}|22x20px|border|alt=|link=]]&nbsp;{athletes}&nbsp;<span style="font-size:90%;">([[{name} {games}|{dispName}]])</span>')
return '[[Fayl:' .. flag .. '|22x20px|border|alt=|link=]]&nbsp;' .. athletes .. '&nbsp;<span style="font-size:90%;">([[' .. fullName .. ' ' .. games .. '|' .. code .. ']])</span>'
:gsub('{(%w+)}', {
athletes = athletes,
flag = countryAlias(parms),
games = games,
name = fullName,
dispName = code,
}))
elseif dispType == 'medalist' then
elseif dispType == 'medalist' then
return (('{athletes}<br>[[Fayl:{flag}|23x15px|border|alt=|link=]]&nbsp;[[{name} {games}|{dispName}]]')
return athletes .. '<br>[[Fayl:' .. flag .. '|23x15px|border|alt=|link=]]&nbsp;[[' .. fullName .. ' ' .. games .. '|' .. disp .. ']]'
:gsub('{(%w+)}', {
athletes = athletes,
flag = countryAlias(parms),
games = games,
name = fullName,
dispName = dispName or fullName,
}))
end
end
end
end