Modulo:Wikidata/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
prova per getdescriptionj, copiato da https://www.wikidata.org/w/index.php?title=Module:Wikidata&oldid=992712360
Nessun oggetto della modifica
 
(12 versioni intermedie di 3 utenti non mostrate)
Riga 1:
--[[
* Modulo per implementare le funzionalità dei template:
* {{Wikidata}}, {{WikidataQ}}, {{WikidataIdx}}, {{WikidataN}}, {{WikidataLabel}}, {{WikidataDescription}}
* {{WikidataLink}}, {{WikidataId}}, {{WikidataTipo}} e {{WikidataIstanza}}.
* Permette di accedere a Wikidata in modo più avanzato rispetto a {{#property}}.
Riga 16:
-- =============================================================================
 
require('Module:No globalsstrict')
 
local getArgs = require('Module:Arguments').getArgs
local mConvert = require('Module:Conversione')
local mLanguages = require('Module:LinguaggiLingue')
local mCitation = require('Module:Citazione')
 
-- Categoria per le pagine con errori
Line 176 ⟶ 177:
end
 
local function formatFromPattern(str, args, refs)
local pattern = args.pattern
pattern = mw.ustring.gsub(pattern, '\\{', '{')
pattern = mw.ustring.gsub(pattern, '\\}', '}')
return mw.getCurrentFrame():preprocess(mw.message.newRawMessage(pattern, str, refs or ''):plain())
end
 
Line 364 ⟶ 365:
end
return text
end
 
local function formatReferences(references, args)
local formattedReferences = {}
local refArgs = {}
local parameters = {
titolo = 'P1476', data = 'P577', url = 'P854', dataaccesso = 'P813',
editore = 'P123', urlarchivio = 'P1065', dataarchivio = 'P2960'
}
if references[1].snaks.P854 then
local snaks = references[1].snaks
for parameter, property in pairs(parameters) do
if snaks[property] then
refArgs[parameter] = formatSnak(snaks[property][1], args)
end
end
refArgs.titolo = refArgs.titolo or refArgs.url
if snaks.P407 then
local langs = {}
for _, value in ipairs(snaks.P407) do
local lang = formatSnak(value, { formatting = 'raw' })
table.insert(langs, mw.wikibase.getLabel(lang) or lang)
end
refArgs.lingua = table.concat(langs, ',')
end
if refArgs.urlarchivio then refArgs.urlmorto = 'sì' end
local formattedReference = mw.getCurrentFrame():extensionTag{
name = 'ref',
content = mCitation.cita_da_modulo('web', refArgs),
args = { name = references[1].hash }
}
table.insert(formattedReferences, formattedReference)
end
return table.concat(formattedReferences)
end
 
Line 386 ⟶ 421:
local formattedStatement = formatStatement(claim, args)
if formattedStatement ~= '' then
local formattedReferences
if args.showreferences and claim.references then
formattedReferences = formatReferences(claim.references, args)
end
-- eventuale pattern
if args.pattern then
formattedStatement = formatFromPattern(formattedStatement, args, formattedReferences)
ifelseif formattedStatement ~= ''formattedReferences then
table.insert(formattedStatements,formattedStatement = formattedStatement) .. formattedReferences
end
if formattedStatement ~= '' then
else
table.insert(formattedStatements, formattedStatement)
end
Line 410 ⟶ 449:
-------------------------------------------------------------------------------
 
-- Restituisce true se lo statement contiene il qualifier richiesto con un dato valore (o uno tra più valori separati da virgola)
local function hasQualifierValue(statement, qualifierId, qualifierValue)
local ret = false
Line 416 ⟶ 455:
local isItem = qualifier.snaktype == 'value' and
qualifier.datavalue.type == 'wikibase-entityid'
local qualifierValues = mw.text.split(qualifierValue, ',')
-- per le proprietà di tipo item il confronto è eseguito sull'id
for _, qualifierHas in ipairs(qualifierValues) do
if formatSnak(qualifier, isItem and { formatting = 'raw' } or {}) == qualifierValue then
-- per le proprietà di tipo item il confronto è eseguito sull'id
ret = true
if formatSnak(qualifier, isItem and { formatting = 'raw' } or {}) == qualifierHas then
break
ret = true
break
end
end
end
Line 724 ⟶ 766:
ret = mw.wikibase.getLabel(entityId)
end
return ret
end
 
-- Restituisce la descrizione di un item o di una proprietà Wikidata.
function p._getDescription(args)
local entityId = args[1] and string.upper(args[1])
local ret = mw.wikibase.getDescription(entityId)
return ret
end
Line 820 ⟶ 869:
end
 
-- Funzione per il template {{WikidataDescription}}
function p._getDescription(entity, lang, fallback)
function p.getDescription(frame)
if not entity then
return i18nselect('Nessuna2, descrizione'xpcall(function()
return p._getDescription(getArgs(frame, { parentOnly = true }))
end
end, errhandler))
if not lang then
lang = "it"
end
if type(entity) ~= 'table' and lang == defaultlang then
local description, lg = mw.wikibase.getDescriptionWithLang(entity)
if description and (fallback ~= '-' or lg == lang) then
return description
end
else
entity = p.getEntity(entity)
if entity and entity.descriptions then
if fallback ~= '-' then
for _, lg in ipairs(fb.fblist(lang, true)) do
if entity.descriptions[lg] then
return entity.descriptions[lg].value
end
end
else
if entity.descriptions[lang] then
return entity.descriptions[lang].value
end
end
end
end
return i18n('Nessuna descrizione')
end
 
Line 882 ⟶ 907:
function p.checkProperty(frame)
return select(2, xpcall(function()
return p._N(getArgs(frame, { parentOnly = true })) > 0 and 10 or ''
end, errhandler))
end
 
-- 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 ''
end, errhandler))
end