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 Footballeur.


local p = {}
local wd = require "Module:Wikidata"
local countrymod = require "Module:Country data"
local frame = mw.getCurrentFrame()

function p._teams(teamtype, headers)

	-- récup des données
	local claims = wd.getClaims{
		rank = 'valid',
		property = 'P54',
		sorttype = 'chronological',
		condition = function(claim)
			local v = wd.getMainId(claim)
			return wd.isInstance(teamtype, v, 3)
			end,
	}
	if not claims then
		return nil
	end
	
	-- Création de la table et des en-têtes
	local tab = mw.html.create("")
	local tab1 = mw.html.create("tr")
	headers = headers or {"Saisons", "Clubs", "M (B.)[[Category:Page utilisant P54]]"}

	for i, j in pairs(headers) do
		tab1:tag("th"):wikitext(j):done()
	end
	tab:node(tab1):done()

	-- Intégration des données
	local function cleanLabel(id)
		local label = wd.getLabel(id)
		if not label then
			return nil
		end
		local patterns = {
			["[Éé]quipe de?s?'?u? ?"] = "",
			["des moins de "] = "-",
			["de soccer"] = "",
			["de football"] = "",
			[" féminine "] = " fém. ",
			["[Aa]ssociation [Ff]ootball [Cc]lub"] = "AFC",
			["[Ff]ootball [Cc]lub ?d?e?u?'?"] = "FC ",
			["Sporting Clube? ?d?e?u?"] = "SC ",
			["Sports Club"] = "SC",
			["Club Atlético "] = "CA ",
			["Club Deportivo "] = "CD ",
			["Associação Atlética "] = "AA ",
			["Futebol Clube"] = "FC",
			["Fútbol Club"] = "FC",
			["Associação Desportiva "] = "AD ",
			["Clube Desportivo "] = "CD ",
			["Club de Deportes "] = "CD ",
			["Association Sportive ?d?e?u?'?"] = "AS ",
			["Associazione Sportiva ?d?e?u?'?"] = "AS ",
			["Union Sportive ?d?e?u?'?"] = "US ",
			["Unione Sportiva ?d?e?u?'?"] = "US ",
		}
		for i, j in pairs(patterns) do
			label = mw.ustring.gsub(label, i, j)	
		end
		return label
	end

	for i, j in pairs(claims) do
		local teamid = wd.getMainId(j)
		
		local period = wd.getFormattedDate(j, {precision = 'year', textformat = 'infobox', linktopic = 'football'})
		local matches = wd.getFormattedQualifiers(j, {'P1350'})
		local goals = wd.getFormattedQualifiers(j, {'P1351'})
		local condition = wd.getFormattedQualifiers(j, {'P1642'})
		
		local teamname = wd.formatEntity(teamid, {labelformat = function(id) return cleanLabel(teamid) end} )
		local atdate = wd.getFormattedQualifiers(j, {'P580'}, {displayformat = 'raw'})  -- date en forme -- pour adapter le drapeau en fonction de la date
		local teamcountry = wd.formatStatements{entity = teamid, property = 'P1532', displayformat = 'raw'} -- nationalité sportive de l'équipe, pour le drapeau (sélection)
		if teamcountry == nil then -- si pas de nationalité sportive, on cherche le pays (cas général)
			teamcountry = wd.formatStatements{entity = teamid, property = 'P17', displayformat = 'raw'}
		end
		if teamcountry == "Q145" then -- si pays=Royaume-Uni, on cherche la zone opérationnelle du championnat du club, pour adapter le drapeau
			local championnat = wd.formatStatements{entity = teamid, property = 'P118', displayformat = 'raw', numval = 1}
			local zone = wd.formatStatements{entity = championnat, property = 'P2541', displayformat = 'raw', numval = 1}
			if zone ~= nil then
			    teamcountry = zone
			end
		end	
		local flag = countrymod.standarddisplay(teamcountry, {label = '-', date = atdate or 'default'}) or ''
		local formattedteam = flag .. ' ' .. teamname
		if condition then
			if string.find (condition, 'prêt') then
				formattedteam = frame:expandTemplate{ title = 'prêt'} .. ' ' .. formattedteam
			else
				formattedteam = formattedteam .. ' <small>(' .. condition .. ')</small>'
			end
		end
		local stats = matches
		if stats and goals then
			goals = mw.text.trim(goals) -- bug d'affichage dans Module:Wikidata apparemment
				stats = stats .. "&nbsp;(" .. goals .. ")"
		end
		
		tab :tag('tr')
				:tag('td'):addClass('data'):wikitext(period):done()
				:tag('td'):addClass('data'):wikitext(formattedteam):done()
				:tag('td'):addClass('data'):cssText( 'white-space:nowrap; text-align:center'):wikitext(stats):done()
			:done()
	end
	
	return tostring(tab)
end

function p.teams(frame) -- pour les clubs de football uniquement ce serait Q476028, mais en attendant que wikidata soit complétement parfait...
	return p._teams('Q847017')
end

function p.selections(frame) -- pour les sélections géographiques
	return p._teams('Q6979593', {"Années", "Sélection", "M&nbsp;(B.)"})
end

return p