Module:Authors: Difference between revisions
Appearance
Created page with "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..." Tag: Recreated |
No edit summary |
||
| Line 16: | Line 16: | ||
local itemId = value.value.id | local itemId = value.value.id | ||
local label = mw.wikibase.getLabel(itemId) or itemId | local label = mw.wikibase.getLabel(itemId) or itemId | ||
table.insert(authors, "[[" .. label .. "]]") | local sitelink = mw.wikibase.getSitelink(itemId) | ||
if sitelink then | |||
table.insert(authors, "[[" .. sitelink .. "|" .. label .. "]]") | |||
else | |||
table.insert(authors, label) | |||
end | |||
end | end | ||
end | end | ||
Revision as of 11:41, 17 April 2026
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