Aller au contenu

Module:Infobox/Art

Cette page fait l’objet d’une mesure de semi-protection étendue.
Une page de Wikipédia, l'encyclopédie libre.
Ceci est une version archivée de cette page, en date du 29 mars 2016 à 21:38 et modifiée en dernier par Zolo (discuter | contributions) (simplification du code avec statementformat). Elle peut contenir des erreurs, des inexactitudes ou des contenus vandalisés non présents dans la version actuelle.

 Documentation[voir] [modifier] [historique] [purger]

Cette page définit un module d'infobox. Pour les conseils sur l'usage de ce module, voyez Modèle:Infobox Art.


local geoloc = require 'Module:Infobox/Fonctions/Géolocalisation'
local general = require 'Module:Infobox/Fonctions'
local owner = require 'Module:Propriétaire'
local material = require 'Module:Matériau'
local linguistic = require 'Module:Linguistique'
local protected = require 'Module:Classement'
local wikidata = require 'Module:Interface Wikidata'.fromLua
local linktopic = 'en arts plastiques'

local function dimensions()
	local dimensions = {
		-- paramètre, abréviation à afficher dans l'en tête, prorpriété Wikidata, nom complet à afficher dans l'entête, stop
		{'diamètre', 'diamètre', nil, 'Diamètre', true},
		{ 'hauteur', 'H', 'P2048', 'Hauteur', false},
		{'largeur', 'L', 'P2049', 'Largeur', false},
		{'profondeur', 'l', nil, 'profondeur', false},
	}
	local data, dims = {}, {}
	local label = 'Dimensions'
	local unit = localdata['unité'] or 'cm'
	
	local wikidataval = function(d) return wikidata.formatStatements{entity = item, showunit = '-', targetunit = unit, addcat = true, property = d} end
	local propertyused = nil
	
	for i, j in pairs(dimensions) do
		local val = localdata[j[1]]
		if item and j[3] and not val then
			val = wikidataval(j[3])
			if val then
				propertyused = j[3]
			end
		end
		if val then
			table.insert(data, val)
			table.insert(dims, i)
			if j[5] then
				break
			end
		end
	end
	if #data == 0 then
		return nil
	end
	if #data == 1 then
		label = dimensions[dims[1]][4] 
	else
		for i, j in pairs(dims) do dims[i] = dimensions[j][2] end
		label = label .. linguistic.inparentheses(linguistic.conj(dims, ' × '))
	end

	local val = linguistic.conj(data, ' × ') .. ' ' .. unit
	if propertyused then
		val = wikidata.formatAndCat{entity = item, property = propertyused, value = val}
	end
		
	return {
		type = 'row',
		label = label,
		value = function() return val end
	}
end

return {
	maincolor = '#f9f9f9',
	parts = {
		{
			type = 'title',
			value = 'titre',
			subtitle = 'titre original',
			style = {['font-style'] = 'italic'} -- ajouter une option pour supprimer l'italique ?
		},
		general.mainimage("Article à illustrer Art"),
		{type = 'table', rows = {
		{
			type = 'row',
			label = 'Artiste',
			plurallabel = 'Artistes',
			value = 'artiste',
			wikidata = {
				property = 'P170',
				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 = wikidata.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 = wikidata.formatStatement(statement, {speciallabels = {Q4233718 = "anonyme"}}) -- speciallabels pour éviter le lien par défaut
					end
					return str
					end
			}
		},
		{
			type = 'row',
			label = 'Date',
			value = 'année',
			wikidata = function() return wikidata.wikidataDate('P571', item, {linktopic = linktopic}) end -- affiche les dates de début et fin utilisées dans les qualificatifs

		},
		{
			type = 'row',
			label = 'Commanditaire',
			plurallabel = 'Commanditaires',
			value = 'commanditaire',
			property = 'P88'
		},
		{
			type = 'row',
			label = 'Type',
			value = 'type',
		},
		{
			type = 'row',
			label = 'Technique',
			plurallabel= 'Techniques',
			value = 'technique',
			property = 'P2079'
		},
		{
			type = 'row',
			label = 'Matériau',
			value = function(localdata, item)
				if localdata['type'] or localdata['technique'] then  -- la matériau est parfois contenu dans le paramètre "type", ne pas utiliser wikidata dans ce cas
					return nil
				end
				return material.formatFromItem(item)
				end
		},
		{
			type = 'row',
			label = 'Lieu de création',
			plurallabel = 'Lieux de création',
			value = 'lieu de création',
			property = 'P1071'
		},
		dimensions(),

		{
			type = 'row',
			label = 'Format',
			value = 'format'
		},
		{
			type = 'row',
			label = 'Mouvement',
			plurallabel = 'Mouvements',
			value = 'style',
			property = 'P135',
		},
		{
			type = 'row',
			label = 'Localisation',
			value = function(localdata, item)
				local museum, city, location, country = localdata['musée'], localdata['ville'], localdata['localisation'], localdata['pays']
				location = linguistic.conj({museum, location, city}, 'comma')
				country = linguistic.inparentheses(country)
				if location or country then
					return (location or '') .. ' ' .. (country or '')
				end
				return nil
			end,
			property = 'P276' -- devrait croiser P195 et utiliser l'arbitrary access pour le lieu
		},
		{
			type = 'row',
			label = 'Propriétaire',
			plurallabel = 'Propriétaires',
			value = 'propriétaire',
			wikidata = function(item) return owner.formatFromItem(item) end
		},
		{
			type = 'row',
			label = 'Numéro d’inventaire',
			value = 'inventaire',
			property = 'P217'
		},
--[[
		{
			type = 'row',
			label = 'Représente',
			value = 'représente',
			wikidata = {property = 'P180', numval = '4', rank = 'best'}
		},
]]--
		{
			type = 'row',
			label = 'Inscription',
			plurallabel = 'Inscriptions',
			value = 'inscription',
			wikidata = {property = 'P1684', conjtype = '<br />', numval = '3', rank = 'best'}
		},
		{	
			type = 'row',
			label = 'Commentaire',
			value = 'commentaire',
		},
		{
			type = 'row',
			label = 'Protection',
			value = function(localdata) return localdata['protection'] or localdata['classement'] end,
			wikidata = function(item) return protected.formattedList(item)end
		},
		geoloc.coordinates({maintenancecat = "Œuvre d'art géolocalisable sans coordonnées paramétrées"}),
		}
		},
		geoloc.geoloc('default', '-'), -- le '-' indique de ne pas chercher automatiquement une carte si aucune n'est fournie dans |géolocalisation=
	}
}