Módulo:Infobox / Functions/B

Wikipediamanta

La documentación para este módulo puede ser creada en Módulo:Infobox / Functions/B/doc

local p = {}
local localdata = require( 'Módulo:Infobox / Localdata' )
local item = localdata.item
local wd = require "Módulo:Wikidata"
local general = require "Módulo:Infobox / Functions"
local linguistic = require "Módulo:Simi-yachay"
local address = require "Módulo:Adress"

local function keyDate(event)
	return wd.keyDate(event, item, {conjtype = 'comma', showqualifiers = {'P518'}, link = '-'})
end
local function keyDateConstruction(event)
	return wd.keyDate(event, item, {conjtype = 'comma', showqualifiers = {'P518', 'P4241'}, link = '-'})
end

local function inclexcl(statement, params) -- formatte les qualificatifs "P518" / "P1011" (à mettre plutôt dans un sous module de Módulo:Wikidata, comme pour les dates ?
	local str = wd.formatSnak(statement.mainsnak, params)
	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 $of",
				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 {
		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.adminloc(divstr) -- affiche l'adresse complète (rue, divisions administratives pertinentes, pays) dans un champ unique

	-- pas de paramètre global pour la ligne streetstr et la ligne divstr, dépend de l'historique du modèle utilisé
	local country = localdata["pays"]
	local streetstr =  localdata['adresse']
	local val = address.fullAddress(localdata['item'], country, nil, streetstr, divstr)
	return 
		{
		type = 'row',
		label = 'Adresse',
		value = function() return val 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
	
	if not (localdata['subdivision1'] or localdata['subdivision nom'] or localdata['subdivision2'] or localdata['subdivision3'] or localdata['commune'] or localdata['ville'] or localdata['quartier']) then
		return p.adminloc()
	end
	return {
		type = 'multi', 
		rows = {
			general.country(),
			p.historicalregion(),
			{
				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 = 'adresse',
				label = 'Adresse',
				wikidata = require('Módulo:Adress').wikidataAddress(localdata.item),
			},
		}
	}
end

function p.onshoreof()
	return {
		type = 'row',
		label = 'Baigné par',
		value = {'baigné par', 'sur les rives de'},
		wikidata = {property = 'P206', defaultlinkquery = {property = 'P361'}},
	}
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 = 'Aire protégée',
		plurallabel = 'Aires protégées',
		value = {'aire protégée', 'aires protégées'},
		wikidata = {property = 'P3018', defaultlinkquery = {property = 'P3018'}},
	}
end

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

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

function p.elevation()
	return {
		type = 'row',
		label = 'Altitude',
		value = 'altitude',
		wikidata = {property = 'P2044', targetunit = 'metre', conjtype = ' ou ', rounding = '0', numval = '2'},
	}
end

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

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

function p.cornerstonelaying()
	return {
		type = 'multi', 
		rows = {
			{
				type = 'row',
				value = {'première pierre', 'pose de la première pierre'},
				label = '[[Première pierre]]',
				wikidata = keyDate('Q18752057')
			}
		}
	}
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 = 'Début de 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 = {'construction', 'Construction', 'date de construction'}, 
				label = 'Construction', 
				wikidata = keyDateConstruction{'Q385378', 'P571'},
			},
		}
	}

end

function p.fondation() --inception P571
	return {
		type = 'multi', 
		rows = {
			{
				type = 'row',
				value = {'fondation', 'Fondation', 'date de fondation'}, 
				label = 'Fondation', 
				wikidata = keyDateConstruction{'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 = 'Reconstruction', 
			},
			{
				type = 'row',
				value = {'fin reconstruction', 'fin'}, 
				label = 'Fin de reconstruction', 
			},

			-- reconstruction (nom de paramètre "date de reconstruction" à déprécier)
			{
				type = 'row',
				value = {'Reconstruction', '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 =  {"ouverture", "date d'ouverture", "mise en service"}, 
				label = 'Ouverture', 
				wikidata = keyDate{'P1619', 'Q15051339'} -- P1619 = ouverture officielle, pas ouverture de facto
			},
			{
				type = 'row', 
				value = 'inauguration', 
				label = 'Inauguration',
				blockers = 'Ouverture', 
				wikidata = keyDate{'Q1417098'}
			},

			{
				type = 'row', 
				value = 'consécration', 
				label = 'Consécration',
				blockers = 'inauguration',
				wikidata = keyDate{ 'Q125375'}
			},
			{
				type = 'row', 
				value = 'première lumière', 
				label = '[[Première lumière]]',
				blockers = 'Ouverture',
				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{'Q19841649'},
				blockers = 'restauration',
			},
			{
				type = 'row',
				value = 'autres travaux',
				label = 'Autres campagnes de travaux',		
		},
	}
}
end

function p.relocation()
	return {
		type = 'multi', 
		rows = {
			{
				type = 'row',
				value = {'déplacement', 'date de déplacement'},
				label = 'Déplacement',
				plurallabel = 'Déplacements',
				wikidata = keyDate('Q826949')
			}
		}
	}
end

function p.demolition()
	return {
		type = 'multi', 
		rows = {
			{
				type = 'row',
				value = {'démolition', 'date de démolition'},
				label = 'Démolition',
				wikidata = keyDate{'Q331483', 'P576'}
			},
			{
				type = 'row',
				value = {'destruction'},
				label = 'Destruction',
				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 = 'Usage',
		value = 'usage', 
		wikidata = {
			property = 'P366',
			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 = 'Gestionnaire',
		wikidata = {property = 'P137', showdate= true},
		value = {'administration', 'gestionnaire'}
	}
end

function p.maintenance()
	return {
		type = 'row',
		label = 'Maintenance',
		wikidata = {property = 'P126', showdate= true},
		value = {'maintenance'}
	}
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 = 'Complexe',
		value = 'complexe',
		wikidata = {
			property = 'P361',
			condition = function(claim)
				local v = wd.getMainId(claim)
				return wd.isInstance("Q1497364", v, 1)
			end,
		}
	}
end

function p.orientation()
	return {
		type = 'row',
		label = 'Orientation',
		value = 'orientation',
		wikidata = {property = 'P7469', numval = '1'},
	}
end

function p.archistyle()
	return {
		type = 'row',
		label = 'Style',
		plurallabel = 'Styles',
		value = {'style architectural', 'style'},
		wikidata = {property = {'P149', 'P135'},
			       showqualifiers = {'P518'},
		}
	}
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 = {
			-- architecte
			{
				type = "row",
				label = localdata["titre architecte"] or "Architecte",
				plurallabel = "Architectes",
				value = "architecte",
				wikidata = wdarchitect,
			},
			-- ingénieur
			{
				type = "row",
				label = "Ingénieur",
				plurallabel = "Ingénieurs",
				value = "ingénieur",
				wikidata =  wdengineer,
			},
	    	-- peintre
			{
				type = "row",
				label = "Peintre",
				plurallabel = "Peintres",
				value = "peintre",
			},
      		-- sculpteur
			{
				type = "row",
				label = "Sculpteur",
				plurallabel = "Sculpteurs",
				value = "sculpteur",
			},
			-- créateur (quand les autres noms ne conviennent pas)
			{	type = "row",
				label = localdata["titre créateur"] or "Créateur",
				plurallabel = "Créateurs",
				value = "créateur",
				-- ne pas utiliser Wikidata si un des paramètres précédent est renseigné (risques de doublon)
				wikidata =  p.creatorQuery("P170"),
				blockers = {'architecte', 'peintre', 'sculpteur'},
			},
		}
	}
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 = function() return require('Módulo:Propietario').formatFromItem(localdata.item, {sorttype = 'chronological', showdate = true, conjtype = 'comma', precision = 'year'}) end,
			}
		}
	}
end

function p.religion()
	return {
		type = 'row',
		label = 'Religion',
		value = {'religion', 'église'},
		property = 'P140',
	}
end

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

function p.dimensions()
	return {
	type = 'multi', 
		rows = {
		{
		type = 'row',
		label = 'Hauteur',
		value = function()
			local str = localdata['hauteur']
			-- hauteurs spéciales, pour infobox:Gratte-ciel
			local function appendheight(str, param, label)
				if not localdata[param] then
					return str
				end
				if str then
					str = str .. '<br />'
				else
					str = ''
				end
				return str .. label .. ' : ' .. localdata[param]
			end
			str = appendheight(str, 'antenne flèche', 'Flèche')
			str = appendheight(str, 'toit', 'Toit')
			str = appendheight(str, 'dernier étage', 'Dernier étage')			
			
			return str
			end,
		wikidata = {
			property = 'P2048',
			targetunit = 'm',
			excludequalifier = {'P518', 'P794'},
			sorttype = 'descending',
			rank = 'valid',
			conjtype = '<br />',
			link = '-',
			showqualifiers = {'P1013', 'P518'}		
		}
	},
	{
		type = 'row',
		label = 'Profondeur',
		value = 'profondeur',
		wikidata =  {property = 'P2610', targetunit = 'metre', numval = '2', statementformat = function(statement) return inclexcl(statement, {targetunit = 'metre', rounding = '1'}) end},
	},
	{
		type = 'row',
		label = 'Longueur',
		value = 'longueur',
		wikidata = {property = 'P2043', targetunit = 'metre', numval = '2', statementformat = function(statement) return inclexcl(statement, {targetunit = 'metre', rounding = '1'}) end},
	},
	{
		type = 'row',
		label = 'Largeur',
		value = 'largeur',
		wikidata = {property = 'P2049', targetunit = 'metre', numval = 2, statementformat = function(statement) return inclexcl(statement, {targetunit = 'metre', rounding = '1'}) end},
	},
	{
		type = 'row',
		label = 'Envergure',
		value = 'envergure',
		wikidata = {property = 'P2050', targetunit = 'metre', conjtype = 'or', rounding = '1', numval = '2'},
	},
	{
		type = 'row',
		label = 'Diamètre',
		value = 'diamètre',
		wikidata = {property = 'P2386', targetunit = 'metre', conjtype = 'or', rounding = '1', numval = '2'},
	},
	{
		type = 'row',
		label = 'Périmètre',
		value = {'périmètre', 'contour', 'circonférence'},
		wikidata = {property = 'P2547', targetunit = 'metre', conjtype = 'or', rounding = '1', numval = '2'},
	},
	{
		type = 'row',
		label = 'Surface',
		value = {'surface', 'superficie'},
		wikidata = {property = 'P2046', targetunit = 'square meter', conjtype = 'or', rounding = '1', numval = '2'},
	},
	{
		type = 'row',
		label = 'Volume',
		value = 'volume',
		wikidata = {property = 'P2234', targetunit = 'cubic metre', conjtype = 'or', rounding = '1', numval = '2'},
	}
	}
}
end

function p.floors()
	return {
	type = 'multi', 
		rows = {
	{
		type = 'row',
		label = 'Niveaux',
		value = {'niveaux au-dessus du sol', 'niveaux'},
		property = 'P1101',
	},
	{
		type = 'row',
		label = 'Sous-sols',
		value = 'sous-sols',
		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 = 'Matériau',
		plurallabel = 'Matériaux',
		value = 'matériau', 
		wikidata = require('Módulo:Material').formatFromItem(localdata.item),
	}
end

function p.colour()
	return {
		type = 'row',
		label = 'Couleur',
		plurallabel = 'Couleurs',
		value = {'couleur', 'couleurs'},
		property = 'P462',
	}
end

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

function p.awards()
	return {
		type = 'row',
		label = 'Prix',
		value = 'prix',
		wikidata = {property = 'P166', showdate = 'yes', numval = '3'},
	}
end

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

function p.replaces()
	return {
		type = 'row',
		label = 'Remplace',
		value = 'remplace',
		property = 'P1398',
	}
end

function p.replacedby()
	return {
		type = 'row',
		label = 'Remplacé par',
		value = 'remplacé par',
		property = 'P167',
	}
end

function p.visitors()
	return {
		type = 'row',
		label = 'Visiteurs par an',
		value = {'visiteurs', 'visiteurs par an', 'fréquentation', 'fréquentation annuelle'},
		wikidata = {property = 'P1174', showdate = 'true', numval = 1, sorttype = "inverted"},
	}
end

function p.protection()
	return {
		type = 'row',
		label = 'Patrimonialité',
		value = {'classement', 'protection', 'statut patrimonial', 'patrimonialité'},
		wikidata = require('Módulo:Classe').formattedList(localdata.item)
	}
end

function p.danger()
	return {
		type = 'row',
		label = 'Danger',
		plurallabel = 'Dangers',
		value = {'danger', 'dangers'},
		wikidata = {property = 'P3335', numval = 5},
	}
end

function p.policy()
	return {
		type = 'row',
		label = 'Règlement',
		plurallabel = 'Règlements',
		value = {'règlement', 'règlements'},
		wikidata = {property = 'P5023', numval = 5},
	}
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 = 'Désignation', value = 'nom unesco'},
		{type = 'row', label = "Type de bien", value = 'type unesco', wikidata = {property = 'P1435', targetvalue = {'Q16617071', 'Q52683527', 'Q52683530'}}},
		{type = 'row', label = "Date d'entrée", value = 'date patrimoine mondial', wikidata = {property = 'P1435', targetvalue = {'Q9259', 'Q16617071', 'Q52683527', 'Q52683530'}, showonlyqualifier = {'P580'}}},
		{
		type = 'row',
		label = "Identifiant",
		value = function() return id end,
		},
		{	
		type = 'row',
		label = "Critères",
		singularlabel = "Critère",
		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