Jump to content

Module:Authors

From wikibase
Revision as of 11:41, 17 April 2026 by Design (talk | contribs)

Documentation for this module may be created at Module:Authors/doc

local p = {}

function p.list(frame)
    local entity = mw.wikibase.getEntity()
    if not entity then
        return "No Wikibase entity found for this page."
    end
    
    local claims = entity.claims or {}
    local p2Claims = claims.P2 or {}
    
    local authors = {}
    for _, claim in ipairs(p2Claims) do
        local value = claim.mainsnak.datavalue
        if value and value.type == "wikibase-entityid" then
            local itemId = value.value.id
            local label = mw.wikibase.getLabel(itemId) or itemId
            local sitelink = mw.wikibase.getSitelink(itemId)
            if sitelink then
                table.insert(authors, "[[" .. sitelink .. "|" .. label .. "]]")
            else
                table.insert(authors, label)
            end
        end
    end
    
    if #authors == 0 then
        return "No authors found."
    end
    
    return table.concat(authors, ", ")
end

return p