Moduuli:Fr:Infobox/paikkakunta

Leningradin alue
Ленинградская областьView and modify data on Wikidata
Sijainti
187000–188999 Venäjä
Pääkaupunki
Pinta-ala
83 900 km2View and modify data on Wikidata
Väkiluku
2 040 000 as.  ()View and modify data on Wikidata
Asukastiheys
24 as./km2  ()
Hallinnon johtaja
Alexander Drozdenko (en) (käännä suomeksi) ( – )[1]View and modify data on Wikidata
Perustettu
Edeltäjä
Virallinen kieli
Kumppanuus
Postinumero
187000–188999View and modify data on Wikidata
Suuntanumero
813View and modify data on Wikidata
Verkkosivusto
Kartta
Koordinaatit
Kalifornia
State of CaliforniaView and modify data on Wikidata

Ääntäminen

Sijainti
Pääkaupunki
Vesistö
Pinta-ala
424 000 km2View and modify data on Wikidata
Korkein kohta
Syvin kohta
Korkeus merenpinnasta
884 mView and modify data on Wikidata
Väkiluku
39 500 000 as.  ()View and modify data on Wikidata
Asukastiheys
93 as./km2  ()
Hallinnon johtaja
Edustuspaikat
Perustettu
Edeltäjä
Kalifornian tasavalta
Alta California Territory (en) (käännä suomeksi)View and modify data on Wikidata
Virallinen kieli
Motto
EurekaView and modify data on Wikidata
Lippu
Kansallislaulu
I Love You, California (en)View and modify data on Wikidata
Symbolit
Kaliforniantuliunikko, Kaliforniantupsuviiriäinen, Kalifornian tartaani (en), Cantharellus californicus (en)View and modify data on Wikidata
Kumppanuus
Verkkosivusto
Kartta
Koordinaatit



  1. http://lenobl.ru/gubernator/biografiya/. Tieto on haettu Wikidatasta.
local localdata = require 'Module:Fr:Infobox/Localdata'
local general = require "Module:Fr:Infobox/Fonctions"
local wikidata = require "Module:Fr:Wikidata"
local linguistic = require "Module:Fr:Linguistique"
local convert = require "Module:Fr:Conversion"
local analysis = require 'Module:Fr:Wikidata/Analyse transitive'
local tools = require 'Module:Fr:Wikidata/Outils'
local building = require 'Module:Fr:Infobox/Fonctions/Bâtiment'
local country = wikidata.stringTable{entity = localdata.item, property = "P17", displayformat = "raw"}
local countryid
if country then
	countryid = country[1]
end

local defaultlink = {'fiwiki'}


local function round(numval, precision)
  local multiplier = 10^(precision or 0)
  return math.floor(numval * multiplier + 0.5) / multiplier
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["väkiluku"], localdata["väkiluku_vuosi"], localdata["väkiluku_huom"], nil
if not pop then
	pop, popdate, popref, popprop = getVal({property = "P1082", sorttype="inverted"})
end

local area, areadate, arearef, areaprop = localdata["pinta-ala"], localdata["pinta-ala_vuosi"], localdata["pinta-ala_huom"], 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 .. "&nbsp;<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 rpop = pop
	if (pop < 100) then
		rpop = round(pop, 0)
	elseif (pop < 1000) then
		rpop = round(pop, -1)	
	elseif (pop < 10000) then
		rpop = round(pop, -2)
	elseif (pop < 1000000) then
		rpop = round(pop, -3)
	elseif (pop < 10000000) then
		rpop = round(pop, -4)
	else
		rpop = round(pop, -5)
	end
	
	local popstr = convert.displayvalue(rpop)
	popstr = string.gsub(popstr, "+", "") -- devrait être fait en amont
	popstr = popstr .. " as."
	
	return formatVal(popstr, popdate, popref, popprop)
end

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

	-- arrondi
	local rarea = area
	local rounding = 0
	if (area < 1) then
		rounding = 2
	elseif (area < 10) then
		rounding = 1
	elseif (area < 1000) then
		rarea = round(area, 0)
	elseif (area < 10000) then
		rarea = round(area, -1)
	elseif (area < 100000) then
		rarea = round(area, -2)
	else
		rarea = round(area, -3)
	end
	
	-- conversion en hectares si trop petit ?
	
	local areastr = convert.displayvalue(rarea, '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 = 0
	if (density < 1) then
		rounding = 2
	elseif (density < 10) then
		rounding = 1
	elseif (density < 10000) then
		density = round(density, 0)
	else
		density = round(density, -1)
	end

	local s = convert.displayvalue(density, nil, {rounding = rounding})
	s = s .. " as./km<sup>2</sup>"
	
	return formatVal(s, popdate)
end

-- divisions amdinistratives

--- 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

--- par Wikidata
local function wikidataDivRows()  -- liste de lignes de divisions administrative basée sur des données de Wikidata
	if not localdata.item then
		return nil
	end
	-- récupération des valeurs
	local list = analysis.transitiveVals(localdata.item, {property = "P131", atdate = "today", excludespecial = true}, 3, 5, countryid)
	if not list then
		return nil
	end

	-- création des colonnes
	local rows = {}
	for i, div in pairs(list) do
		if (div == countryid) then
			break
		end
		local rowlabel, rowlabelid, rowlabeltext, rowlabellink, rowvalue
		rowlabelid = wikidata.formatStatements{entity= div, property = 'P31', numval = 1, displayformat = 'raw', excludespecial = true}
		rowlabeltext = wikidata.getLabel(rowlabelid, 'fi', function(id) 
			local str = wikidata.getLabel(id)
			if str then
				return linguistic.ucfirst(linguistic.removecomplement(str))  -- imposé par les libellés pas très logiques sur Wikidata du genre "canton de Suisse" plutôt que "canton"		else
			end
				return ''
			end
		)
		if (not rowlabeltext) then
			rowlabeltext = 'Division'
		end
		rowlabellink = tools.siteLink(rowlabelid, {defaultlink = '-', defaultlinkquery= {property = "P2354"}} ) -- si pas de lien, lier vers la page de liste e.g liste des Etats de Californie

		if rowlabellink then
			rowlabel = "[[" .. rowlabellink .. "|" .. rowlabeltext .. "]]"
		else
			rowlabel = rowlabeltext
		end
		rowvalue = wikidata.formatEntity(div, {labelformat = function(id) 
			local str = wikidata.getLabel(id) or ""
			if mw.ustring.match(rowlabel, str) then
				str = linguistic.keepcomplement(str)-- si le nom de la division administrative affiché est présent, ne pas le répéter
			end
			return str
			end})
		
		table.insert(rows, 1, {type = "row", label = rowlabel, value = function() return rowvalue end})
	end
	return rows
end

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

return 
	{
	maincolor = "DDFFDD",
	parts =
    	{
			general.title( "map", {}, 'alkuperäinen_nimi', {property = 'P1705', showlang = false}),
			general.prononciation(),			
			general.mainimage{ 
				cat = "Subdivision administrative illustrée par defaut.svg", 
				wikidata = {property = {"P2716", "P18", "P1766"}, numval = 1} 
			},
			{
			type = 'images',
			imageparameters =  {'kuva_vaakuna', 'kuva_lippu'}, -- blason, drapeau
			wikidata = {property = {'P94', 'P41'}},
			numval = 2,
			defaultupright = '0.4',
			style={ ['padding-top']='0.5em'}
			},	
			general.logo(),
			{type = "table", title = "", rows = {
				{type = 'row', label = 'Taivaankappale', value = 'taivaankappale', wikidata = { property = 'P376', excludevalue = 'Q2' }}, -- corps astronomique où se trouve le lieu dont il est question (utile pour les lieux de fictions)
				function()
					if (not localdata["sijainti"]) then
						return building.adminlocation()
					end
				end,
				{type = "row", label = "saaressa", value = "saaressa", property = "P5130"},
				{type = "row", label = "Sijainti", value = "sijainti", property = "P706"},
				{type = "row", label = "[[Pääkaupunki]]", value = "pääkaupunki", wikidata={property = "P36"}, blockers={'hallinnollinen keskus'}},
				{type = "row", label = "Suurin kaupunki", value = "suurin_kaupunki" },				
				{type = "row", label = "Eksklaavi", value = "eksklaavi", property = "P500"},
				{type = "row", label = "Enklaavi", value = "enklaavi", property = "P501"},
				{type = "row", label = "Vesistö", value = "vesistö", property = "P206"},
				{type = "row", label = "Ilmasto", plurallabel = "Ilmastot", value = "ilmasto", property = "P2564"},
				{type = "row", label = "Pinta-ala", value = function() return formatArea() end },
--				{type = "row", label = "Vesiala", value = "vesiala", property = "P2927", showunit="short", showsource=true},
				{type = "row", label = "hallinnollinen osa", plurallabel = "Hallinnolliset osat", value = "hallinnolliset osat", wikidata =
					function(item)
					local vals = wikidata.getClaims{entity = item, property = 'P150', atdate = 'today'}
					if (not vals) or (#vals > 15) then -- si trop de subdivisions, il faut me 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
				},
				building.highestpoint(),
				building.lowestpoint(),				
				{type = "row", label = "Korkeus merenpinnasta", value = "korkeus merenpinnasta", wikidata = {property = "P2044", targetunit = "metre", rounding = "0", showsource=true} },
				{type = "row", label = "Suojelualue", plurallabel = "Suojelualue", value = "suojelualue", property = "P3018", showsource=true},
				{type = "row", label = "Väkiluku", value = function() return formatPop() end },
				{type = "row", label = "Asukastiheys", value = function() return density() end},
				{type = "row", label = "[[Inhimillisen kehityksen indeksi|HDI]]", value = "hdi", wikidata = {property = "P1081", showqualifiers = {"P585"} , sorttype="inverted", numval = 1, showsource=true}},
				{type = "row", label = "[[bruttokansantuote|BKT (PPP)]]", value = "", wikidata = {property = "P4010", showqualifiers = {"P585"} , sorttype="inverted", numval = 1, showsource=true, blockers={"gdp"} }},
				{type = "row", label = "[[bruttokansantuote|BKT]]", value = "gdp" },
				{type = "row", label = localdata["johtajan nimike"] or "Hallinnon johtaja", value = "johtaja", 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 = "Edustuspaikat", value = "edustus", wikidata = {property = "P1410", showqualifiers="P194", conjtype = 'new line'}},				
				{type = "row", label = "Asutuskeskus", plurallabel = "Asutuskeskukset", value = "asutuskeskus", wikidata = {property = "P1383", showdate = true}},
				{type = "row", label = "Perustettu", value = "perustamisajankohta", property = "P571", showsource=true},
				{type = "row", label = "Edeltäjä", value = "edeltäjä", wikidata = {property = "P1365,P155", conjtype = 'new line'}},
				{type = "row", label = "Seuraaja", value = "seuraaja", wikidata = {property = "P1366,P156", conjtype = 'new line'}},				
				{type = "row", label = "Tapahtuma", plurallabel = "Tapahtumat", value = "tapahtumat", property = "P793"},
				{type = "row", label = "Lopetettu", value = "lopetettu", property = "P576"},
				{type = "row", label = "Virallinen kieli", plurallabel = "Viralliset kielet", value = "virallinen kieli", property = "P37"},
				{type = 'row', label = "Kieli", plurallabel = "Kielet", value = "kielet" },			
--				{type = 'row', label = "Kieli", plurallabel = "Kielet", value = "kielet", wikidata = {property = 'P2936', showdate = 'true', showsource=true}},			
				{type = "row", label = "Motto", value = "motto", property = "P1451"},
				{type = "row", label = "Vaakuna", value = "vaakuna-artikkeli", wikidata = { property = "P237", withlink=true} },
				{type = "row", label = "Lippu", value = "lippuartikkeli", wikidata = {property = "P163", withlink=true}},
				{type = 'row', label = 'Kansallislaulu', plurallabel = 'Kansallislaulut', value = 'kansallislaulu', property = 'P85', showsource=true},
				{type = "row", label = "Symboli", plurallabel = "Symbolit", value = "symboli", property = "P2238"},
				{type = "row", label = "Juhlapäivä", plurallabel = "juhlapäivät", value = "juhlapäivä", property = "P841", showsource=true},
				{type = "row", label = "Perinneruoka", plurallabel = "Perinneruoat", value = "perinneruoka", property = "P868", showsource=true},
				{type = "row", label = "Kumppanuus", plurallabel = "Kumppanuudet", value = "ystävyyskaupunki", wikidata = {property = "P190", showdate = true, conjtype = 'new line'}},
				{type = "row", label = "Luokitus", value = "kulttuuriperintökohteen luokitus", wikidata = {property = "P1435", showdate = true}},
				{type = "row", label = "Postinumero", value = "postinumero", property = "P281", showsource=true},
				{type = "row", label = "[[Suuntanumero]]", value = "suuntanumero", property = "P473", showsource=true},
				{type = "row", label = "[[NUTS]]", value = "nuts", property = "P605"},
				general.website(),
				}
			},
			building.geoloc({marker = 'village'}),
			{type = 'table',  rows = {
				building.coordinates({displaytitle='-'}),
				}
			}
	}
}