Modulo:Sandbox/Laurentius: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Nessun oggetto della modifica
Omega Bot (discussione | contributi)
m Bot: rimuovo no globals obsoleto
 
(10 versioni intermedie di un altro utente non mostrate)
Riga 1:
-- Modulo per gestire le liste di monumenti di Wiki Loves Monuments
 
require('Module:No globalsstrict')
local getArgs = require('Module:Arguments').getArgs
local mWikidata = require('Modulo:Wikidata')
Riga 7:
local p = {}
 
function p.map_point(qid)
-- Associa il nome della regione (come usato nelle sottopagine di
local data = {}
-- [[Progetto:Wiki Loves Monuments 2019/Monumenti]] con il nome (inglese)
local desc = ''
-- usato nelle categorie su Commons e la presenza o meno di un concorso regionale
local regioni = {
desc = desc .. '{{WLM-link-2019|' .. qid .. '}}'
['Abruzzo'] = {'Abruzzo', false},
local img = mWikidata._getProperty({'P18', from = qid, snaktype = 'value', n=1, pattern="[[File:$1|200px]]"})
['Basilicata'] = {'Basilicata', true},
if img then
['Calabria'] = {'Calabria', false},
['Campania'] desc = {desc .. 'Campania<br/>', false},.. img
['Emilia-Romagna'] = {'Emilia-Romagna', false},
['Friuli-Venezia Giulia'] = {'Friuli-Venezia Giulia', false},
['Lazio'] = {'Lazio', false},
['Liguria'] = {'Liguria', true},
['Lombardia'] = {'Lombardy', false},
['Marche'] = {'Marche', false},
['Molise'] = {'Molise', false},
['Piemonte'] = {'Piedmont', false},
['Puglia'] = {'Apulia', false},
['Sardegna'] = {'Sardinia', false},
['Sicilia'] = {'Sicily', false},
['Toscana'] = {'Tuscany', true},
['Trentino-Alto Adige'] = {'Trentino-South Tyrol', false},
['Umbria'] = {'Umbria', true},
['Valle d\'Aosta'] = {'Aosta Valley', false},
['Veneto'] = {'Veneto', true},
}
 
local function titleparts(inputstr)
local t = {}
for str in mw.ustring.gmatch(inputstr, "([^/]+)") do
table.insert(t, str)
end
data.type = "Feature"
return t
data.properties = {
title = mWikidata._getLink({qid}),
description = desc,
["marker-color"] = "#B80000"
}
data.geometry = {
type = "Point",
coordinates = {
tonumber(mWikidata._getProperty({'P625', from = qid, snaktype = 'value', coord='longitude', n=1})),
tonumber(mWikidata._getProperty({'P625', from = qid, snaktype = 'value', coord='latitude', n=1}))
}
}
return data
end
 
function p._map_data(args)
-- se il monumento ha una categoria associata, restituisce quella.
local points = {}
-- Altrimenti, quella del comune.
local function get_main_category(qid, comcat)
local category = comcat or mWikidata._getProperty({'P373', from = qid, snaktype = 'value'})
if category then
return {category, 'Foto del monumento'}
else
category = mWikidata._getProperty({'P131', from = qid, showprop = 'P373', snaktype = 'value'})
return {category, 'Foto nel comune'}
end
end
 
function p.main_category(frame)
local args = getArgs(frame)
local cat = get_main_category(args[1], args.comcat)
return '[[c:Category:' .. cat[1] .. '|' .. cat[2] .. ']]'
end
 
function p.categories(frame)
local args = getArgs(frame)
local qid = args[1]
 
local categories = {}
local lake_como = false
 
-- categoria principale
table.insert(categories, get_main_category(qid, args.comcat)[1])
 
if args.area then
-- alberi monumentali
local shape = {
if mWikidata._instanceOf({'Q811534', from = qid}) then
type = "ExternalData",
table.insert(categories, 'Images from Wiki Loves Monuments 2019 in Italy - veteran trees')
service = "geoshape",
ids = args.area,
service = "geomask"
}
table.insert(points, shape)
end
 
--for Wiki_, Lovesqid Lakein Comoipairs(args) do
if mWikidata._getProperty({'P625', from = qid, snaktype = 'value'}) then
local tp = titleparts(mw.title.getCurrentTitle().fullText)
table.insert(points, p.map_point(qid))
local provincia = tp[4]
end
if provincia == 'Provincia di Como' or provincia == 'Provincia di Lecco' then
table.insert(categories, 'Images from Wiki Loves Monuments 2019 in Italy - Lake Como')
lake_como = true
end
 
return mw.text.jsonEncode(points)
-- foto per regione
end
local regione = tp[3]
if regioni[regione] then
table.insert(categories, 'Images from Wiki Loves Monuments 2019 in Italy - ' .. regioni[regione][1])
if not regioni[regione][2] and not lake_como then
table.insert(categories, 'Images from Wiki Loves Monuments 2019 in Italy - without regional award')
end
else
table.insert(categories, 'Images from Wiki Loves Monuments 2019 in Italy - unknown region')
end
 
function p.map_data(frame)
return table.concat(categories, '|')
local args = getArgs(frame)
return p._map_data(args)
end