Modulo:Wikidata: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
implemento parametro "outputtype" (funzionalità proposta in Discussioni template:Wikidata#Solo etichette/titoli)
m inverto logica del parametro per retrocompatibilità
 
(6 versioni intermedie di uno stesso utente non sono mostrate)
Riga 37:
['unknown-datavalue-type'] = 'Tipo di dato sconosciuto',
['unknown-entity-type'] = 'Tipo di entità sconosciuta',
['unknown-output-typeformat'] = 'TipoFormato di output sconosciuto'
},
somevalue = "''valore sconosciuto''",
Riga 271:
local entityId = getEntityIdFromValue(datavalue.value)
if args.showprop then
ret = p._getProperty({ args.showprop, n = 1, from = entityId, formatting = args.formatting }) or ''
elseif args.formatting then
local formatting = args.formatting:lower()
ret = (formatting == 'raw' or formatting == 'id') and entityId or
outputtypeformatting == 'label' and mw.wikibase.getLabel(entityId) or
outputtypeformatting == 'title' and (mw.wikibase.getSitelink(entityId) or '') or
error(i18n.errors['unknown-output-typeformat'])
else
ret = args.formatting == 'raw' and entityId or formatEntityId(entityId)
end
elseif datavalue.type == 'string' then
Riga 382 ⟶ 388:
 
local function formatStatements(claims, args, rawTable)
local outputtype = args.outputtype and args.outputtype:lower() or 'link'
local formattedStatements = {}
 
for _, claim in ipairs(claims) do
local formattedStatement = formatStatement(claim, args)
if outputtype ~= 'link' and claim.mainsnak.snaktype == 'value' and claim.mainsnak.datatype == 'wikibase-item' then
local entityId = getEntityIdFromValue(claim.mainsnak.datavalue.value)
formattedStatement =
outputtype == 'id' and entityId or
outputtype == 'label' and mw.wikibase.getLabel(entityId) or
outputtype == 'title' and mw.wikibase.getSitelink(entityId) or
error(i18n.errors['unknown-output-type'])
else
formattedStatement = formatStatement(claim, args)
end
if formattedStatement ~= '' then
-- eventuale pattern
Riga 783 ⟶ 778:
 
-- Restituisce l'ID dell'item Wikidata collegato alla pagina corrente o a una pagina specificata
-- (nota: se il parametro followRedirects è valorizzato con "no", segue i redirect fermandosi al primo redirect collegato a un elemento)
function p._getId(args)
local ret
local followRedirects = not args.followRedirects or args.followRedirects ~= "no"
if args[1] then
local title = mw.title.new(args[1])
Riga 794 ⟶ 790:
break
else
title = followRedirects and title.redirectTarget or nil
end
end
Riga 886 ⟶ 882:
-- Funzione per il template {{WikidataClasse}}
function p.propertyHasEntity(frame)
local args = getArgs(frame, { parentOnly = true })
local propertyId = args[1]
args.recursion = tonumber(args.prof) or 8
return select(2, xpcall(function()
return p._propertyHasEntity(propertyId, args) and 1 or ''