Module:Infobox/Espace public

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


-- luacheck: globals mw, no max line length

local localdata = require 'Module:Infobox/Localdata'
local general = require "Module:Infobox/Fonctions"
local building = require "Module:Infobox/Fonctions/Bâtiment"
local wikidata = require "Module:Wikidata"
local wd = require "Module:Wikidata"
local linguistic = require "Module:Linguistique"
--local convert = require "Module:Conversion" -- UNUSED
local country = wikidata.stringTable{entity = localdata.item, property = "P17", displayformat = "raw"}
local countryid
if country then
	countryid = country[1]
end

local defaultlinks = { -- version de Wikipédia à utiliser pour les liens en l'absence d'article français
	Q17 = 'jawiki', -- Japon
	Q182 = 'dewiki', -- Allemagne
	Q40 = 'dewiki',	-- Autriche
	Q38 = 'itwiki', -- Italie
	Q41 = 'elwiki', -- Grèce
	Q29 = 'eswiki', -- Espagne
	Q96 = 'eswiki', -- Mexique
	Q739 = 'eswiki', -- Colombie
	Q717 = 'eswiki', -- Vénézuéla
	Q298 = 'eswiki', -- Chili
	Q414 = 'eswiki', -- Argentine
	Q750 = 'eswiki', -- Bolivie
	Q736 = 'eswiki', -- Équateur
	Q45 = 'ptwiki', -- Portugal
	Q155 = 'ptwiki', -- Brésil
	Q43 = 'trwiki', -- Turquie
	Q881 = 'viwiki', -- Viêt Nam
	Q29999 = 'nlwiki', -- Pays-Bas
	Q34 = 'svwiki', -- Suède
	Q148 = 'zhwiki', -- République populaire de Chine
	Q865 = 'zhwiki', -- Taïwan
	Q668 = 'hiwiki', -- Inde
	Q843 = 'hiwiki', -- Pakistan
}
local defaultlink = {'enwiki'}
if defaultlinks[countryid] then
	table.insert(defaultlink, defaultlinks[countryid])
end


-- UNUSED
--[[
local function getVal(addargs) -- pour une propriété donnée, retourne la meilleure valeur, ainsi que sa date, sa référence, et si ça vient ou non de Wikidata
	local args = {numval = 1, entity = localdata.item, showunit = '-', displayformat = 'raw', precision = 'year'}
	for i, j in pairs(addargs or {}) do
		args[i] = j
	end
	local statements = wikidata.getClaims(args)
	if not statements then
		return nil
	end
	local val = statements[1]
	local v = wikidata.formatStatement(val, args)
	local period = wikidata.getFormattedDate(val, args)
	local ref = nil -- TODO : fonction dans Module:Wikidata pour récupérer les refs

	return v, period, ref, args.property
end
--]]

-- divisions amdinistratives

--- par paramètres locaux
local function localDivRows() -- liste de lignes de divisions administrative basée sur des données locales
	local rows = {}
	local hasrows = false -- devient vraie si une valeur est non null
	for i = 1, 10 do
		i = tostring(i)
		if i == "1" then
			i = ""
		end
		local param, labelparam = "division" .. i, "nom division" .. i --"nom de division" .. i
		if localdata[param] then
			hasrows = true
			local label = localdata[labelparam] or "Subdivision"
			table.insert(rows, {type = "row", label = label, value = function() return localdata[param] end})
		end
	end
	if hasrows then
		return rows
	end
end

--- par Wikidata
local function wikidataDivRows()  -- liste de lignes de divisions administrative basée sur des données de Wikidata
	if not localdata.item then
		return nil
	end
	-- récupération des valeurs
	local list = wikidata.transitiveVals(localdata.item, {property = "P131", atdate = "today", excludespecial = true}, 3, 5, countryid)
	if not list then
		return nil
	end

	-- création des colonnes
	local rows = {}
	for i, div in pairs(list) do
		if (div == countryid) then
			break
		end
		local rowlabel, rowlabelid, rowlabeltext, rowlabellink, rowvalue
		rowlabelid = wikidata.formatStatements{entity= div, property = 'P31', numval = 1, displayformat = 'raw', excludespecial = true}
		rowlabeltext = wikidata.getLabel(rowlabelid)
		if rowlabeltext then
			-- imposé par les libellés pas très logiques sur Wikidata du genre "canton de Suisse" plutôt que "canton"
		    rowlabeltext = linguistic.ucfirst(linguistic.removecomplement(rowlabeltext))
		end
		if not rowlabeltext or rowlabeltext == '' then
		    rowlabeltext = 'Division'
		end
		rowlabellink = wikidata.siteLink(rowlabelid, {defaultlink = '-', defaultlinkquery= {property = "P2354"}} ) -- si pas de lien, lier vers la page de liste e.g liste des Etats de Californie

		if rowlabellink then
			rowlabel = "[[" .. rowlabellink .. "|" .. rowlabeltext .. "]]"
		else
			rowlabel = rowlabeltext
		end
		rowvalue = wikidata.formatEntity(div, {labelformat = function(id)
			local str = wikidata.getLabel(id) or ""
			if mw.ustring.match(rowlabel, str) then
				str = linguistic.keepcomplement(str)-- si le nom de la division administrative affiché est présent, ne pas le répéter
			end
			return str
			end})

		table.insert(rows, 1, {type = "row", label = rowlabel, value = function() return rowvalue end})
	end
	return rows
end

--========================================

local formats = {
	--{icône carte, icône entete, couleur titre, couleur sous-titre, couleur texte)
	Q174782 = {'monument', nil, '#ECE5CA', '#ECE5CA', '#000000', 'defaut'}, -- place
	default = {'defaut', nil, '#ECE5CA', '#ECE5CA', '#000000', 'defaut'}
}

local function wdformat() --retourne une table contenant la couleur principale de l'infobox et l'icône de titre
	local wtypes = wd.stringTable{ -- récupère les Qid des types d'espaces spécifiques
		entity = localdata.item,
		property = 'P31',
		displayformat = 'raw',
		excludespecial = true
	}
	local default = formats.default
	wtypes = wd.addVals(wtypes or {}, {property = 'P279'}, 1) -- on utilise en plus les sous-classe
	for i, item in pairs(wtypes or {}) do
		if formats[item] then
			return formats[item]
		end
	end
	return default
end
local function setcharte()
	local charte = localdata['charte']
	if charte then
		for i, j in pairs(formats) do
			if j[2] == charte then
				return j
			end
		end
	end
	return wdformat()
end

local displayformat = setcharte()

return
	{
	maincolor = displayformat[3],
	secondcolor = displayformat[4],
	thirdcolor = displayformat[5],
	parts =
		{
			general.title(displayformat[2], nil, 'nom local', nil),
			general.logo(),
			building.mainimage('Article à illustrer Monument'),
			{type = 'table', title = 'Situation', rows = {
general.country(),
				{type = "multi", rows = localDivRows() or wikidataDivRows() or {}},
				building.coordinates(),
				--{type = 'row', label = 'Destination initiale', value = 'destination initiale'},
				--{type = 'row', label = 'Destination actuelle', value = 'destination actuelle'},
				--{type = 'row', label = 'Rattachement', value = 'rattachement'},
				--{type = 'row', label = 'Dédicataire', plurallabel = 'Dédicataires', value = 'dédicataire', property = 'P825', showsource = true},
				--{type = 'row', label = 'Commémore', value = 'commémore', property = 'P547', showsource = true},
				{type = 'row', label = 'Extrémité', plurallabel = 'Extrémités', value = {'extrémités'}, property = 'P559', showsource = true},
				{type = 'row', label = 'Début', value = {'début', 'tenant'}, showsource = true},
				{type = 'row', label = 'Fin', value = {'fin', 'aboutissant'}, showsource = true},
				--building.archistyle(),
				--building.material(),
				--{type = 'row', label = 'Commanditaire', value = 'commanditaire', property = 'P88', showsource = true},
				--building.religion(),
				--{type = 'row', label = 'Occupant', plurallabel = 'Occupants', value = 'occupant', wikidata = {property = 'P466', showdate = true}, showsource = true},
				--building.owner(),
				building.usage('fonction'),
				--{type = 'row', label = 'Franchit', property = 'P177', showsource = true},
				--{type = 'row', label = 'Précédent franchissement en amont', property = 'P2673', showsource = true},
				--{type = 'row', label = 'Prochain franchissement en aval', property = 'P2674', showsource = true},
				--{type = 'row', label = 'Permet de faire passer', property = 'P2505', showsource = true},
				--building.operator(),

				{type = 'row', label = "[[Office de tourisme|Informations]]", value = "informations", wikidata = {property = 'P2872', numval = '3'}, showsource = true},
				building.visitors(),
				building.website('site', 'site web'),
				}
			},

			{type = 'table', title = 'Morphologie', rows = {
				{type = 'row', label = 'Type', value = 'type', blockers = {'destination initiale', 'destination finale'}, wikidata = {property = 'P31', excludevalues = {'Q41176', 'Q811979' }}, showsource = true},
				{type = 'row', label = 'Forme', value = 'forme'},
				building.dimensions(),
				{type = 'row', label = 'Altitude', value = 'altitude', wikidata = {property = 'P2044', targetunit = 'metre', conjtype = ' ou ', rounding = '0'}, showsource = true},
				{type = 'row', label = 'Emplacement', value = 'emplacement', wikidata = {property = 'P706', numval = '1'}, showsource = true},
				}
			},
			{type = 'table', title = 'Histoire', rows = {
				building.creator(),
				building.construction('dates'),
				building.opening(),
				building.reconstruction(),
				building.relocation(),
				building.renovation(),
				building.demolition(),
				{type = 'row', label = 'Date de début', value = {'dates'}, property = 'P580', showsource = true},
				{type = 'row', label = 'Date de fin', value = {'dates2'}, property = 'P582', showsource = true},
				{type = 'row', label = 'Nom précédent', plurallabel = 'Noms précédents', value = 'noms'},
				{type = 'row', label = 'Surnom', plurallabel = 'Surnoms', value = 'surnom'},
				{type = 'row', label = 'Nom complet', value = 'nom complet'},
				{type = 'row', label = 'Lieu', plurallabel = 'Lieux', value = 'lieux'},
				{type = 'row', label = 'Monument', plurallabel = 'Monuments', value = 'monuments'},
				building.protection('classement'),
				building.protectedarea(),
				},
			},
			building.unesco(),
			{type = 'table', title = 'Accès et transport', rows = {
				building.transport(),
				}
			},
			general.geoloc({marker=displayformat[1], default_zoom=12}),
	}
}