Moduuli:Fr:Infobox/Fonctions/Bâtiment

Wikimatkoista

local p = {}
local localdata = require( 'Module:Fr:Infobox/Localdata' )
local item = localdata.item
local wd = require( 'Module:Fr:Interface Wikidata' ).fromLua
local general = require 'Module:Fr:Infobox/Fonctions'
local linguistic = require "Module:Fr:Linguistique"
local address = require "Module:Fr:Adresse"

local function keydate(event)
	return wd.keyDate(event, item)
end

local function inclexcl(statement) -- formatte les qualificatifs "P518" / "P1011" (à mettre plutôt dans un sous module de Module:Fr:Wikidata, comme pour les dates ?
	local str = wd.formatSnak(statement.mainsnak)
	if not statement.qualifiers then
		return str
	end
	local incl = wd.getFormattedQualifiers(statement, "P518")
	local excl = wd.getFormattedQualifiers(statement, "P1011")

	if incl then
		str = str .. linguistic.inparentheses(incl .. " y compris") -- pas la formulation la plus élégante mais elle évite les problèmes d'accord grammaticaux
	end
	if excl then
		str = str .. linguistic.inparentheses("sans " .. excl) -- pas la formulation la plus élégante mais elle évite les problèmes d'accord grammaticaux
	end
	return str
end

function p.creatorQuery(prop) 
	return {
		property = prop,
		entity = localdata.item,
		showqualifiers = {'P518'},
		showdate = true,
		qualiflink = '-',
		statementformat = function(statement)
			
			local str
			-- On commence par les qualificatifs (attibué à, atelier etc.)
			local possiblequalifiers = {
				P1773 = "attribué $to $creator", 
				P1774 = "atelier $of $creator",
				P1775 = "suiveur $of $creator",
				P1776 = "cercle $of $creator",
				P1777 = "d'après $creator", -- TODO : d'après LE Maître X
				P1778 = "faux d'après $creator",
				P1779 = "$creator (?)",
				P1780 = "école $orégf",
				P1877 = "d'après un œuvre $of",
			}
	
			if statement.qualifiers then
				for qualif, text in pairs(possiblequalifiers) do
					local creator = wd.getFormattedQualifiers(statement, {qualif})
					if creator then
						str = text
						str = mw.ustring.gsub(str, '$to $creator', "à ".. creator)
						str = mw.ustring.gsub(str, '$of $creator', linguistic.of(creator))
						str = mw.ustring.gsub(str, '$creator', creator)
						break
					end
				end
			end
						
			-- Sinon, la voie normale
			if not str then
				str = wd.formatStatement(statement, {speciallabels = {Q4233718 = "anonyme"}}) -- speciallabels pour éviter le lien par défaut
			end
			return str
		end
	}
end

--Titrest
function p.title()
	--	local class = en-tête par défaut à définir ici ?
	return general.title()
end

--Image
function p.mainimage(cat, defaultimage)
	if not cat then 
		cat = 'Article à illustrer Bâtiment divers'
	end
	return general.mainimage(cat, defaultimage)
end

function p.country()
	return -- déprécié	
end


function p.historicalregion()
	return nil -- paramètre région mis dans adminlocation() : le gens l'utilisent pour la région administrative plutôt que pour la région historique
end

function p.adminlocation() -- Fonction assez compliquée du fait des différences entre infobox. Simlifiable si on harmonise les infobox
	-- infobox à prendre en compte : bâtiment, gratte-ciel, gare, château

	local streetstr = localdata['osoite']
	local area = localdata['sijainti']
	local city = localdata['kunta'] 

	local div1 = localdata['subdivision'] or localdata['subdivision1']  or localdata['subdivision 1']
	local div2 = localdata['subdivision2'] or localdata['subdivision 2']
	local div3 = localdata['subdivision3'] or localdata['subdivision 3']
	local div4 = localdata['région']
	local citystr = linguistic.conj({area, city}, "comma") 
	local divstr = linguistic.conj({div1, div2, div3}, "comma")
	divstr = linguistic.conj({citystr, divstr, div4}, "new line") -- on fait plusieusr lignes différentes pour éviter que ce soit trop moches avec des drapeaux
	local country = localdata['valtio']

	
	local val = linguistic.ucfirst(address.fullAddress(localdata['item'], country, nil, streetstr, divstr ))
	return 
	{
		type = "row",
		label = "Sijainti",
		value = function() return val end
	}
end

function p.onshoreof()
	return {
		type = 'row',
		label = 'Vesistö',
		value = {'vesistö', 'rannalla'},
		wikidata = {property = 'P206', defaultlinkquery = {property = 'P361'}},
	}
end

function p.protectedarea()
	return {
		type = 'row',
		label = 'Suojelualue',
		plurallabel = 'Suojelualueet',
		value = {'suojelualue'},
		property = 'P3018',
	}
end

function p.elevation()
	return {
		type = 'row',
		label = 'Korkeus merenpinnasta',
		value = 'korkeus',
		wikidata = {property = 'P2044', targetunit = 'm', conjtype = ' tai ', rounding = '0', numval = '2'},
	}
end

function p.coordinates(args)
	return general.coordinates(args)
end

function p.website() 
	return general.website()
end

function p.construction()
	return {
		type = 'multi', 
		rows = {

			-- début construction, fin construction (legacy infobox Stade, Infobox Château),
			{
				type = 'row',
				value = {'début construction', 'début'}, 
				label = 'Construction', 
			},
			{
				type = 'row',
				value = {'fin construction', 'fin'}, 
				label = 'Fin de construction', 
			},

			-- construction (nom de paramètre "date de construction" à déprécier)
			{
				type = 'row',
				value = {'valmistumisvuosi', 'rakennettu', 'date de construction'}, 
				label = 'Valmistuminen', 
				wikidata = keydate{'Q385378', 'P571'}
			},
		}
	}

end

function p.opening()  --ouverture / consécration / date de mise en service (!= date de construction)
	return {
		type = 'multi', 
		rows = {
			{
				type = 'row', 
				value =  {"date d'ouverture", "mise en service"}, 
				label = 'Otettu käyttöön', 
				wikidata = keydate{'P1619', 'Q15051339'} -- P1619 = ouverture officielle, pas ouverture de facto
			},
			{
				type = 'row', 
				value = 'inauguration', 
				label = 'Vihkimistilaisuus',
				blockers = 'Otettu käyttöön', 
				wikidata = keydate{'Q1417098'}
			},

			{
				type = 'row', 
				value = 'consécration', 
				label = 'Consécration',
				blockers = 'Vihkimistilaisuus',
				wikidata = keydate{ 'Q125375'}
			},
			{
				type = 'row', 
				value = {'loistoksi', 'ensivalo'}, 
				label = 'Ensivalo',
				blockers = 'Otettu käyttöön',
				wikidata = keydate{'Q1306940'} -- P1619 = ouverture officielle, pas ouverture de facto
			}
		}
	}
end


function p.renovation()
	return {
		type = 'multi', 
		rows = {
			{
				type = 'row',
				value = 'restauration',
				label = 'Restauration',			
				wikidata = keydate{'Q217102'},
				blockers = 'rénovation',
			},
			{
				type = 'row',
				value = 'rénovation',
				label = 'Rénovation',			
				wikidata = keydate{'Q2144402'},
				blockers = 'restauration',
			},
			{
				type = 'row',
				value = {'extension', 'agrandissement'},
				label = 'Extension',		
				wikidata = keydate{'Q18621193'},
				blockers = 'restauration',
			},
			{
				type = 'row',
				value = 'autres travaux',
				label = 'Autres campagnes de travaux',		
		},
	}
}
end

function p.demolition()
	return {
		type = 'multi', 
		rows = {
			{
				type = 'row',
				value = {'purettu','démolition', 'date de démolition'},
				label = 'Purettu',
				wikidata = keydate('Q331483')
				},
				{
				type = 'row',
				value = {'tuhoutui', 'destruction'},
				label = 'Tuhoutuminen',
				wikidata = keydate('Q17781833')
			}
		}
	}
end

function p.closure()
	return {
		type = 'row',
		value = {'fermeture', 'date de fermeture'},
		label = 'Fermeture',
		wikidata = keydate{'Q14954904', 'P3999', 'P576'} -- P576: date de dissolution, plutôt réservé aux organisations
	}
end

function p.usage()
	return {
		type = 'row',
		label = 'Käyttö',
		value = 'käyttö', 
		wikidata = {
			property = 'P366',
			link = '-',
			speciallabels = {Q182060 = 'bureaux'}, -- bureaux semble toujours pouvoir se mettre au pluriel quand c'est en P366 d'un bâtiment
		}	
	}
end

function p.operator()
	return {
		type = 'row',
		label = 'Käyttäjä',
		wikidata = {property = 'P466', showdate= true},
		value = {'administration', 'gestionnaire'}
	}
end

function p.transport()
	return {
		type = 'multi', 
		rows = {
			{type = 'row', label = 'Stationnement', value = 'stationnement'},
			{type = 'row', label = 'Gare', value = 'gare'},
			{type = 'row', label = 'Métro', value = 'métro'},
			{type = 'row', label = 'Tramway', value = {'tram', 'tramway'}},
			{type = 'row', label = 'Autobus', value = 'bus'},
		},
	}
end

function p.complex() -- le complexe immobilier auquel appartient un bâtiment
	return {
		type = 'row',
		label = 'Osa kohdetta',
		value = 'osa kohdetta',
		wikidata = {
			property = 'P361',
			condition = function(claim)
				local v = wd.getmainid(claim)
				return wd.isInstance("Q1497364", v, 1)
			end,
		}
	}
end

function p.archistyle()
	return {
		type = 'row',
		label = 'Tyylisuunta',
		value = {'tyylisuunta', 'style architectural', 'style'},
		wikidata = function ()
			local val = wd.formatAndCat{entity = localdata.item, property = 'P149'}
				or wd.formatAndCat{entity = localdata.item, property = 'P135'}
			if not val then
				return nil
			end
			val = mw.ustring.gsub(val, "\|style ", "\|")
			return val
		end
	}
end

function p.creator() -- toute sorte de créateurs, pourraient peut-être être partagé avec infobox oeuvre d'art
	local wdarchitect, wdengineer = p.creatorQuery("P84"), p.creatorQuery("P631")
	if wdarchitect and wdengineer then -- ne pas afficher les deux si c'est la même valeur
		if (wd.formatStatements{property = "P84", displayformat = "raw", entity= localdata.item} == wd.formatStatements{property = "P631", displayformat = "raw", entity = localdata.item}) then
			wdengineer = nil
		end
	end
	return {
		type = 'multi',
		rows = {
			-- architect
			{
				type = "row",
				label = localdata["titre architecte"] or "Arkkitehti",
				plurallabel = "Arkkitehdit",
				value = "arkkitehti",
				wikidata = wdarchitect,
			},
			-- ingénieur
			{
				type = "row",
				label = "Suunnittelija",
				plurallabel = "Suunnittelijat",
				value = "suunnittelija",
				wikidata =  wdengineer,
			},
			-- créateur (quand les autres noms ne conviennent pas)
			{	type = "row",
				label = "Luoja",
				plurallabel = "Luojat",
				value = "luoja",
				-- ne pas utiliser Wikidata si le paramètre "architecte" est renseigné (risques de doublon)
				wikidata =  p.creatorQuery("P170"),
				blockers = {'arkkitehti'},
			},
		}
	}
end


function p.owner()
	return {
		type = 'multi', 
		rows = {
			{
				type = 'row',
				label = 'Propriétaire initial',
				plurallabel = 'Propriétaires initiaux',
				value = 'propriétaire initial',
			},
			{
				type = 'row',
				label = 'Propriétaire actuel',
				plurallabel = 'Propriétaires actuels',
				value = 'propriétaire actuel',
			},
			{
				type = 'row',
				label = 'Omistaja',
				plurallabel = 'Omistajat',
				value = 'omistaja',
				wikidata = require('Module:Fr:Propriétaire').formatFromItem(localdata.item)
			}
		}
	}
end

function p.shape()
	return {
		type = 'row',
		label = 'Muoto',
		value = {'muoto', 'forme', 'aspect'},
		property = 'P1419',
	}
end

function p.dimensions()
	return {
	type = 'multi', 
		rows = {
	{
		type = 'row',
		label = 'Antennin huippu' ,
		value = 'antenni/huippu',
		wikidata = {property = 'P2048', targetunit = 'm', qualifier = 'P518', qualifiervalue = {'Q131214','Q852590'}}
	},
	{
		type = 'row',
		label = 'Kattokorkeus',
		value = 'katto_korkeus',
		wikidata = {property = 'P2048', targetunit = 'm', qualifier = 'P518', qualifiervalue = 'Q83180'}
	},
	{
		type = 'row',
		label = 'ylin_kerros',
		value = 'Ylin kerros' 
	},
--- Hauteur générique : exclut lesvaleurs Wikidata affichées dans une des lignes précedentes + affiche le qualificatif P518
	{
		type = 'row',
		label = 'Korkeus',
		value = 'korkeus',
		wikidata =  {property = 'P2048', targetunit = 'm', statementformat = function(statement) return inclexcl(statement) end, excludequalifier = {'P518', 'P794'}, excludequalifiervalue = {'Q24192182', 'Q131214','Q852590', 'Q83180'}}
	},
	{
		type = 'row',
		label = 'Paksuus',
		value = 'paksuus',
		wikidata = {property = 'P2610', targetunit = 'metre', conjtype = ' ou ', rounding = '1', numval = '2'},
	},
	{
		type = 'row',
		label = 'Pituus',
		value = 'pituus',
		wikidata = {property = 'P2043', targetunit = 'metre', statementformat = function(statement) return inclexcl(statement) end, conjtype = ' ou ', rounding = '1', numval = '2'},
	},
	{
		type = 'row',
		label = 'Leveys',
		value = 'leveys',
		wikidata = {property = 'P2049', targetunit = 'metre',  statementformat = function(statement) return inclexcl(statement) end, conjtype = ' ou ', rounding = '1', numval = '2'},
	},
	{
		type = 'row',
		label = 'Kärkiväli',
		value = 'kärkiväli',
		wikidata = {property = 'P2050', targetunit = 'metre', conjtype = ' ou ', rounding = '1', numval = '2'},
	},
	{
		type = 'row',
		label = 'Halkaisija',
		value = 'halkaisija',
		wikidata = {property = 'P2386', targetunit = 'metre', conjtype = ' ou ', rounding = '1', numval = '2'},
	},
	{
		type = 'row',
		label = 'Ympärysmitta',
		value = {'ympärysmitta', 'périmètre', 'contour', 'circonférence'},
		wikidata = {property = 'P2547', targetunit = 'metre', conjtype = ' ou ', rounding = '1', numval = '2'},
	},
	-- Hauteur (avec plusieurs différentes affichées pour les gratte-ciel, voir les bases Emporis ou skyscrapercenter
	{
		type = 'row',
		label = 'rakennelman Korkeus',
		value = 'rakennelman korkeus',
		wikidata =  {property = 'P2048', targetunit = 'm', qualifier = {'P794'}, {'P518', 'P794'}, qualifiervalue = {'Q24192182'}}
	},
	{
		type = 'row',
		label = 'Pinta-ala',
		value = {'pintaala', 'superficie'},
		wikidata = {property = 'P2046', targetunit = 'square meter', conjtype = ' ou ', rounding = '1', numval = '2'},
	},
	{
		type = 'row',
		label = 'Tilavuus',
		value = 'tilavuus',
		wikidata = {property = 'P2234', targetunit = 'cubic metre', conjtype = ' ou ', rounding = '1', numval = '2'},
	}
	}
}
end

function p.floors()
	return {
	type = 'multi', 
		rows = {
	{
		type = 'row',
		label = 'Maanpäällisiä kerroksia',
		value = {'maanpäällisiä kerroksia', 'kerroksia', 'niveaux au-dessus du sol', 'étages'},
		property = 'P1101',
	},
	{
		type = 'row',
		label = 'Maanalaisia kerroksia',
		value = 'maanalaisia kerroksia',
		property = 'P1139',
	}
	}
}
end

function p.destroyedby()
	return {
		type = 'row',
		label = 'Détruit par',
		value = {'détruit par', 'cause de la destruction'}, 
		property = 'P770',
	}
end

function p.material()
	return {
		type = 'row',
		label = 'Materiaali',
		plurallabel = 'Materiaalit',
		value = {'rakennusmateriaali', 'julkisivumateriaali'}, 
		wikidata = require('Module:Fr:Matériau').formatFromItem(localdata.item),
	}
end

function p.colour()
	return {
		type = 'row',
		label = 'Väri',
		plurallabel = 'Värit',
		value = {'väri', 'couleur', 'couleurs'},
		property = 'P462',
	}
end

function p.inscription()
	return {
		type = 'row',
		label = 'Merkinnät',
		value = {'merkinnät', 'inscription', 'enseigne'},
		wikidata = {property = 'P1684', numval = '1'},
	}
end

function p.equipment()
	return {
		type = 'row',
		label = 'Équipement',
		plurallabel = 'Équipements',
		value = {'équipement', 'équipements'},
		property = 'P912',
	}
end

function p.replaces()
	return {
		type = 'row',
		label = 'Edeltäjä',
		value = 'edeltäjä',
		property = 'P1398',
	}
end

function p.replacedby()
	return {
		type = 'row',
		label = 'Seuraaja',
		value = 'seuraaja',
		property = 'P167',
	}
end

function p.protection()
	return {
		type = 'row',
		label = 'Luokitus',
		value = {'kulttuuriperintökohteen luokitus', 'classement', 'protection'},
		wikidata = require('Module:Fr:Classement').formattedList(localdata.item)
	}
end

function p.geoloc(params)
	return general.geoloc(params)
end

return p