Module:Bac à sable
Ceci est le bac à sable de modèle.
Cette page permet d'effectuer des modifications du code sans provoquer de perturbations.
Utilisation[modifier le code]
Cette page est destinée à vous aider à vous familiariser avec le système de création et modification de modules de Wikipédia.
Il est possible de tester le résultat de votre module dans la page Modèle:Bac à sable (placez-y le code {{#invoke:Bac à sable|nom_fonction|arg1|arg2|…}}
).
Vous pouvez consulter le Manuel de référence complet en français sur www.mediawiki.org, Projet:Scribunto/Guide, aide:module, ou discuter avec les autres membres du projet Scribunto.
Voir les statistiques d'utilisation du module sur l'outil wstat.
La documentation de ce module est générée par le modèle {{Documentation module}}.
Elle est incluse depuis sa sous-page de documentation. Veuillez placer les catégories sur cette page-là.
Les éditeurs peuvent travailler dans le bac à sable (créer).
local wd = require 'Module:Wikidata'
local n2t = require 'Module:Nombre2texte'
local flagsData = require 'Module:Drapeau/Data'
local flagsDomaine = require "Module:Drapeau/Domaine"
local cs = {}
local function getFlag(id)
-- drapeau non liste TODO
--if id == '83286' or id=='36704' or id=='33946' or id=='15180' then
-- id=1751472
--end
c = flagsData.data[tonumber(id)]
if c== nil then
mw.log("Country id " .. id .. ' unknow')
return '<span class="flagicon">[[Image:Flag of None.svg|20px]]</span>'
end
return '<span class="flagicon">[[Fichier:' .. c['flag'] .. '|20px|border|Drapeau: ' .. c['label'] .. '|class=noviewer|alt=Drapeau ' .. flagsDomaine.genre[c['genre']]['du'] .. c['label'] .. ']]</span>'
end
local function getMedal(rank, medalType)
rank = tonumber(rank)
medalMetal = {
'Gold ',
'Silver ',
'Bronze '
}
altText = {
'd\'or ',
'd\'argent ',
'de bronze'
}
medalTypeText = {
JP = 'Jeux paralympiques',
JO = 'Jeux olympiques',
JM = 'Jeux méditerranéens',
Af = 'Afrique',
As = 'Asie',
Am = 'Amérique',
Eu = 'Europe',
Oc = 'Océanie',
CA = 'Amérique centrale',
NA = 'Amérique du Nord',
SA = 'Amérique du Sud',
AO = 'Asie Océanie',
PA = 'Pacifique Asie',
CM = 'Coupe du Monde',
Mo = 'Monde',
Au = 'Australie',
N = 'Numéro',
}
medalTypeTextEn = {
JP = 'medal Paralympics',
JO = 'medal olympic',
JM = 'MedGames',
Af = 'medal africa',
As = 'medal asia',
Am = 'medal america',
Eu = 'medal europe',
Oc = 'medal Oceania',
CA = 'medal centralamerica',
NA = 'medal northamerica',
SA = 'medal southamerica',
AO = 'medal Asia&Oceania',
PA = 'medal Asia&Oceania',
CM = 'medal world centered-2',
Mo = 'medal world centered-2',
Au = 'medal australia',
N = 'medal icon',
}
file= '[[Fichier:' .. medalMetal[rank] .. medalTypeTextEn[medalType] .. '.svg|16px|Médaille ' .. altText[rank] .. ', ' .. medalTypeText[medalType] .. '|alt=Médaille ' .. altText[rank] .. ', ' .. medalTypeText[medalType] .. '|link=]]'
return '<span data-sort-value="'.. rank ..'">'.. file ..'</span>'
end
local function getSportColor(rank)
color = {
'#F7F6A8',
'#DCE5E5',
'#FFDAB9'
}
return color[tonumber(rank)]
end
--function cs.tableauPalmares()
function cs.tableauPalmares(frame)
if 1 == 0 then
medalType = 'Mo'
id = 'Q205570'
teamId = 'Q728491'
else
args = frame.args
medalType = args['médaille']
id = args['championnat']
teamId = args['équipe']
end
teamCountryId = wd.getClaims({property = {'P17'}, entity = teamId})[1]['mainsnak']['datavalue']['value']['id']
championships = wd.getClaims({property = {'P527'}, entity = id})
championshipsLabel = wd.getLabel(id)
result = '{| class="wikitable" style="text-align: center;" \n'
result = result .. '|+ [[' .. championshipsLabel .. '|'.. championshipsLabel:gsub(" masculin", ""):gsub(" féminin", ""):gsub(" de handball", "") .. ']]\n'
result = result .. '! scope="col"| Édition\n'
result = result .. '! scope="col"| Rang\n'
result = result .. '! scope="col"| Participants\n'
for i in pairs(championships) do
-- browse championships
championshipId = championships[i]['mainsnak']['datavalue']['value']['id']
championshipLabel = wd.getLabel(championshipId)
--mw.log(championshipLabel)
-- check if qualifier ordinal exists
valid = 0
for ii in pairs(championships[i]['qualifiers']) do
if ii == 'P1545' then
valid = 1
end
end
if valid == 1 then
championship = wd.getClaims({property = {'P31', 'P17', 'P587', 'P1132', 'P1923'}, entity = championshipId})
rank = -1
flag = ''
nbPart = 0
for j in pairs(championship) do
if championship[j]['mainsnak']["property"] == "P17" then
-- host
countryId = championship[j]['mainsnak']['datavalue']['value']['id']
-- for multi host
if flag ~= '' then
flag = flag .. '/'
end
flag = flag .. getFlag(countryId:sub(2))
elseif championship[j]['mainsnak']["property"] == "P1132" then
nbPart = championship[j]['mainsnak']['datavalue']['value']['amount']:sub(2)
elseif championship[j]['mainsnak']["property"] == "P1923" then
-- teams
if championship[j]['mainsnak']['datavalue']['value']['id'] == teamId then
rank = 0
for data in pairs(championship[j]) do
if data == 'qualifiers' then
for property in pairs(championship[j]['qualifiers']) do
if property == 'P1352' then
-- rank
rank = championship[j]['qualifiers']['P1352'][1]['datavalue']['value']['amount']:sub(2)
end
end
end
end
end
end
end
-- for future championship todo
if flag == '' then
flag = getFlag('0')
end
-- check special case for podiums
if rank == '1' or rank == '2' or rank == '3' then
result = result .. '|- bgcolor=' .. getSportColor(rank) .. '\n'
else
result = result .. '|-\n'
end
-- ]]--
if teamCountryId == countryId then
result = result .. '| style="border: 3px solid red"|' .. flag .. ' [[' .. championshipLabel .. '|'.. championshipLabel:gsub(championshipsLabel, '') .. ']]\n'
else
result = result .. '| ' .. flag .. ' [[' .. championshipLabel .. '|'.. championshipLabel:gsub(championshipsLabel, '') .. ']]\n'
end
-- check special case for medals
if rank == '1' or rank == '2' or rank == '3' then
result = result .. '| ' .. getMedal(rank, medalType) .. '\n'
result = result .. '| ' .. nbPart .. '\n'
elseif rank == 0 then
result = result .. '|colspan=2|<i>Qualifié</i>\n'
elseif rank == -1 then
result = result .. '|colspan=2 style="background: #ececec; color: grey; vertical-align: middle; text-align: center;"| <small><i>non qualifié</i></small>\n'
else
result = result .. '| ' .. n2t.ordinal(rank) .. '\n'
result = result .. '| ' .. nbPart .. '\n'
end
end
end
result = result .. '|}\n'
return result
end
return cs