Modulo:Giochi olimpici
Questo è un modulo scritto in Lua. Le istruzioni che seguono sono contenute nella sottopagina Modulo:Giochi olimpici/man (modifica · cronologia)
Sandbox: Modulo:Giochi olimpici/sandbox (modifica · cronologia) · Sottopagine: lista · Test: Modulo:Giochi olimpici/test (modifica · cronologia · esegui)
Modulo che implementa i template {{EdizOlimp}} e {{Link Giochi olimpici}}.
Ha una sottopagina di configurazione:
in cui si possono definire tutte le varie edizioni dei Giochi olimpici, sia estivi che invernali, paralimpici e giovanili.
--[[
* Modulo che implementa i template EdizOlimp e Link Giochi olimpici.
]]--
require('strict')
local getArgs = require('Modulo:Arguments').getArgs
local cfg = mw.loadData('Modulo:Giochi olimpici/Configurazione')
local errorCategory = '[[Categoria:Voci con errori del modulo Giochi olimpici]]'
local p = {}
local function errhandler(msg)
local cat = mw.title.getCurrentTitle().namespace == 0 and errorCategory or ''
return string.format('<span class="error">%s</span>%s', msg, cat)
end
local function getTable(tipo, stagione)
local ret
if tipo == 'G' then
ret = stagione == 'I' and cfg.giochi_olimpici_giovanili_invernali or cfg.giochi_olimpici_giovanili_estivi
elseif tipo == 'P' then
ret = stagione == 'I' and cfg.giochi_paralimpici_invernali or cfg.giochi_paralimpici_estivi
else
ret = stagione == 'I' and cfg.giochi_olimpici_invernali or cfg.giochi_olimpici_estivi
end
return ret
end
local function getAnno(tbl, edizione)
local ret
for key, val in pairs(tbl) do
if val.e == edizione then
ret = key
break
end
end
return ret
end
local function formatTarget(disciplina, specialita, anno, edizione, stagione, tipo)
local target
if disciplina then
local prep = 'ai'
if (stagione == 'I' or tipo == 'P') and (edizione == 'VIII' or edizione == 'XI') then
prep = 'agli'
end
disciplina = string.format('%s %s ', disciplina, prep)
else
disciplina = ''
end
if tipo == 'G' then
target = string.format('%s Giochi olimpici giovanili %s',
edizione, stagione == 'I' and 'invernali' or 'estivi')
elseif tipo == 'P' then
target = string.format('%s Giochi paralimpici %s',
edizione, stagione == 'I' and 'invernali' or 'estivi')
else
if stagione == 'I' then
target = string.format('%s Giochi olimpici invernali', edizione)
else
if anno == '1906' then
target = 'Giochi olimpici intermedi'
else
target = string.format('Giochi della %s Olimpiade', edizione)
end
end
end
specialita = specialita and (' - ' .. mw.language.getContentLanguage():ucfirst(specialita)) or ''
return disciplina .. target .. specialita
end
function p._edizOlimp(args)
local ret
-- args[3] e args[4] sono opzionali, per indicare estivi/invernali e paralimpici/giovanili
if args[1] and args[2] then
local field, anno_ediz, stagione, tipo = args[1], args[2], args[3], args[4]
local tbl = getTable(tipo, stagione)
local anno = tonumber(anno_ediz) and anno_ediz or getAnno(tbl, anno_ediz)
if anno and tbl[anno] then
ret = field == 'a' and anno or tbl[anno][field]
else
error('Anno o edizione non esistente', 2)
end
end
return ret
end
function p._getWlink(args)
local ret
-- args[2] obbligatorio, args[1] può essere vuoto
if args[2] then
local disciplina, anno, stagione, tipo = args[1], args[2], args[3], args[4]
local tbl = getTable(tipo, stagione)
local citta
anno = tonumber(anno) and anno or getAnno(tbl, anno)
if tbl[anno] then
citta = tbl[anno].c .. (tbl[anno].c2 and ' ' .. tbl[anno].c2 or '')
end
if tbl[anno] and not mw.ustring.find(citta, '(non disputat', 1, true) then
if args.formatting == 'label' then
ret = string.format('%s %s', citta, anno)
elseif args.formatting == 'target' then
ret = formatTarget(disciplina, args['specialità'], anno, tbl[anno].e, stagione, tipo)
elseif args.formatting == 'città_paese' then
local linkCitta1 = string.format('[[%s|%s]]', tbl[anno].d, tbl[anno].c)
local linkPaese1 = string.format('[[%s]]', tbl[anno].p)
local linkCitta2 = tbl[anno].c2 and string.format('[[%s|%s]]', tbl[anno].d2, tbl[anno].c2) or nil
local linkPaese2 = tbl[anno].p2 and string.format('[[%s]]', tbl[anno].p2) or nil
if linkCitta2 and linkPaese2 and linkPaese2 ~= linkPaese1 then
ret = string.format('%s, %s e %s, %s', linkCitta1, linkPaese1, linkCitta2, linkPaese2)
elseif linkCitta2 then
ret = string.format('%s e %s, %s', linkCitta1, linkCitta2, linkPaese1)
else
ret = string.format('%s, %s', linkCitta1, linkPaese1)
end
else
ret = string.format('[[%s|%s %s]]',
formatTarget(disciplina, args['specialità'], anno, tbl[anno].e, stagione, tipo),
citta, anno)
end
elseif args.errore == 'sì' then
error('Anno o edizione non esistente', 2)
else
ret = string.format("''%s - Nessuna %s %s%s''", args[2],
tipo == 'P' and 'Paralimpiade' or 'Olimpiade',
tipo == 'G' and 'giovanile ' or '',
stagione == 'I' and 'invernale' or 'estiva')
end
end
return ret
end
-- Entry-point per {{EdizOlimp}}
function p.EdizOlimp(frame)
return select(2, xpcall(function()
return p._edizOlimp(getArgs(frame, {parentOnly = true}))
end, errhandler))
end
-- Entry-point per {{Link Giochi olimpici}}
function p.Link_Giochi_olimpici(frame)
return select(2, xpcall(function()
return p._getWlink(getArgs(frame, {parentOnly = true}))
end, errhandler))
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.