Modul:EntityList
Moduldokumentasjon
[opprett]
local lib = {}
function lib:parts( entityId, property )
local parts = {}
local statements = {}
if entityId then
statements = mw.wikibase.getBestStatements( entityId, property )
end
for i,claim in ipairs( statements ) do
local mainsnak = claim.mainsnak
if mainsnak.snaktype == 'value' and mainsnak.datatype == 'wikibase-item' then
local datavalue = mainsnak.datavalue
if datavalue.type == 'wikibase-entityid' then
local value = datavalue.value
if value['entity-type'] == 'item' then
local id = value.id
local entity = mw.wikibase.getEntity( id )
local label = entity:getLabel() or '?' -- fallback could fail
if not entity.labels then -- might be empty
entity.labels = {}
end
entity.labels['_'] = { ["language"] = "_", ["value"] = label } -- keep this for sorting purposes
table.insert( parts, entity )
end
end
end
end
return parts
end
setmetatable( lib, {
__call = function( self, property )
local entityId = mw.wikibase.getEntityIdForCurrentPage()
local parts = self:parts( entityId, property )
table.sort( parts, function( a, b ) return mw.ustring.upper( a.labels['_'] ) < mw.ustring.upper( b.labels['_'] ) end)
return parts
end })
return lib