Modulo:Wikidata/sandbox: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
m uso funzione già esistente |
prova per getdescriptionj, copiato da https://www.wikidata.org/w/index.php?title=Module:Wikidata&oldid=992712360 |
||
Riga 79:
if success and uri.protocol and protocols[uri.protocol] then
local dest = tostring(uri)
return string.format('<
else
return url
Riga 89:
local siteLink = mw.wikibase.getSitelink(entityId)
local ret
if entityId == mw.wikibase.getEntityIdForCurrentPage() then
if siteLink and label then▼
ret = siteLink
ret = mw.getContentLanguage():ucfirst(label) == siteLink and
string.format('[[%s]]', label) or
Line 322 ⟶ 324:
qualifiers = (n and n <= #qualifiers) and { qualifiers[n] } or {}
end
--
args.snaktype = args.snaktype or 'value'
for _, qualifier in ipairs(qualifiers) do
Line 663 ⟶ 665:
if statement == entityId then
return true
end
end
end
-- Se non è stato trovato alcun valore, controlla se questo sia ereditato
-- tramite la proprietà "sottoclasse di" (P279) scavando in profondità
-- fino all'esaurirsi del numero specificato in args.recursion.
--[[ TODO: Valutare se sia opportuna una ricerca ricorsiva potenzialmente infinita.
Per farlo si può aggiungere un parametro (opzionale) maxDepth
che svolga l'attuale funzione di recursion e cambiare quest'ultimo
in un parametro booleano.
]]
args.recursion = tonumber(args.recursion) or 0
if args.recursion > 0 then
local recursion = args.recursion
if type(args.loadedEntities) ~= 'table' then
args.loadedEntities = setmetatable({}, {
__newindex = function(t, k, v)
rawset(t, k, v)
rawset(t, #t+1, k)
end })
args.loadedEntities[args.from or mw.wikibase.getEntityIdForCurrentPage()] = true
end
for _, statement in ipairs(statements) do
if not args.loadedEntities[statement] then
args.loadedEntities[statement] = true
args.recursion = args.recursion - 1
args.from = statement
if p._propertyHasEntity('P279', args) then
return true, args.loadedEntities
end
args.recursion = recursion
end
end
Line 668 ⟶ 702:
end
return false, args.loadedEntities
end
Line 784 ⟶ 818:
return p._getLabel(getArgs(frame, { parentOnly = true }))
end, errhandler))
end
function p._getDescription(entity, lang, fallback)
if not entity then
return i18n('Nessuna descrizione')
end
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
|