Moduuli:Fr:Infobox/Fonctions/Bâtiment

Wikisanakirjasta

Moduulin Fr:Infobox/Fonctions/Bâtiment käyttöohje [näytä tämä käyttöohje omalla sivullaan] [muokkaa tätä käyttöohjetta] [päivitä] [testit] [hiekkalaatikko]


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(" ml. " .. incl) -- pas la formulation la plus élégante mais elle évite les problèmes d'accord grammaticaux
	end
	if excl then
		str = str .. linguistic.inparentheses("pl. " .. 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 ))
	
	-- perinteisesti sijainti-parametriin on kirjoitettu koko sijainti mukaanlukien valtio.
	local countrymatch=wd.formatStatements{ entity= localdata.item, property = "P17", link="-"}
	if (area and countrymatch and string.find(area,countrymatch)) then
		val=area
	end
	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.geographiclocation()
	return {
		type = 'row',
		label = 'Sijaintipaikka',
		wikidata = {property = 'P706'},
		blockers='sijainti'
	}
end

function p.islandlocation()
	return {
		type = 'row',
		label = 'Saari',
		wikidata = {property = 'P5130'},
	}
end

function p.watershed()
	return {
		type = 'row',
		label = 'Bassin versant',
		value = 'bassin versant',
		wikidata = {property = 'P4614', defaultlinkquery = {property = {'P4614', 'P138'}}},
	}
end

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

function p.island()
	return {
		type = 'row',
		label = 'Saari',
		plurallabel = 'Saaret',
		value = 'île',
		property = 'P5130',
	}
end

function p.mountainrange()
	return {
		type = 'row',
		label = 'Vuoristo',
		plurallabel = 'Vuoristot',
		value = {'massif', 'chaîne de montagnes'},
		wikidata = {property = 'P4552', defaultlinkquery = {property = 'P4552'}},
	}
end

function p.elevation()
	return {
		type = 'row',
		label = 'Korkeus merenpinnasta',
		value = 'korkeus',
		wikidata = {property = 'P2044', targetunit = 'm', conjtype = ' tai ', rounding = '0', numval = '2', showsource=true},
	}
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 = {'rakentamisen alku'}, 
				label = 'Rakentaminen alkoi', 
			},
			{
				type = 'row',
				value = {'rakentaminen päättyi', 'loppu'}, 
				label = 'Rakentaminen päättyi', 
			},

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

end

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

			-- début reconstruction, fin reconstruction (legacy infobox Stade, Infobox Château),
			{
				type = 'row',
				value = {'début reconstruction', 'début'}, 
				label = 'Uudelleenrakennettu', 
			},
			{
				type = 'row',
				value = {'fin reconstruction', 'fin'}, 
				label = 'Uudelleenrakentaminen päättyi', 
			},

			-- reconstruction (nom de paramètre "date de reconstruction" à déprécier)
			{
				type = 'row',
				value = {'construction', 'Reconstruction', 'date de reconstruction'}, 
				label = 'Reconstruction', 
				wikidata = keydate{'Q1370468'}
			},
		}
	}

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', 
				blockers ='rakennettu',
				wikidata = keydate{'P1619', 'Q15051339'} -- P1619 = ouverture officielle, pas ouverture de facto
			},
			{
				type = 'row', 
				value = 'inauguration', 
				label = 'Avajaiset',
				blockers = 'rakennettu', 
				wikidata = keydate{'Q1417098'}
			},

			{
				type = 'row', 
				value = 'consécration', 
				label = 'Consécration',
				blockers = 'rakennettu',
				wikidata = keydate{ 'Q125375'}
			},
			{
				type = 'row', 
				value = {'loistoksi', 'ensivalo'}, 
				label = 'Ensivalo',
				blockers = 'rakennettu',
				wikidata = keydate{'Q1306940'} -- P1619 = ouverture officielle, pas ouverture de facto
			}
		}
	}
end


function p.renovation()
	return {
		type = 'multi', 
		rows = {
			{
				type = 'row',
				value = 'restauration',
				label = 'Restauroitu',			
				wikidata = keydate{'Q217102'},
				blockers = 'rénovation',
			},
			{
				type = 'row',
				value = 'rénovation',
				label = 'Remontoitu',			
				wikidata = keydate{'Q2144402'},
				blockers = 'restauration',
			},
			{
				type = 'row',
				value = {'extension', 'agrandissement'},
				label = 'Laajennettu',		
				wikidata = keydate{'Q18621193'},
				blockers = 'restauration',
			},
			{
				type = 'row',
				value = 'autres travaux',
				label = 'Muita rakennustöitä',		
		},
	}
}
end

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

function p.closure()
	return {
		type = 'row',
		value = {'lakkautettu', 'suljettu'},
		label = 'Lakkautettu',
		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, showsource=true},
		value = {'administration', 'gestionnaire'}
	}
end

function p.transport()
	return {
		type = 'multi', 
		rows = {
			{type = 'row', label = 'Pysäköinti', value = 'stationnement'},
			{type = 'row', label = 'Rautatieasema', value = 'gare'},
			{type = 'row', label = 'Metro', value = 'métro'},
			{type = 'row', label = 'Raitiovaunu', value = {'tram', 'tramway'}},
			{type = 'row', label = 'Bussi', 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,
				blockers = {'suunnittelija'},
			},
			-- ingénieur
			{
				type = "row",
				label = "Suunnittelija",
				plurallabel = "Suunnittelijat",
				value = "suunnittelija",
				wikidata =  wdengineer,
			},
			-- créateur (quand les autres noms ne conviennent pas)
			{	type = "row",
				label = "Tekijä",
				plurallabel = "Tekijät",
				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 = 'Alkuperäinen omistaja',
				plurallabel = 'Alkuperäiset omistajat',
				value = 'propriétaire initial',
			},
			{
				type = 'row',
				label = 'Nykyinen omistaja',
				plurallabel = 'Nykyiset omistajat',
				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.getLocalValueWithDefaultUnit(localdata, paramname, testparams )
	local ret=localdata[paramname] 

	if ret == nil then
		return nil
	end
	
	if ret == "-" then
		return "-"
	end
	
	if localdata[paramname .. "_ohita_tarkistus"] == "1"  then
		return ret;
	end

	args= {
		["sisältö"] = ret .."",
		tyyppi = testparams["type"] ,
		["sallitut_yksiköt"] = testparams["allowedunits"],
		malline = testparams["templatename"],
		parametri = testparams["paramname"] ,
		["vakioyksikkö"] = testparams["defaultunit"], 
		virheviesti = testparams["errormessage"],
		minimiarvo = testparams["minvalue"] ,
		maksimiarvo = testparams["maxvalue"],
		ohita_tarkistus = testparams["skiptests"]
	}

	frame=mw.getCurrentFrame();
	ret=frame:expandTemplate{ title = 'Tarkista luku', args = args }
	return ret
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'}, showsource=true}
	},
	{
		type = 'row',
		label = 'Kattokorkeus',
		value = 'katto_korkeus',
		wikidata = {property = 'P2048', targetunit = 'm', qualifier = 'P518', qualifiervalue = 'Q83180', showsource=true}
	},
	{
		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
--- inclexcl() rikkoo showsource = true:n joten siksi showgroupedsource = true
	{
		type = 'row',
		label = 'Korkeus',
		value = function()  return  p.getLocalValueWithDefaultUnit(localdata, 'korkeus',
				{
					paramname='korkeus', 
					type='desimaaliluku', 
					allowedunits='m', 
					templatename='p.dimensions()', 
					defaultunit='m', 
					errormessage='Esimerkkiarvo: 10 m', 
					minvalue=0,
					maxvalue=5000,
					skiptests=""
				} ) end,
		wikidata =  {property = 'P2048', targetunit = 'm', statementformat = function(statement) return inclexcl(statement) end, excludequalifier = {'P518', 'P794'}, excludequalifiervalue = {'Q24192182', 'Q131214','Q852590', 'Q83180'}, showgroupedsource=true}
	},
	{
		type = 'row',
		label = 'Paksuus',
		value = 'paksuus',
		wikidata = {property = 'P2610', targetunit = 'metre', conjtype = ' ou ', rounding = '1', numval = '2', showsource=true},
	},
	{
		type = 'row',
		label = 'Pituus',
		value = 'pituus',
		wikidata = {property = 'P2043', targetunit = 'metre', statementformat = function(statement) return inclexcl(statement) end, conjtype = ' ou ', rounding = '1', numval = '2', showgroupedsource=true},
	},
	{
		type = 'row',
		label = 'Leveys',
		value = 'leveys',
		wikidata = {property = 'P2049', targetunit = 'metre',  statementformat = function(statement) return inclexcl(statement) end, conjtype = ' ou ', rounding = '1', numval = '2', showgroupedsource=true},
	},
	{
		type = 'row',
		label = 'Kärkiväli',
		value = 'kärkiväli',
		wikidata = {property = 'P2050', targetunit = 'metre', conjtype = ' ou ', rounding = '1', numval = '2', showsource=true},
	},
	{
		type = 'row',
		label = 'Halkaisija',
		value = 'halkaisija',
		wikidata = {property = 'P2386', targetunit = 'metre', conjtype = ' ou ', rounding = '1', numval = '2', showsource=true},
	},
	{
		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', showsource=true},
	},
	-- 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'}, showsource=true}
	},
	{
		type = 'row',
		label = 'Pinta-ala',
		value = {'pintaala', 'superficie'},
		wikidata = {property = 'P2046', targetunit = 'square meter', conjtype = ' ou ', rounding = '1', numval = '2', showsource=true},
	},
	{
		type = 'row',
		label = 'Tilavuus',
		value = 'tilavuus',
		wikidata = {property = 'P2234', targetunit = 'cubic metre', conjtype = ' ou ', rounding = '1', numval = '2', showsource=true},
	}
	}
}
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',
		showsource = true,
	},
	{
		type = 'row',
		label = 'Maanalaisia kerroksia',
		value = 'maanalaisia kerroksia',
		property = 'P1139',
		showsource = true,
	}
	}
}
end

function p.destroyedby()
	return {
		type = 'row',
		label = 'Tuhoutumisen syy',
		value = {'détruit par', 'cause de la destruction'}, 
		property = 'P770',
		showsource = true,
	}
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', showsource=true},
	}
end

function p.equipment()
	return {
		type = 'row',
		label = 'Varustettu',
		plurallabel = 'Varusteet',
		value = {'équipement', 'équipements'},
		property = 'P912',
		showsource = true,
	}
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.visitors()
	return {
		type = 'row',
		label = 'Kävijämäärä',
		value = function(localdata) 
			if localdata["kävijämäärä"] then
				if localdata["kävijävuosi"] then
					return localdata["kävijämäärä"] .. " (" .. localdata["kävijävuosi"] ..")" 
				else
					return localdata["kävijämäärä"]
				end
			end
		end,
		wikidata = {property = 'P1174', showdate = 'true', numval = 1, sorttype = "inverted", showsource = true},
	}
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.unesco() -- pour remplacer [[Modèle:Infobox Patrimoine Mondial]] à ajouter : paramètres extension, patrimoine en péril, retrait, gestion des monuments faisant partie d'un ensemble
	local id = localdata['identifiant patrimoine mondial']
	if (id == '-') then
		return nil
	end
	if id then
		id = '[http://whc.unesco.org/fr/list/' .. id .. ' ' .. id .. ']'

	else
		id = wd.formatAndCat{entity = item, property = 'P757',  urlpattern = 'http://whc.unesco.org/fr/list/$1'}

	end
	if (not id) then
		return nil
	end
	return 
	{type = 'table', title = '[[Fichier:World Heritage Emblem.svg|15px|alt=Logo du patrimoine mondial|link=Patrimoine mondial]] Patrimoine mondial', rows = {
		{type = 'row', label = 'Kohde', value = 'nom unesco'},--Désignation
		{type = 'row', label = "Tyyppi", value = 'type unesco', wikidata = {property = 'P1435', targetvalue = {'Q16617071', 'Q52683527', 'Q52683530'}}},--Type de bien
		{type = 'row', label = "Päivämäärä", value = 'date patrimoine mondial', wikidata = {property = 'P1435', targetvalue = {'Q9259', 'Q16617071', 'Q52683527', 'Q52683530'}, showonlyqualifier = {'P580'}}},--Date d'entrée
		{
		type = 'row',
		label = "Tunnus",
		value = function() return id end,
		},
		{	
		type = 'row',
		label = "Kriteerit",
		singularlabel = "Kriteeri",
		value = function(localdata)
			if localdata['critères patrimoine mondial'] then
					return '[http://whc.unesco.org/fr/criteres/' .. localdata['critères patrimoine mondial'] .. ']'
			end
			end, 
		wikidata = function(item)
			local str, numclaims = wd.formatStatements{entity = item, property = 'P2614', link = '-', conjtype = ' ', returnnumberofvalues = true}
			if str then
				return wd.formatAndCat{value = '[http://whc.unesco.org/fr/criteres/$1 ' .. str .. ']', entity = item, property = 'P2614'}, numclaims
			end
			end
		},
		{type = 'row', label = 'Surface', value = 'surface unesco'},
		{type = 'row', label = 'Zone tampon', value = 'surface zone tampon unesco'},
	}
}
end

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

return p