Difference between revisions 24028344 and 24028346 on svwiki

p = {}
 
function p.huvudkategori(frame)
    local text = ''
    local table entity = mw.wikibase.getEntity()
    if entity then
        if entity.claims.p910 then
            local i = 0
            while entity.claims.p910[i] do
                if entity.claims.p910[i].mainsnak.snaktype == 'value' then
                    local id = entity.claims.p910[i].mainsnak.datavalue.value['numeric-id']
                    local sort = entity.claims.p910[i].mainsnak.datavalue.value['entity-type']
                    if sort == 'item' then 
                        id = 'q' .. id
                    elseif sort == 'property' then
                        id = 'p' .. id
                    else
                        return ''
                    end
                    local u = mw.wikibase.sitelink( id )
                    if string.sub(u, 1, 9) == 'Kategori:' then
                        text = text .. id-- '[[:' .. u .. ']]'
                    end
                end
                i = i + 1
            end
        end
    end
    return text
end
 
return p