Modul:Country alias: Versiyalar orasidagi farq

Country alias modulida memoizatsiya (keshlash) qo'shildi (CPU vaqt chegarasidan oshib ketishni oldini olish)
flagXYZ tezyurar satr ulanishiga (string concatenation) o'tkazildi va optimallashtirildi
 
Qator 253: 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 265: 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 278: 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 293: 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