Aller au contenu

Module:Infobox/Localité d'Iran

Une page de Wikipédia, l'encyclopédie libre.
Ceci est une version archivée de cette page, en date du 16 août 2023 à 21:55 et modifiée en dernier par Darknessswamp8 (discuter | contributions) (Un peu de deplacement). 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 Localité d'Iran.


local localdata = require 'Module:Infobox/Localdata'
local general = require "Module:Infobox/Fonctions"
local building = require "Module:Infobox/Fonctions/Bâtiment"
local wikidata = require "Module:Wikidata"
local linguistic = require "Module:Linguistique"
local convert = require "Module:Conversion"
local str = require "Module:Str"
local lng = require "Module:Langue"
local country = wikidata.stringTable{entity = localdata.item, property = "P17", displayformat = "raw"}
local countryid
if country then
	countryid = country[1]
end

local defaultlinks = { -- version de Wikipédia à utiliser pour les liens en l'absence d'article français
	Q17 = 'jawiki', -- Japon
	Q182 = 'dewiki', -- Allemagne
	Q40 = 'dewiki',	-- Autriche
	Q38 = 'itwiki', -- Italie
	Q29 = 'eswiki', -- Espagne
	Q96 = 'eswiki', -- Mexique
}
local defaultlink = {'enwiki'}
if defaultlinks[countryid] then
	table.insert(defaultlink, defaultlinks[countryid])
end


local function getVal(addargs) -- pour une propriété donnée, retourne la meilleure valeur, ainsi que sa date, sa référence, et si ça vient ou non de Wikidata
	local args = {numval = 1, entity = localdata.item, showunit = '-', displayformat = 'raw', precision = 'year'}
	for i, j in pairs(addargs or {}) do
		args[i] = j
	end
	local statements = wikidata.getClaims(args)
	if not statements then
		return nil
	end
	local val = statements[1]
	local v = wikidata.formatStatement(val, args)
	local period = wikidata.getFormattedDate(val, args)
 	local ref = nil -- TODO : fonction dans Module:Wikidata pour récupérer les refs
 	
 	return v, period, ref, args.property
end



-- Fonctions de récupération de données valables dans plusieurs champs (et appelées plusieurs fois)

local pop, popdate, popref, popprop = localdata["population"], localdata["année pop"], localdata["population notes"], nil
if not pop then
	pop, popdate, popref, popprop = getVal({property = "P1082", sorttype="inverted"})
end

local area, areadate, arearef, areaprop = localdata["superficie"], localdata["année superficie"], localdata["superficie notes"], nil
if not area then
	area, areadate, arearef, areaprop = getVal({property = "P2046", targetunit = "square kilometer", sorttype="inverted"})
end

if pop then pop = tonumber(pop) end
if area then area = tonumber(area) end

-- Fonctions de mise en forme

local function formatVal(val, period, ref, prop)
	local s = tostring(val)
	if period then
		s = s .. "<small>" .. linguistic.inparentheses(period) .. "</small>"
	end
	if ref then
		s = s .. "<ref>" .. ref .. "</ref>"
	end
	
	if prop then
		s = wikidata.formatAndCat{entity = localdata.item, property = prop, value = s} -- permet de mettre le rétrolien à la fin
	end
	return s
end

local function formatPop()
	if not pop then
		return nil
	end
	
	local popstr = convert.displayvalue(pop)
	popstr = string.gsub(popstr, "+", "") -- devrait être fait en amont
	popstr = popstr .. " hab."
	
	return formatVal(popstr, popdate, popref, popprop)
end

local function formatArea()
	if not area then
		return nil
	end

	-- arrondi
	local rounding = 2
	if area < 1 then
		rounding = 2
	end
	
	-- conversion en hectares si trop petit ?
	
	local areastr = convert.displayvalue(area, 'square kilometer', {showunit = true, rounding = rounding})
	return formatVal(areastr, areadate, arearef, areaprop)
end

local function density()
	-- TODO : vérifier que la date de la population correspond à celle de la superficie, pour les quelque cas de changements de frontière

	if not (pop and area) then
		return nil
	end
	local density = pop / area
	local rounding = 1
	if density < 0.1 then
		rounding = 2
	end
	local s = convert.displayvalue(density, nil, {rounding = rounding})
	s = s .. " hab./km<sup>2</sup>"
	
	return formatVal(s, popdate)
end

-- divisions administratives

--- par paramètres locaux
local function localDivRows() -- liste de lignes de divisions administrative basée sur des données locales
	local rows = {}
	local hasrows = false -- devient vraie si une valeur est non null
	for i = 1, 10 do
		i = tostring(i)
		if i == "1" then
			i = ""
		end
		local param, labelparam = "division" .. i, "nom division" .. i --"nom de division" .. i
		if localdata[param] then
			hasrows = true
			local label = localdata[labelparam] or "Subdivision"
			table.insert(rows, {type = "row", label = label, value = function() return localdata[param] end})
		end
	end
	if hasrows then
		return rows
	end
end

--======================================

local natureformats = {
	--{élément Wikidata, nom charte, couleur titre, couleur sous-titre, couleur texte, icône)  doivent être classés du plus spécifique au plus général
    {'Q23442' , 'île', '#7793E0', '' , '#FFFFFF', 'map'},
    {'Q123705', 'quartier' , '#ECE5CA' , '' , '' , 'map'},
    {'Q8502' , 'montagne' , '#996633', '' , '#FFFFFF' , 'map'},
    {'Q12280' , 'pont', '#D4D0BA' , '' , '' , 'map' },
}

local function setformat() --retourne une table contenant la couleur principale de l'infobox et l'icône de titre
	local natures = wikidata.getIds(localdata.item, {property = 'P31'}) -- récupère les Qid des natures

	if not natures or (#natures > 1) then -- si plusieurs natures, on ne sait pas lequel choisir
		return  {'Q', '', '#DDFFDD', '', '', 'map'}
	end
	natures = wikidata.addVals(natures, {property = 'P279'}, 2) -- nombre d'étages de sous-classes à remonter
	for i, j in pairs(natures) do
		for k, l in pairs(natureformats) do
			if l[1] == j then
				return l
			end
		end
	end
	return {'Q', '', '#DDFFDD', '', '' , 'map'}
end
local function setcharte()
	local charte = localdata['charte']
	if charte then
		for i, j in pairs(natureformats) do
			if j[2] == charte then
				return j
			end
		end
	end
	return setformat()
end
local natureformat = setcharte()
return {
	maincolor = natureformat[3],
	secondcolor = natureformat[4],
	thirdcolor = natureformat[5],
	parts =
    	{
			general.title(natureformat[6]),
			general.logo(),
			general.mainimage{ 
				cat = "Subdivision administrative illustrée par defaut.svg", 
				defaultimage = "Defaut 2.svg", 
				wikidata = {property = {"P2716", "P18", "P5252", "P3451", "P1766"}, numval = 1} 
			},
			{type = "table", title = "Administration", rows = {
				{type = "row", label = "Nom officiel", plurallabel = "Noms officiels", value = "nom officiel", wikidata = {property = "P1448", showlang = true, showdate = true, precision = 'year', sorttype = 'chronological', conjtype = 'new line'} },
				{type = "row", label = "Nom local", plurallabel = "Noms locaux", value = "nom local", wikidata = {property = "P1705", showlang = true} },
				{type = 'row', label = 'Surnom', plurallabel = "Surnoms", value = "surnom", property = 'P1449'}, -- autres noms
				general.country(),
				{type = "multi", rows = localDivRows() or general.wikidataDivRows(countryid) or {}},	
				{type = "row", label = "Île", value = "île", property = "P5130", showsource = true},
				{type = "row", label = "Localisation géographique", value = "localisation géographique", property = "P706"},
				{type = "row", label = "Partie de", value = "partie de", property = "P361", showsource = true},
				{type = "row", label = "Chef-lieu", value = "chef-lieu", property = "P36", showsource = true},
				{type = "row", label = "Capitale de", value = "capitale de",
					wikidata = {property = "P1376", showdate = true, precision = 'year', sorttype = 'chronological', conjtype = 'new line', showsource = true}
				},
				{type = "row", label = "Revendiqué par", value = "revendiqué par", property = "P1336", showsource = true},
				{type = "row", label = "Baigné par", value = "baigné par", property = "P206", showsource = true},
				{type = "row", label = "Code postal", value = "code postal", property = "P281", showsource = true},
				{type = 'row', label = "[[Statistisches Bundesamt|AGS]]", value = "AGS",Iproperty = 'P439'},
				{type = 'row', label = "[[Statistique Indonésie|Code de desa]]", value = "BPS", property = 'P1588'},
				{type = "row", label = "[[Federal Information Processing Standard|Code FIPS]]", value = "FIPS", property = "P774"},
				{type = "row", label = "[[Geographic Names Information System|GNIS]]", value = "GNIS", wikidata = {property = "P590", urlpattern= "https://edits.nationalmap.gov/apps/gaz-domestic/public/summary/$1"}},
				{type = 'row', label = "[[Institut national de la statistique (Espagne)|INE]]", value = "INE municipalités", property = 'P772'},
				{type = 'row', label = "[[Code Insee|INSEE]]", value = 'INSEE', property = 'P374'},
				{type = 'row', label = "[[Istituto nazionale di statistica|ISTAT]]", value = "ISTAT", property = 'P635'},
				{type = 'row', label = "Code [[Departamento Administrativo Nacional de Estadística|DANE]]", value = "DANE", property = 'P7325'},
				{type = 'row', label = "[[OKATO]]", value = "OKATO", property = 'P721'},
				{type = 'row', label = "[[Office for National Statistics|Code ONS]]", value = "ONS"},
				{type = 'row', label = "[[Classification géographique type|CGT]]", value = "statcan","CGT", property="P3012"},
				{type = 'row', label = "TGN", value = "TGN", wikidata = {property = "P1667", urlpattern= "http://vocab.getty.edu/page/tgn/$1"}},
				{type = "row", label = "[[Liste des indicatifs téléphoniques internationaux par indicatif|Indicatif téléphonique]]", value = "indicatif téléphonique", property = "P473", showsource = true},
				{type = 'row', label = "[[Plaque d'immatriculation|Immatriculation]]", value = 'immatriculation', property = 'P395', showsource = true},
				general.website(),
				{type = "row", label = "Représenté par", value = "représenté par", property = "P1875", showsource = true},
				{type = "row", label = "Distinction", plurallabel = "Distinctions", value = "distinction", wikidata = {property = "P166", showdate = true}, showsource = true},
				}
			},
			general.locationmap(),
			{type = "table", title = "Démographie", rows = {
				{type = "row", label = "Population", value = function() return formatPop() end },
				{type = "row", label = "Densité", value = function() return density() end},
				{type = "row", label = "Gentilé", value = "gentilé", property = "P1549", showlang = true, showsource = true},
				}
			},
			{type = "table", title = "Fonctionnement", rows = {
				{type = "row", label = "Statut", value = "statut", wikidata = {property = "P31",
					excludevalues = {"Q515", "Q532", "Q486972", "Q123705", "Q3957", "Q3257686", "Q23413", "Q82794", "Q1549591", "Q15661340", "Q23442", "Q23442", "Q33837", "Q37901", "Q37901", "93352", "Q1637706", "Q50330360", "Q8502", "Q39594", "Q207524", "Q27590", "Q40080", "Q839954","Q1021711"}, -- exclut les valeurs qui ne correspondent pas à un statut administratif
					defaultlinkquery = {property = "P2354"}, showdate = true}, showsource = true}, 
				{type = 'row', label = 'Constitution', value = 'constitution'},
				{type = "row", label = localdata["libellé chef de l'exécutif"] or "Chef de l'exécutif", value = "chef de l'exécutif", wikidata = {property = "P6", showdate = true, textformat = 'long', sorttype="inverted", numval = 1}, showsource = true}, -- pour le libellé : utiliser P1313 poste occupé par le chef de l'exécutif" ? il faudrait voir comment retraiter les cas comme Q31388880 "maire de Brême"
				{type = "row", label = "Assemblée délibérante", value = "assemblée", wikidata = {property = "P194", defaultlink = defaultlink}, showsource = true},
				{type = "row", label = "Équipement", plurallabel = "Équipements", value = "équipement", property = "P912", showsource = true},
				{type = "row", label = "Employés", value = "employés", property = "P1128", showsource = true},
				{type = "row", label = "Géographie", value = "géographie", property = "P2633", showsource = true},
				{type = "row", label = "Économie", value = "économie", property = "P8744", showsource = true},
				building.protection(),
				{type = "row", label = "[[Propriété contributrice à un district historique|Propriété contributrice]]", plurallabel = "[[Propriété contributrice à un district historique|Propriétés contributrices]]", value = "propriété contributrice", wikidata = {property = "P527", numval = "5", showdate = true, textformat = "minimum", precision = "year", sorttype = "chronological", qualifier = "P3831", qualifiervalue = "Q1129142"}, showsource = true},
				{type = "row", label = "Contient la localité", plurallabel = "Contient les localités",value = "contient la localité", wikidata = {property = "P1383", showdate = true}, showsource = true},
				{type = "row", label = "Membre de", value = "membre de", wikidata = {property = "P463", showdate = true}, showsource = true},
				{type = "row", label = "Jumelage", plurallabel = "Jumelages", value = "jumelage", wikidata = {property = "P190", showdate = true}, showsource = true},
				{type = 'row', label = "[[Office de tourisme|Informations]]", value = "informations", wikidata = {property = 'P2872', numval = '1'}, showsource = true},
				}
			},
			{type = "table", title = "Histoire", rows = {
				{type = "row", label = "Origine du nom", value = "origine du nom", property = "P138", showsource = true},
				{type = "row", label = "Concepteur", plurallabel = "Concepteurs", value = "concepteur", property = "P287", showsource = true},
				{type = "row", label = "Fondation", value = "fondation", property = "P571", showsource = true},
				{type = "row", label = "Fondateur", plurallabel = "Fondateurs", value = "fondateur", property = "P112", showsource = true},
				{type = "row", label = "Architecte", plurallabel = "Architectes", value = "architecte", property = "P84", showsource = true},
				building.archistyle(),
				{type = "row", label = "Remplace", value = "remplace", property = "P1365", showsource = true},
				{type = "row", label = "Remplacé par", value = "remplacé par", property = "P1366", showsource = true},
				{type = "row", label = "Événement clé", plurallabel = "Événements clés", value = "événement clé", wikidata = {property = "P793", showdate = true}, showsource = true},
				{type = 'row', label = 'Histoire', value = 'histoire', wikidata = {property = 'P2184', withlink = 'frwiki', numval = '1'}, showsource = true},
				{type = "row", value = "dissolution", property = "P576", showsource = true , label = function() return localdata['intitulé dissolution'] or 'Dissolution' end, },
				{type = "row", label = "Direction des fouilles", value = "fouilles", property = "P4345", showsource = true},
				{type = "row", label = "ISO 3166-2", value = "iso", property = "P300", showsource = true},
				{type = "row", label = "Langue officielle", plurallabel = "Langues officielles", value = "langue officielle", property = "P37", showsource = true},
				{type = "row", label = "Symbole", plurallabel = "Symboles", value = "symbole", property = "P2238", showsource = true},
				{type = "row", label = "Fête", plurallabel = "Fêtes", value = "fête", property = "P841", showsource = true},
				{type = "row", label = "Plat traditionnel", plurallabel = "Plats traditionnels", value = "plat traditionnel", property = "P868", showsource = true},
				}
			},
			{type = "table", title = "Géographie", rows = {
				{type = "row", label = "Superficie", value = function() return formatArea() end },
				{type = "row", label = "Surface en eau", value = "surface en eau", property = "P2927", showsource = true},
				{type = "row", label = "Subdivision", plurallabel = "Subdivisions", value = "subdivision", wikidata =
					function(item)
					local vals = wikidata.getClaims{entity = item, property = 'P150', atdate = 'today'}
					if (not vals) or (#vals > 5) then -- si trop de subdivisions, il faut les mettre dans le corps du texte, c'est pas lisible en infobox
						return nil
					end
					return wikidata.formatAndCat{claims = vals, property = 'P150', defaultlink = defaultlink, conjtype = 'new line'}, #vals
					end
				},
				{type = "row", label = "Point le plus bas", plurallabel = "Points les plus bas", value = "point le plus bas", property = "P1589", showsource = true},
				{type = "row", label = "Point culminant", plurallabel = "Points culminants", value = "point culminant", property = "P610", showsource = true},
				{type = "row", label = "Altitude", value = "altitude", wikidata = {property = "P2044", targetunit = "metre", rounding = "0"} , showsource = true},
				building.mountainrange(),
				{type = "row", label = "Aire protégée", plurallabel = "Aires protégées", value = "aire protégée", wikidata = {property = "P3018", showqualifiers = "P518"}, showsource = true},
				{type = "row", label = "Géographie", value = "géographie", property = "P2633", showsource = true},
				general.coordinates(),
				}
			},
			general.geoloc({default_zoom = 7, marker = 'village', maptype = localdata["type carte"], width = localdata["taille carte"]}),
			general.prononciation(),
	}
}