Module:Infobox/Fonctions/Géolocalisation

De Lagny-sur-Marne Wiki
Aller à : navigation, rechercher

La documentation pour ce module peut être créée à Module:Infobox/Fonctions/Géolocalisation/doc

local coord = require('Module:Coordinates')
local wikidatamod = require('Module:Wikidata')
local p = {}


local p = {}
function p.country(country, label, flagdate, size) -- à faire : gestion des dates, mapping Wikidata/modèles, peut-être mettre une partie de la fonction dans un module séparé
	return function(localdata, item)
	if localdata['country'] then -- priorité aux données locales
		country =  localdata['country']
	end
	if not country then -- si le pays n'est ni sur la page ni dans le module d'infobox, essayer wikidata
		country = wikidata.formatStatements({item=item, property = 'P17'})
	end  
	if not country then
		return nil
	end
	local countrydata = require('Module:Country data')[mw.ustring.lower(country)]
	if not countrydata then
		return country 
	end
	if countrydata['alias'] then
		country =  '[[' .. countrydata['alias'] .. ']]'
	end
	
	if not label then
		label = 'Pays'
	end
	if not size then
		size = '22x20'
	end
	
	local flag = countrydata['flag alias']
	if flag then
		flag = '<span class="flagicon">[[File:' .. flag .. '|' .. size .. 'px' .. ']]</span>'
	else 
		flag = ''
	end
	local val = flag .. ' ' .. country
	
	return  {
		type = 'mixed',
		label = label,
		value = val,
	}
	end
end

function p.coordinates(moduleparams)
	-- initialise les paramètres avec les valeurs du module d'infobox (moduleparams)
	if not moduleparams then moduleparams = {} end
	local globe = moduleparams.globe
	local displayinline = moduleparams.displayinline
	local displaytitle = moduleparams.displaytitle
	local displayformat = moduleparams.displayformat
	if not displaytitle then displaytitle = 'title' end -- displayinline et displaytitle sont des chaînes à utiliser dans le paramètre "display" de coord
	if not displayinline then displayinline = 'inline' end

	return function(localdata, item)
		
		-- vérifie qu'il faut afficher les coordonnées
		if localdata["géolocalisation"] == 'pas pertinent' or localdata['géolocalisation'] == 'non' then
			if not (localdata['coordonnées'] == 'oui') then
			return nil
		end end
		
		-- si paramètres donnés dans l'article, écrasent les autres
		if localdata['format coordonnées'] then
			displayformat = localdata['format coordonnées']
		end
		if localdata['coords en titre'] == 'oui' then
			local displaytitle = 'title'
		end
		if localdata['coords en titre'] == 'non' or  localdata['coords en titre'] == '-' then
			displaytitle = ''
		end
		if localdata['coords en en ligne'] == 'oui' then
			displayinline = 'inline'
		end
		if localdata['coords en en ligne'] == 'non' or localdata['coords en en ligne'] == '-' then
			displayinline = ''
		end	
		local displayplace = displaytitle .. ',' .. displayinline
		local latitude = localdata['latitude']
		local longitude = localdata['longitude']
		if localdata['globe'] then
			globe = localdata['globe']
		end
		local wikidata = localdata['wikidata'] or 'true'
		if displayinline == '' then
			return -- type: external text pour ne pas avoir de ligne vide en infobox
			{
			type = 'external text',
			maintenancecat = 'Page géolocalisable sans coordonnées paramétrées',
			sortkey = sortkey,
 			value =
 				function(localdata, item)
 					return coord._coord({latitude = latitude, longitude = longitude, displayformat = displayformat, display= displayplace, globe = globe, wikidata =wikidata})
 			end
 		}
 		else return
 			{
		type = 'mixed',
		label = 'Coordonnées',
		maintenancecat = 'Page géolocalisable sans coordonnées paramétrées',
		sortkey = sortkey,
 		value =
 			function(localdata, item)
 				return coord._coord({latitude = latitude, longitude = longitude, displayformat = displayformat, display= displayplace, globe = globe, wikidata =wikidata})
 			end
 		}	
	end end
end

function p.geoloc(maplist)
	return   {
		type = 'map',
		latitude = 'latitude',
		longitude = 'longitude',
		wikidata = function(localdata, item) return wikidatamod.getClaims{item = item, property = 'P625'} end,
		maps = function(localdata, item)
					local str
					if localdata['géolocalisation'] then
						str = localdata['géolocalisation']
					elseif maplist then
						str = maplist
					end
					if str then
						return mw.text.split( str, '/', true)
					end
					end
     }
 
end
return p