Modulo:Tabella beni culturali
Da Wikipedia, l'enciclopedia encyclopedia
require('strict')
local getArgs = require('Module:Arguments').getArgs local errorCategory = '' local p = {}
local function errhandler(msg) local cat = mw.title.getCurrentTitle().namespace == 0 and errorCategory or return string.format('%s%s', msg, cat) end
function p._tabella(frame, args)
local i = 1
local imappa = 1
local wmappac = {}
table.insert(wmappac,'\n{{Mappa OSM|dati = [ ')
local wid, entita, wlabel, wlink, wdesc, wimma, wtipo, wluogo, wluoghi, wcoord, wlat, wlon, wmappa, wcommons
local ww, t, wwid, wwlabel, wwlink
local comune
local comune2 =
local wTabella = {}
local mostramappa = tonumber(args['mappa']) or 0
table.insert(wTabella, '{| class="wikitable sortable" width=100%\n|-\n!style="width:45px|Num !!style="width:100px"|Immagine !!style="width:25%"|Elemento !!Tipologia !!style="width:25%"|Luogo !!style="width:50px"|Mappa !!style="width:50px"|Commons')
while args[i] do
wid = args[i]
entita = mw.wikibase.getEntity(wid)
if not entita then error('Entità ' .. wid .. ' non presente') end
wlabel = entita:getLabel('it')
if not wlabel then wlabel = end
wlabel = string.gsub(wlabel,'"',)
wlink = entita:getSitelink('itwiki')
if wlink then
if wlabel == then
wlink = '' .. wlink .. ''
else
wlink = '' .. wlabel .. ''
end
else
wlink = wlabel
end
wdesc = entita:getDescription('it')
if wdesc then
wdesc = '
\'\ .. wdesc .. '\'\''
else
wdesc =
end
wtipo = entita:formatPropertyValues('P31').value
wluogo =
wimma =
if entita.claims then
t = entita.claims['P18']
if t then
wimma = '[[File:' .. t[1].mainsnak.datavalue.value .. '|80x80px]]'
else
wimma = '
ww = 1 t = entita.claims['P131'] comune = while t[ww] do wwid = t[ww].mainsnak.datavalue.value.id if string.len(comune)>0 then comune = comune .. ',' .. wwid else comune = wwid end if string.len(comune2)>0 then comune2 = comune2 .. ',' .. wwid else comune2 = wwid end wwlabel = mw.wikibase.getLabel(wwid) wwlink = mw.wikibase.getSitelink(wwid,'itwiki') if wwlink then if wwlabel then wluogo = wluogo .. '• ' .. wwlabel .. ' ' else wluogo = wluogo .. '• ' .. wwlink .. ' ' end else if wwlabel then wluogo = wluogo .. '• ' .. wwlink else wluogo = wluogo .. '• ...' end end ww = ww+1 end end
wcommons = entita:formatPropertyValues('P373').value
if wcommons ~= then
wcommons = ''
end
wcoord = entita:formatPropertyValues('P625').value
if wcoord ~= "" then
wlat = entita.claims.P625[1].mainsnak.datavalue.value.latitude
wlon = entita.claims.P625[1].mainsnak.datavalue.value.longitude
wmappa = '
'
table.insert(wmappac,'{ "type": "Feature", "properties": {"title": "['.. i .. '] ' .. wlabel ..'", "marker-color": "0060c0"},'..
'"geometry": { "type": "Point", "coordinates": [ '.. wlon .. ',' .. wlat ..' ] } },')
imappa = imappa + 1
else
wmappa =
end
table.insert(wTabella, '\n|-')
--if (i == 2*math.floor(i/2)) then table.insert(wTabella, ' style="background-color:#f0f2f4"') end
table.insert(wTabella, '\n|align=center| ' .. i)
table.insert(wTabella, '\n|align=center| ' .. wimma)
table.insert(wTabella, '\n| ')
table.insert(wTabella, wlink)
table.insert(wTabella, wdesc)
table.insert(wTabella, '\n|style="font-size:90%"|' .. wtipo)
table.insert(wTabella, '\n| ' .. wluogo)
table.insert(wTabella, '\n|align=center| ' .. wmappa)
table.insert(wTabella, '\n|align=center| ' .. wcommons)
i = i+1
end
table.insert(wTabella,'\n|}\n')
table.insert(wmappac,' { "type": "ExternalData", "service": "geoshape", "ids": "' .. comune2 ..'", "properties": { "stroke": "#0060c0", "fill-opacity": 0 } } ] |cornice=0|allinea=center|larghezza=600}}\n')
if (mostramappa == 1 and imappa>1) then table.insert(wmappac, table.concat(wTabella)) return frame:preprocess(table.concat(wmappac)) else return frame:preprocess(table.concat(wTabella)) end end
function p.tabella(frame) return select(2, xpcall(function() return p._tabella(frame,getArgs(frame, { parentOnly = true })) end, errhandler))end return p