Modulo:Cita Wikidata

Questo è un modulo scritto in Lua. Le istruzioni che seguono sono contenute nella sottopagina Modulo:Cita Wikidata/man (modifica · cronologia)
Sandbox: Modulo:Cita Wikidata/sandbox (modifica · cronologia) · Sottopagine: lista · Test: Modulo:Cita Wikidata/test (modifica · cronologia · esegui)
Questo modulo serve come supporto per il Template:Cita tramite Wikidata.
require('Modulo:No globals')
local p = {}
local propertyId = ''
local getArgs = require('Modulo:Arguments').getArgs
local mWikidata = require('Modulo:Wikidata')
local mCitazione = require('Modulo:Citazione')
local function is_set( var )
return not (var == nil or var == '');
end
local function getQualifier(qualifierId, conjunction)
return mWikidata._getQualifier( { propertyId, qualifierId, conjunction=conjunction } )
end
local function getAutori()
local autoriStringa = getQualifier('P2093')
if is_set(autoriStringa) then
local autoriConLink = getQualifier('P50', ", ")
if is_set(autoriConLink) then
return autoriConLink .. ', ' .. autoriStringa
else
return autoriStringa
end
else
return getQualifier('P50')
end
end
local function getTitolo()
local titolo = getQualifier('P1476')
or getQualifier('P1932')
or getQualifier('P1932')
or getQualifier('P742')
or getQualifier('P554')
or mw.title.getCurrentTitle().fullText--TODO: aggiungere pipetrick
return titolo
end
local function getUrl(urlPattern)
return mWikidata._getProperty( { propertyId, pattern=urlPattern } )
end
function p.getCitation(frame)
local args = getArgs(frame)
propertyId = args.prop
local medium = args.medium
local identifier = args.id
local urlType = args.tipourl or 'titolo'
local urlPattern = args.patternurl
-- Se un identificatore è specificato, allora si sta forzando l'inserimento manuale;
-- in tal caso, nessun dato va ricavato da Wikidata, altrimenti si rischierebbero incongruenze fra i dati manuali e quelli automatici
if not is_set(identifier) then
if not is_set(args.autore) then
args.autore = getAutori()
end
if urlType == 'titolo' then
if not is_set(args.titolo) then
args.titolo = getTitolo()
end
if not is_set(args.url) then
args.url = getUrl(urlPattern)
end
elseif urlType == 'capitolo' then
if not is_set(args.capitolo) then
args.capitolo = getTitolo()
end
if not is_set(args.urlcapitolo) then
args.urlcapitolo = getUrl(urlPattern)
end
end
if not is_set(args.data) and not is_set(args.anno) then
args.data = getQualifier('P577')
end
if not is_set(args.vol) and not is_set(args.volume) then
args.data = getQualifier('P478')
end
end
args.medium = nil
args.prop = nil
args.id = nil
return mCitazione.cita_da_modulo(medium, args)
end
return p