Module:Infobox/Fonctions/Bâtiment

Από τη Βικιπαίδεια, την ελεύθερη εγκυκλοπαίδεια
Documentation icon Τεκμηρίωση module[δημιουργία]
local p = {}
local util = require 'Module:Utilitaire Wikidata'
local general = require 'Module:Infobox/Fonctions'
local coordfunctions = require 'Module:Infobox/Fonctions/Géolocalisation'

local function daterow(args)
	local wikidataquery
	if args.event then
		wikidataquery = function() return util.keydate(args.event) end
	end
	
	-- blocker définit des événements proches de celui recherché, s'il sont rensignés localement, on désactive la reuqête Wikidata pour éviter les doublons 
	-- exemple : "ouverture" désactive la recher d'"inauguration" sur Wikidata
	if args.blocker and localdata[args.blocker] then
		wikidata = false
	elseif args.blocker and type(args.blocker) == 'table' then
		for i, j in pairs(blocker) do 
			if localdata[j] then
				wikidata = false
				break
			end
		end
	end

	return {
		type = 'row',
		label = args.label,
		value =  args.param,
		wikidata = wikidataquery
	}
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(default)
	return	coordfunctions.country(default)	
end

function p.address() return nil end -- pour éviter un bug de tansitions, si vous lisez cela vous pouvez effacer la fonctions

function p.historicalregion()
	return {
		type = 'row', -- pour les régions historiques, non adminstratives
		value = 'région',
		label = localdata['intitulé région'] or localdata['lien région'] or 'Région',
	}
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
	return 
	{type = 'multi', rows = {
			{
				type = 'row', 
				value = {'subdivision', 'subdivision1', 'subdivision nom'},
				label = localdata['intitulé subdivision'] or localdata['lien subdivision1'] or localdata['lien subdivision'] or localdata['subdivision type'] or 'Division administrative'
			},
			{
				type = 'row', 
				value = 'subdivision2',
				label = localdata['intitulé subdivision2'] or localdata['lien subdivision2'] or 'Subdivision administrative'
			},
			{
				type = 'row', 
				value = 'subdivision3',
				label = localdata['intitulé subdivision3'] or localdata['lien subdivision3'] or 'Subdivision administrative'
			},
			{
				type = 'row', 
				value = {'commune', 'ville'},
				label = localdata['intitulé commune'] or localdata['lien commune'] or 'Commune'
			},
			{
				type = 'row', 
				value = 'quartier',
				label = localdata['intitulé quartier'] or localdata['titre quartier'] or 'Quartier'
			},
			{
				type = 'row', 
				value = {'localisation', 'localité'},
				label = 'Localisation', -- pour les phares et autres,
				property = 'P131'
			},
		{
			type = 'row',
			value = 'adresse',
			label = 'Adresse',
			wikidata = require('Module:Adresse').wikidataAddress(item),
		}
	} }
end

function p.coordinates(coordspecs)
	return coordfunctions.coordinates(coordspecs)
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),
			daterow{param = 'début construction', label = 'Début de construction'},
			daterow{param = 'fin construction', label = 'Fin de construction'},

		-- construction (nom de paramètre "date de construction" à déprécier)
			daterow{param = {'construction', 'Construction', 'date de construction'}, label = 'Construction', event = {'Q385378', 'P571'}},

		}
	}

end

function p.opening() return --ouverture / consécration / date de mise en service (!= date de construction)
	{type = 'multi', rows = {
			daterow{param =  {"ouverture", "date d'ouverture"}, label = 'Ouverture', event = {'P1619', 'Q15051339'}}, -- P1619 = ouverture officielle, pas ouverture de facto
			daterow{param = 'inauguration', label = 'Inauguration', event = 'Q1417098', blocker = 'ouverture'}, -- désactivé si "ouverture" est renseigné : risques de doublon 
			daterow{param = 'consécration', label = 'Consécration', event = 'Q125375', blocker = 'inauguration'},
			daterow{param =  'première lumière', label = '[[Première lumière]]', event = 'Q1306940'}, 
		}
	}
end


function p.renovation() return
	{type = 'multi', rows = {
		daterow{param = 'restauration', label = 'Restauration', event = 'Q217102', blocker = 'rénovation'},
		daterow{param = 'rénovation', label = 'Rénovation', event = 'Q2144402', blocker = 'restauration'},
		daterow{param = {'extension', 'agrandissement'}, label = 'Extension', event = 'Q18621193'},
		daterow{param = 'autres travaux', label = 'Autres campagnes de travaux'},
		}
	}
end

function p.demolition() return
	{type = 'multi', rows = {
		daterow{param = {'démolition', 'date de démolition'}, label = 'Démolition', event = 'Q331483'},
		daterow{param = 'destruction', label = 'Destruction', event = 'Q17781833'},
	}
	}
end

function p.closure() return
	daterow{param = 'fermeture', label = 'Fermeture', event = {'Q14954904','P576'}} -- P576: date de dissolution, plutôt réservé aux organisations
end

function p.usage() return
	{
	type = 'row',
	label = 'Usage',
	value = 'usage', 
	wikidata = function(item)
		local speciallabels = {
			Q182060 = 'bureaux', -- bureaux semble toujours pouvoir se mettre au pluriel quand c'est en P366 d'un bâtiment
		}
		return util.formatAndCat{entity = item, property = 'P366', speciallabels = speciallabels, link = '-'}		
	end
	}
end

function p.operator()
	return 
	{
		type = 'row',
		label = 'Gestionnaire',
		wikidata = function() return util._formatStatements{property = 'P137', entity = item, showdate= true} end,
		value = localdata['administration'] or localdata['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()
	return {
		type = 'row',
		label = 'Partie de',
		value = {'partie de', 'ensemble', 'ensemble architectural', 'complexe', 'complexe architectural'},
		property = 'P361',
	}
end

function p.archistyle()
	return {
		type = 'row',
		label = 'Style',
		value = {'style architectural', 'style'},
		wikidata = function ()
			local val = util.formatAndCat{entity = item, property = 'P149'} or util.formatAndCat{entity = 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
	return {type = 'multi', rows = {
	-- architect
	{	type = 'row',
		label = localdata['titre architecte'] or 'Architecte',
		value = 'architecte',
		wikidata = util.formatAndCat{entity = item, property = 'P84', showqualifiers = {'P518'}, showdate = true, qualiflink = '-'}
	},
	-- ingénieur
	{
		type = 'row',
		label = 'Ingénieur',
		value = 'ingénieur',
		property = 'P631',
	},
	-- créateur (quand les autres noms ne conviennent pas)
	{	type = 'row',
		label = 'Créateur',
		value = function() 
			if localdata['architecte'] then
				return nil
			end
			if localdata['créateur'] then
				return localdata['créateur']
			end
			if item then
				return util.formatAndCat{entity = item, property = 'P170', showqualifiers = {'P518'}}
			end
		end
	},
}	}
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 = 'Propriétaire',
			plurallabel = 'Propriétaires',
			value = 'propriétaire',
			wikidata = require('Module:Propriétaire').formatFromItem(item)
		}
	} }
end

function p.material()
	return {
		type = 'row',
		label = 'Matériau',
		plurallabel = 'Matériaux',
		value = 'matériau', 
		wikidata = require('Module:Matériau').formatFromItem(item),
	}
end

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

function p.protection()
	return {
		type = 'row',
		label = 'Statut patrimonial',
		value = {'classement', 'protection'},
		wikidata = require('Module:Classement').formattedList(item)
	}
end

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

return p