Module:Infobox/Biographie/Bac à sable

 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 Biographie/Bac à sable.


local localdata = require 'Module:Infobox/Localdata'
local person = require 'Module:Infobox/Fonctions/Personne/Bac à sable'
local wd = require 'Module:Wikidata'
local linguistic = require 'Module:Linguistique'
local occupationformats = require 'Module:Infobox/Biographie/Chartes'

local function setformat() --retourne une table contenant la couleur principale de l'infobox et l'icône de titre
	local occupations = wd.getIds(localdata.item, {property = 'P106'}) -- récupère les Qid des professions

	if not occupations or (#occupations > 1) then -- si plusieurs occupations, on ne sait pas laquelle choisir
		return  {'Q', {'par défaut'}, '#EEEEFF', '#F6F6FF', '#000000', 'defaut'}
	end
	occupations = wd.addVals(occupations, {property = 'P279'}, 2) -- nombre d'étages de sous-classes à remonter
	for i, j in pairs(occupations) do
		for k, l in pairs(occupationformats) do
			local chartIds = l[1]
			if type(chartIds) == 'string' then chartIds = {chartIds} end
			if wd.isHere(chartIds,j) then
				return l --retourne une ligne de la table occupationformats, correspondant à l'occupation du sujet
			end
		end
	end
	return {'Q', {'par défaut'}, '#EEEEFF', '#F6F6FF', '#000000', 'defaut'}
end
local function setcharte()
	local charte = localdata['charte']
	if charte then
		for i, j in pairs(occupationformats) do
			local knowncharts = j[2]
			if type(knowncharts) == 'table' then
				if wd.isHere(knowncharts,charte) then
					return j
				end
			end
		end
	end
	return setformat()
end
local personformat = setcharte()

local function documentation()

	local lines = {}

	table.insert(lines , '{| class="wikitable sortable" style="width:100%"')
	table.insert(lines , '|-')
	table.insert(lines , '! style="width:10%" | Charte')
	table.insert(lines , '! style="width:10%" | Élément Wikidata')
	table.insert(lines , '! style="width:10%" | Valeur primaire<br />(fond titre)')
	table.insert(lines , '! style="width:10%" | Valeur secondaire<br />(sous-titre)')
	table.insert(lines , '! style="width:10%" | Valeur tertiaire<br />(texte titre)')
	table.insert(lines , '! style="width:10%" | Icône<br />([[Projet:Infobox/Pictogramme|liste]])')
	table.insert(lines , '! style="width:20%" | rendu titre')
	table.insert(lines , '! style="width:20%" | rendu sous-titre')
	
	table.sort(occupationformats, function (left, right)
	    return string.lower(left[2][1] or ''):gsub('é','e') < string.lower(right[2][1] or ''):gsub('é','e')
	end)

	table.insert(occupationformats, 1, {nil, nil, nil, nil, nil, nil})

	for i, j in pairs(occupationformats) do
		local wdsource = j[1] or {"Q"}
		if type(wdsource) == 'string' then wdsource = {wdsource} end
		local wd = table.concat(wdsource, ", ")
		local chartesource = j[2] or {"par défaut"}
		if type(chartesource) == 'string' then chartesource = {chartesource} end
		local charte = table.concat(chartesource or {}, ", ")
		local couleur1 = j[3] or '#CCCCAA'
		local couleur2 = j[4] or '#D1CFAD'
		local couleur3 = j[5] or '#000000'
		local icone = j[6] or ''

		local pict = ''
		if icone ~= '' and icone ~= 'defaut' then
			pict = mw.getCurrentFrame():extensionTag('templatestyles', '', {src = 'Infobox/Pictogramme/' .. mw.text.trim(icone) .. '.css'})
		end

		table.insert(lines , '|-')
		table.insert(lines , '! style="text-align:left;" | ' .. charte)
		table.insert(lines , '| style="text-align:center;" | ' .. wd)
		table.insert(lines , '| style="text-align:center;" | ' .. couleur1)
		table.insert(lines , '| style="text-align:center;" | ' .. couleur2)
		table.insert(lines , '| style="text-align:center;" | ' .. couleur3)
		table.insert(lines , '| style="text-align:center;" | ' .. icone)
		table.insert(lines , '| class="entete ' .. icone .. '" style="background-color:' .. couleur1 .. '; height:45px; text-align:center; font-size:150%; font-weight:bolder; color:' .. couleur3 .. ';" | titre ' .. pict)
		table.insert(lines , '| style="background-color:' .. couleur2 .. '; height:45px; text-align:center; font-size:150%; font-weight:bolder; color:#000000;" | sous-titre')
	end

	table.insert(lines , '|}')
	
	return table.concat(lines, "\n" )
end

--catégorisation par charte utilisée (qu'elle soit déclarée manuellement ou déduite de Wikidata)
local chartcatlabel = (personformat[2] or {})[1] or "par défaut"
chartcatlabel = "Article utilisant l'infobox Biographie2 avec la charte " .. chartcatlabel
local categories
if not mw.title.makeTitle('Catégorie', chartcatlabel ).exists then chartcatlabel = "Article utilisant l'infobox Biographie2 avec une charte sans catégorie" end

return {
	maincolor = personformat[3],
	secondcolor = personformat[4],
	thirdcolor = personformat[5],
	categories = {chartcatlabel},
	documentation = documentation,
	parts = {
		
		person.title(personformat[6]),
		person.mainimage(),
		person.officialposition(),
		person.specialrole(),
		person.nobilitytitle(),
		{type = 'table',title='Biographie',rows = {
			person.birth(),
			person.death(),
			person.placeofburial(),
			person.nativenames(),
			person.othernames(),
			{type = 'row', label = 'Époque', value = 'époque', wikidata = {property = 'P2348'}},
			person.nationality(),
			{type = 'row', label = 'Allégeance', plurallabel = 'Allégeances', value = 'allégeance', wikidata = {property = 'P945'}},
			person.places(),
			person.education(),
			person.occupation(),
			person.floruit(),
			person.writinglanguage(),
			person.haswrittenfor(),
			{
				type = 'row',
				label = 'Appartenance ethno-culturelle',
				plurallabel = 'Appartenances ethno-culturelles',
				value= 'ethnicité',
				wikidata = {
				-- ethnicité veut dire appartenance à une ethnie d'après [[Ethnie]]
				-- essai de expl=true qui est normalement fait pour données mises à jour 
				-- mais à utilité dans chaque article difficile à décider automatiquement
					property = 'P172',
					expl = true, 
					-- désactivé si la valeur est une instance de race humaine (Q3254959)
					condition = function(claim)
						local v = wd.getMainId(claim)
						return (not wd.isInstance('Q3254959', v, 2))
					end
				}
			},
			person.family(),
			person.gens(),
			person.slavery(),
		}},
		{type = 'table',title='Autres informations',rows = {
			{type = 'row', label = 'Organisation', plurallabel = 'Organisations', value = 'organisation', wikidata = {property = 'P1268', showdate = true}},
			person.employer(),
			{type = 'row', label = 'Chaire', plurallabel = 'Chaires', value = 'chaire', wikidata = {property = 'P803'}},
			{type = 'row', label = 'Domaine', plurallabel = 'Domaines', value = 'domaine'},  --l'appel à P101 doublonne généralement l'Activité 
			{type = 'row', label = 'Propriétaire de', value = 'propriétaire de', wikidata = {property = 'P1830', showdate = true, sorttype= 'chronological'}},
			person.religion(),
			person.politicalparty(),
			{type = 'row', label = 'Idéologie', value = 'idéologie', wikidata = {property = 'P1142'}},
			person.memberof(),
			{
				type = 'row',
				label = '[[Huit Bannières|Bannière]]',
				plurallabel = '[[Huit Bannières|Bannières]]',
				value = "bannière d'appartenance",
				wikidata = {
					property = 'P470',
					labelformat = function(id)
						local label = wd.getLabel(id)
						if label then
							return mw.ustring.gsub(label, '[Bb]annière ', '')
						end
					end
				}
 			},
			person.military(),
			person.movement(),
			person.appearance(),
			person.sport(),
			{type = 'row', label = 'Grade', plurallabel = 'Grades', value= {'grade dan/kyu','grade'}, wikidata = {property = 'P468', numval = '1', sorttype = 'inverted', showdate = true, precision = 'year', removedupes = true}},
			--{type = 'row',label = 'Commandement',plurallabel = 'Commandements',wikidata = {property = 'P598', sorttype= 'chronological', showdate = true, precision = 'year'},}, --propriété obsolète sur Wikidata
			--{type = 'row', label = 'A participé à', value = 'participant à', property = 'P1344'}, --risque de générer de longue listes sans grande pertinence
			person.torero(),
			person.music(),
			person.contacts(),
			{type = 'row', label = 'Monture', plurallabel= 'Montures', value= 'monture', wikidata = {property = 'P3091', showdate = true}},
			{type = 'row', label = 'Genre artistique', plurallabel= 'Genres artistiques', value= {'genre artistique','genre'}, wikidata = {property = 'P136'}},
			person.influencedby(),
			person.victims(),
			person.penalties(),
			{type = 'row', label = 'Adjectifs dérivés', value = 'adjectifs dérivés'},
			person.website(),
			{type = 'row', label = 'Blog officiel', value = 'blog officiel', wikidata={property = 'P1581' , conjtype = 'new line', showlang = true }},
			person.awards(),
			person.filmography(),
			person.discography(),
			{type = 'row', label = 'Abréviation en botanique', plurallabel = 'Abréviations en botanique', value = 'abréviation en botanique', wikidata={property = 'P428'}},
			{type = 'row', label = 'Abréviation en zoologie', plurallabel = 'Abréviations en zoologie', value = 'abréviation en zoologie', wikidata={property = 'P835'}},
			person.archivesat(),
			person.feast(),
		}},
		person.honorifictitle(),
		person.voice(),
		person.prononciation(),
		person.blason(),
		person.sceau(),
		person.monogram(),
		person.flag(),
		person.logo(),
		person.works{title = localdata['intitulé œuvres'] or localdata['intitulé oeuvres']},
		person.signature(),
		person.plaque(),
		person.tombe(),
	}
}