Aller au contenu

Module:Infobox/Équipe cycliste

Une page de Wikipédia, l'encyclopédie libre.

 Documentation[voir] [modifier] [historique] [purger]

Cette page définit un module d'infobox. Pour les conseils sur l'usage de ce module, voyez Modèle:Infobox Équipe cycliste.


local wikidata = require "Module:Wikidata"
local general = require "Module:Infobox/Fonctions"
local sports = require "Module:Infobox/Fonctions/Compétition sportive"
local linktopic = '-'

local function getFormerNames( item )
	local claims =  wikidata.getClaims{
		property = vals,
		entity = item,
		property = 'P1448',
		rank = 'valid',
		sorttype = 'chronological'
	}
	if not claims then
		return nil
	end
	local names, periods = {}, {}
	for i, val in pairs(claims) do
		table.insert(names, wikidata.formatStatement(val))
		table.insert(periods, wikidata.getFormattedDate(val, {linktopic = '-', precision = 'day'}))
	end
	return names, periods
end

local function formerNamesTable( localdata ) -- retourne une table de lignes contenant les anciens noms de l'équipe
	local names, periods = localdata['ancien_nom'], localdata['saison']
	if names then
		names =  mw.text.split(names, '<br />')
		periods = mw.text.split(periods or '', '<br />')
	else
		names, periods = getFormerNames( localdata.item )
	end
	if not names then
		return nil
	end
	local rows = {}
	for i, period in pairs(periods) do
		table.insert( rows, {type = 'row', label = period, value = function () return names[i] end})	
	end
	local title = 'Dénominations'
	if #names == 1 then
		title = 'Dénomination'
	end
	return {type = 'table', title = title, rows = rows}
end

local function firstValue(QID, PID, field)
	local ss = mw.wikibase.getAllStatements(QID, PID)
	for _, s in pairs(ss) do
		if s.rank ~= 'deprecated' and s.mainsnak.snaktype == 'value' then
			return field and s.mainsnak.datavalue.value[field] or s.mainsnak.datavalue.value
		end
	end
end

function countseason(item)
	local str, creationDateyear, disparitionDateyear
	local creationDate=firstValue(item,'P571','time')
	local disparitionDate = firstValue(item,'P576','time')
	if creationDate~=nil and disparitionDate~=nil then
		local creationDateyear=string.sub(creationDate, 2, 5)
		local disparitionDateyear=string.sub(disparitionDate, 2, 5)
		str= tostring(disparitionDateyear- creationDateyear+1)
	else
		local seasons = wikidata.getClaims{entity = item, property = 'P527'}
		if not seasons then
			return nil
		end
	    str = tostring(#seasons)
	end
	str = wikidata.addLinkBack(str, item, 'P527')
	str = str .. wikidata.addTrackingCat('P527')
	return str
end	

return {
	maincolor = '#FFDF80',
	parts = {
		general.title('cyclisme'),
		general.mainimage('Article à illustrer Équipe cycliste'),
		{type = 'table', title = 'Informations', rows = {
			sports.typeofteam,
			{
				type = 'row',
				label = function ( localdata )
					local claims = wikidata.getClaims{property = 'P1998', entity = localdata.item}
					if (not claims) or #claims == 1 then
						return "Code UCI"
					end
					return "Codes UCI"
				end,
				value = 'code',
				wikidata = function ( item )
					local claims = wikidata.getClaims{
						entity = item,
						property = 'P1998',
						conjtype = '<br />',
						sorttype = 'chronological',
						rank = 'valid'
					}
					if not claims then
						return nil
					end
					local conjtype,textformat = '<br />', 'long'
					if #claims > 4 then
						conjtype, textformat = 'comma', 'long'
					end
					return wikidata.formatAndCat{
						entity = item,
						property = 'P1998',
						showdate = true,
						textformat = textformat,
						linktopic = '-',
						rank = 'valid'
					}
				end
			},
			{type = 'row', label = 'Discipline', value = 'discipline', property = 'P641'},
			function ( localdata ) -- affichage du pays, avec les dates seulement s'il y en a plus qu'1
				local c = wikidata.getClaims{entity = localdata.item, property = 'P17', rank = 'valid'}
				if not c then
					return nil
				elseif c == 1 then
					return general.country{rank = 'valid', sorttype = 'chronological'}
				else
					return general.country{rank = 'valid', sorttype = 'chronological', showdate = true}
				end
			end,
			{type = 'row', label = 'Création', value = 'creation', property = 'P571'},
			{type = 'row', label = 'Disparition', value = 'disparition', property = 'P576'},
			{
				type = 'row',
				label = 'Saisons',
				value = 'saisons',
				wikidata = function ( item ) -- suppose que P527 ne contienne que des saisons, et contienne toutes les saisons
					return countseason(item)
				end,
			},
			{type = 'row', label = 'Budget', value = 'budget', wikidata = {
				property = 'P2769',
				separator = '<br />',
				rank = 'valid',
				showdate = true
			}},
			{type = 'row', label = 'Sponsor', singularlabel = 'Sponsor', plurallabel = 'Sponsors', property = 'P859'},
			{type = 'row', label = 'Marque de cycles', value = 'velo'},
		}},
		{type = 'table', title = 'Encadrement', rows = {
			{type = 'row', label = 'Directeur général', value = 'manager_gén', wikidata = {
				property = 'P505',
				conjtype = '<br />',
				showdate = true,
				linktopic = linktopic
			}},
			{type = 'row', label = 'Directeur technique', value = 'dir_tech'},
			{
				type = 'row',
				label = 'Directeur(s) sportif(s)',
				singularlabel = 'Directeur sportif',
				plurallabel = 'Directeurs sportifs',
				value = function ( localdata )
					local vals = {}
					for i = 1, 10 do
						local dir = localdata['ds' .. tostring(i)]
						if dir then
							table.insert(vals, dir)
						end
					end
					if #vals > 0 then
						return table.concat(vals, '<br />')
					end
				end,
				wikidata = {
					property = 'P286',
					conjtype = '<br />',
					showdate = true,
					linktopic = linktopic
				}
			},
			{type = 'row', label = 'Soigneur', value = 'sg1'},
			{type = 'row', label = 'Médecin', value = 'medecin'},
		}},
		formerNamesTable,
	}
}