Module:Infobox/Espace public

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 Espace public.


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"
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
	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
	Q881 = 'viwiki', -- Viêt Nam
	Q29999 = 'nlwiki', -- Pays-Bas
	Q34 = 'svwiki', -- Suède
}
local defaultlink = {'enwiki'}
if defaultlinks[countryid] then
	table.insert(defaultlink, defaultlinks[countryid])
end


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, 'fr', function(id) 
			local str = wikidata.getLabel(id)
			if str then
				return linguistic.ucfirst(linguistic.removecomplement(str))  -- imposé par les libellés pas très logiques sur Wikidata du genre "canton de Suisse" plutôt que "canton"		else
			end
				return ''
			end
		)
		if (not 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 = 'Civilisation', plurallabel = 'Civilisations', value = 'civilisation', property = 'P2596'},
				--{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'},
				--{type = 'row', label = 'Commémore', value = 'commémore', property = 'P547'},
				{type = 'row', label = 'Début', value = {'début', 'tenant'}},
				{type = 'row', label = 'Fin', value = {'fin', 'aboutissant'}},
				--building.archistyle(),
				--building.material(),
				--{type = 'row', label = 'Commanditaire', value = 'commanditaire', property = 'P88'},
				--building.religion(),
				--{type = 'row', label = 'Occupant', plurallabel = 'Occupants', value = 'occupant', wikidata = {property = 'P466', showdate = true}},
				--building.owner(),
				building.usage(),
				--{type = 'row', label = 'Franchit', property = 'P177'},
				--{type = 'row', label = 'Précédent franchissement en amont', property = 'P2673'},
				--{type = 'row', label = 'Prochain franchissement en aval', property = 'P2674'},
				--{type = 'row', label = 'Permet de faire passer', property = 'P2505'},
				--building.operator(),

				{type = 'row', label = "[[Office de tourisme|Informations]]", value = "informations", wikidata = {property = 'P2872', numval = '3'}},
				--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' }}},
				{type = 'row', label = 'Forme', value = 'forme'},
				building.dimensions(),
				{type = 'row', label = 'Longueur', value = 'longueur', wikidata = {property = 'P2043', targetunit = 'metre', conjtype = ' ou ', rounding = '0'}},
				{type = 'row', label = 'Largeur', value = 'largeur', wikidata = {property = 'P2049', targetunit = 'metre', conjtype = ' ou ', rounding = '0'}},
				{type = 'row', label = 'Superficie', value = 'superficie', wikidata = {property = 'P2046', targetunit = 'metre', conjtype = ' ou ', rounding = '0'}},
				{type = 'row', label = 'Altitude', value = 'altitude', wikidata = {property = 'P2044', targetunit = 'metre', conjtype = ' ou ', rounding = '0'} },
				{type = 'row', label = 'Emplacement', value = 'emplacement', wikidata = {property = 'P706', numval = '1'}},
				--building.mountainrange(),
				--building.onshoreof(),
				--building.watershed(),
				}
			},
			{type = 'table', title = 'Histoire', rows = {
				building.creator(),
				building.construction('dates'),
				building.opening(),
				building.reconstruction(),
				building.relocation(),
				building.renovation(),
				building.demolition(),
				{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(),
				building.unesco(),
				building.protectedarea(),
				},
			},
			{type = 'table', title = 'Accès et transport', rows = {
				building.transport(),
				}
			},
			general.geoloc({marker=displayformat[1], default_zoom=12}),
	}
}