local localdata = require( 'وحدة:ب.ص.م/بيانات' )
local item = localdata.item
local id
if item then
id = item.id
end
local wd = require "Module:Wikidata2"
-- Modules chargés si necessaire :
-- local countrymodule = require "Module:Country data"
-- local coord = require "Module:Coordinates"
local gdata = mw.loadData ("Module:Country data/liste" )
local p = {}
function p.country()
--[[local function formatCountry1(country)
if not country then
return nil
end
local countrymodule = require "Module:Country data"
local val, success = countrymodule.standarddisplay(country) -- val = nil si country n'est pas reconnu
if success then
return val
end
end
]]--
local function formatCountry(country)
if not country then
return nil
end
country = mw.ustring.lower(country)
if gdata[country] then
return mw.getCurrentFrame():expandTemplate({title="علم";args={gdata[country]}})
else -- si le module existe mais n'est pas dans la liste
return mw.getCurrentFrame():expandTemplate({title="علم";args={country}})
end
end
return {
type = 'mixed',
label = 'البلد',
value = function() return formatCountry(localdata['بلد']) or localdata['بلد'] end,
wikidata = {
property = 'P17',
conjtype = 'new line',
displayformat = function(snak)
local id = wd.getId(snak)
return formatCountry(id) or wd.formatSnak(snak)
end
}
}
end
function p.coordvalue(moduleparams) -- valeurs des coordonnées, sans mise en infoboîte
local coord = require "Module:Coordinates"
if not moduleparams then
moduleparams = {}
end
local function toboolean(val) -- transforme un "-" en false au moment voulu
if val == '-' or val == 'non' then
return false
end
return true
end
-- paramètres Wikidata
local wikidata = tostring(toboolean(localdata['wikidata'] or true)) -- doit être string dans Module:Coordinates
local maxdistance = moduleparams.maxdistance
local wikidataquery = moduleparams.wikidataquery or {property = 'P625'}
if not wikidataquery.entity then
wikidataquery.entity = item
end
-- paramètres d'affichage
local displayformat = localdata['format coordonnées'], moduleparams.displayformat
local displayplace = ''
local displayinline = toboolean(localdata['coords en ligne'] or moduleparams.displayinline or true)
-- par défaut : on met dans les coordonnées de l'infobox principale en titre
local displaytitle = localdata['coords en titre']
or moduleparams.displaytitle
or (localdata['infoboxrank'] == 'main')
if displayinline and (displayinline ~= '-') then
displayplace = displayplace .. 'inline'
end
if displaytitle and (displaytitle ~= '-') then
displayplace = displayplace .. 'title,'
end
-- données sur géograhiques
local globe = localdata['globe'] or localdata['planète'] or moduleparams['globe'] or 'earth'
local latitude = localdata['latitude']
local longitude = localdata['longitude']
local parameterlist = {
latitude = latitude,
longitude = longitude,
displayformat = displayformat,
display= displayplace,
globe = globe,
wikidata = wikidata,
wikidataquery = wikidataquery,
maxdistance = maxdistance,
}
local val = coord._coord({latitude,longitude}) --(parameterlist)
if (not val) and moduleparams.fallbackquery then -- si pas de valeur, essayer la query de sustitution
parameterlist.wikidataquery = moduleparams.fallbackquery
parameterlist.wikidataquery.entity = item
val = coord._coord(parameterlist)
end
if val and latitude and longitude and localdata['référence géolocalisation'] then
val = val .. ' ' .. localdata['référence géolocalisation']
end
if val and not localdata['latitude'] then
val = wd.addLinkBack(val, item, wikidataquery.property)
end
if displayinline == false then
return -- type: external text pour ne pas avoir de ligne vide en infobox
{
type = 'external text',
sortkey = sortkey,
value = val
}
else
return val
end
end
function p.coordinates(moduleparams)
if not moduleparams then
moduleparams = {}
end
-- paramètre coordonnées a la priorité sur "géolocalisation" (=carte)
local relevant = localdata['إحداثيات'] or localdata['احداثيات']
if relevant == '-' or relevant == 'non' then
return nil
end
-- initialise les paramètres avec les valeurs du module d'infobox (moduleparams)
return {
type = 'mixed',
label = 'الإحداثيات',
maintenancecat = moduleparams.maintenancecat or 'Page géolocalisable sans coordonnées paramétrées',
sortkey = moduleparams.sortkey,
value = function (localdata) return p.coordvalue(moduleparams) end
}
end
function p.geoloc(params)
if not params then
params = {}
end
if (localdata['خريطة الموقع'] == '-') then
return nil
end
return {
type = 'map',
latitude = {'latitude','دائرة عرض','دائرة العرض'},
longitude = {'longitude','خط طول','خط الطول'},
entity = item,
pointtype = params.pointtype,
maptype = params.type,
globe = localdata.globe or localdata['كوكب'] or params.globe,
marker = params.marker,
markercolor = params.markercolor,
shapecolor = params.shapecolor,
markersize= params.markersize,
markersymbol=params.markersymbol,
default_zoom = localdata['zoom'] or localdata['تكبير'] or params.default_zoom,
ids = params.ids or params.id or id,
}
end
function p.locationmap(size)
return {
type = 'images',
imageparameters = {'صورة خريطة'},
sizeparameter = 'حجم صورة خريطة',
captionparameter = {'تعليق صورة خريطة'},
defaultsize = size,
property = 'P242',
numval = 1,
}
end
return p