--[[
* Modulo che implementa i template Sito ufficiale e Blog ufficiale.
]]--
require('Modulo:No globals')
local mWikidata = require('Modulo:Wikidata')
local p = {}
local function formatWebsite(website)
return mw.getCurrentFrame():expandTemplate {
title = 'Cita web',
args = {
url = website.url,
titolo = 'Sito ufficiale',
lingua = table.concat(website.langs, ' ')
}
}
end
local function getWebsites(frame)
local claims
local websites = {}
claims = mWikidata._getClaims(frame.args.pid) or {}
for idx, claim in ipairs(claims) do
local langs = mWikidata._formatQualifiers(claim, 'P407', { formatting = 'raw' }, true)
langs = (#langs == 1 and langs[1] == 'Q652') and {} or langs
for i, lang in ipairs(langs) do
langs[i] = mWikidata._getLabel({ lang })
end
websites[idx] = {
url = mWikidata._formatStatement(claim),
langs = langs
}
end
return websites
end
-- Funzione per i template {{Sito ufficiale}} e {{Blog ufficiale}}
function p.main(frame)
local websites = getWebsites(frame)
for idx, website in ipairs(websites) do
-- P856 e P1581 sono di tipo "valore singolo", aggiunge l'elenco puntato solo per le eccezioni
websites[idx] = (idx > 1 and '*' or '') .. formatWebsite(website)
end
return #websites > 0 and table.concat(websites, '\n') or ''
end
return p