Modulo:Wikidata: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
m aggiunto parametro "entity" |
rimossa mw.wikibase.getEntity per l'utilizzo di mw.wikibase.getBestStatements e mw.wikibase.getAllStatements |
||
Riga 8:
* http://test2.wikipedia.org/w/index.php?title=Module:Wikidata&oldid=52322
]]
-- =============================================================================
-- Non utilizzare mai mw.wikibase.getEntity, per esempio un solo utilizzo di:
-- fa aumentare di 7 MB l'utilizzo di memoria per Lua ed è estremamente lenta se ripetuta.
-- Gli unici due utilizzi nel modulo sono in getLabel quando si deve specificare
-- una lingua diversa dall'italiano e in getDatatype, non essendoci alternative;
-- entrambe le funzioni non sono comunque mai usate nelle voci.
-- =============================================================================
require('Module:No globals')
Riga 414 ⟶ 423:
-- "rank", "qualifier", "qualifiertype" e "n"
local function getClaims(property, args)
local
entityId = args.from or mw.wikibase.getEntityIdForCurrentPage()
▲ entity = args.entity or mw.wikibase.getEntity(args.from)
▲ if not entity then
return nil
end
-- il default rank è 'best'
else▼
return nil▼
end▼
-- statements filtrati per rank (default 'best')▼
args.rank = args.rank or 'best'
if args.rank == 'best' then
claims = mw.wikibase.getBestStatements(entityId, property)
filteredClaims = filterRankValue(claims, 'preferred')▼
else
claims = mw.wikibase.getAllStatements(entityId, property)
end
-- statements filtrati per qualifier
Riga 655 ⟶ 654:
-- Restituisce l'etichetta di un item o di una proprietà Wikidata.
function p._getLabel(args)
local
local ret
return entity and entity:getLabel(args[2])▼
if args[2] then
-- mw.wikibase.label non permette di scegliere la lingua
local entity = mw.wikibase.getEntity(entityId)
▲ else
ret = mw.wikibase.label(entityId)
▲ end
end
Riga 681 ⟶ 688:
end
entity =
if not entity then
error(i18n.errors['entity-not-found'], 2)
|