Module:Infobox/Fonctions/Bâtiment : Différence entre versions

De Lagny-sur-Marne Wiki
Aller à : navigation, rechercher
(ajout de fonctions depuis gratte-ciel, avec un peu de formatage en plus)
Ligne 134 : Ligne 134 :
 
function p.demolition() return
 
function p.demolition() return
 
{type = 'multi', rows = {
 
{type = 'multi', rows = {
{type = 'mixed', label = 'Démolition', value = 'démolition', wikidata = function(item) return keydate('Q331483', item) end},
+
{type = 'mixed', label = 'Démolition', value = 'démolition', wikidata = function(item) return wikidatamod.keydate('Q331483', item) end},
{type = 'mixed', label = 'Destruction', value = 'destruction', wikidata = function(item) return keydate('Q17781833', item) end},
+
{type = 'mixed', label = 'Destruction', value = 'destruction', wikidata = function(item) return wikidatamod.keydate('Q17781833', item) end},
 
}
 
}
 
}
 
}

Version du 11 mars 2015 à 21:45

La documentation pour ce module peut être créée à Module:Infobox/Fonctions/Bâtiment/doc

local p = {}
local wikidatamod = require 'Module:Wikidata'
local general = require 'Module:Infobox/Fonctions'
local coordfunctions = require 'Module:Infobox/Fonctions/Géolocalisation'

--Titre
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 = function(localdata, item) return localdata['intitulé région'] or localdata['lien région'] or 'Région' end,
	}
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 = function(localdata, item) return localdata['subdivision'] or localdata['subdivision1']end,
				label = function(localdata, item) return
					localdata['intitulé subdivision'] or localdata['lien subdivision1'] or localdata['lien subdivision'] or 'Subdivision administrative'
				end
			},
			{
				type = 'row', 
				value = 'subdivision2',
				label = function(localdata, item) return
					localdata['intitulé subdivision2'] or localdata['lien subdivision2'] or 'Subdivision administrative'
				end
			},
			{
				type = 'row', 
				value = 'subdivision3',
				label = function(localdata, item) return
					localdata['intitulé subdivision3'] or localdata['lien subdivision3'] or 'Subdivision administrative'
				end
			},
			{
				type = 'row', 
				value = function(localdata, item) return localdata['commune'] or localdata['ville'] end,
				label = function(localdata, item) return
					localdata['intitulé commune'] or localdata['lien commune'] or 'Commune'
				end
			},
			{
				type = 'row', 
				value = 'quartier',
				label = function(localdata, item) return localdata['intitulé quartier'] or localdata['titre quartier'] or 'Quartier' end
			},
		{
			type = 'row',
			value = 'adresse',
			label = 'Adresse',
			wikidata = function(item) return require('Module:Adresse').wikidataAddress(item) end,
		}
	} }
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)
			{	type = 'row',
				label = 'Début de construction',
				value = 'début construction',
			},
			{	type = 'row',
				label = 'Fin de construction',
				value = 'fin construction',
			},
			-- construction
			{	type = 'row',
				label = 'Date de construction',
				value =  'date de construction' or 'construction',
				wikidata = function(item) return
					wikidatamod.getTheDate{entity = item, property = 'P793', targetvalue = 'Q385378', addcat = true}
					or 
					wikidatamod.formatAndCat{entity = item, property = 'P571', showqualifiers = {'P518'}}
				end
			},
			--  ouverture
			{	type = 'row', 
				label = 'Ouverture',
				value = 'ouverture',
				--wikidata  valeur de P793 ?
			},
			-- inauguration
			{	type = 'row',
				label = 'Inauguration',
				function(localdata, item)  -- déactivé si le paramètre "ouverture" este renseigné : risques de doublon
					if localdata['ouverture'] then
						return nil
					end
					if localdata['inauguration'] then
						return localdata['inauguration']
					end
					if item then
						return wikidatamod.getTheDate{entity = item, property = 'P793', targetvalue = 'Q1417098', addcat = true, item=item}
					end
			end
			}
		} }
end

function p.demolition() return
	{type = 'multi', rows = {
		{type = 'mixed', label = 'Démolition', value = 'démolition', wikidata = function(item) return wikidatamod.keydate('Q331483', item) end},
		{type = 'mixed', label = 'Destruction', value = 'destruction', wikidata = function(item) return wikidatamod.keydate('Q17781833', item) end},
	}
	}
end

function p.closure() return
	{type = 'row', label = 'Fermeture', value = function(localdata, item)
		return wikidatamod.getTheDate{property = 'P793', targetvalue = 'Q14954904', addcat = true, item=item}
	end
	}
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 wikidatamod.formatStatements{entity = item, property = 'P366', speciallabel = speciallabels}
		end
	}
end

function p.operator()
	return 
	{type = 'row', label = 'Gestionnaire', property = 'P137',
		value = function(localdata, item) return localdata['administration'] or localdata['gestionnaire'] end}
end

function p.transport()
	return {
		{type = 'table', title = 'Accès et transport', 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 = 'bus'},
				{type = 'row', label = 'Autobus', value = 'gare'},
				},
		}
	}
end

function p.archistyle()
	return {
		type = 'row',
		label = 'Style',
		value = function(localdata, item) return localdata['style architectural'] or localdata['style'] end,
		wikidata = function (item)
			local val = wikidatamod.formatAndCat{entity = item, property = 'P149'} or wikidatamod.formatAndCat{entity = item, property = 'P135'}
			if not val then
				return nil
			end
			val = mw.ustring.gsub(val, "\|architecture ", "\|")
			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 = function(localdata, item) return localdata['titre architecte'] or 'Architecte' end,
		value = 'architecte',
		wikidata = wikidatamod.formatAndCat{entity = item, property = 'P84', showqualifiers = {'P518'}, showdate = true}
	},
	-- 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(localdata, item) 
			if localdata['architecte'] then
				return nil
			end
			if localdata['créateur'] then
				return localdata['créateur']
			end
			if item then
				return wikidatamod.formatAndCat{entity = item, property = 'P170', showqualifiers = {'P518'}}
			end
			end
	},
}	}
end


function p.owner()
	return 	{type = 'multi', rows = {
		{
			type = 'row',
			label = 'Propriétaire initial',
			value = 'propriétaire initial',
		},
		{
			type = 'row',
			label = 'Propriétaire actuel',
			value = 'propriétaire actuel',
		},
		{
			type = 'row',
			label = 'Propriétaire',
			value = 'propriétaire',
			wikidata = function(item) return require('Module:Propriétaire').formatFromItem(item) end
		}
	} }
end

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




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

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

return p