Module:AuthorsDisplay
Appearance
Documentation for this module may be created at Module:AuthorsDisplay/doc
local p = {}
function p.main(frame)
local item = frame.args.item or "Q14"
local entity = mw.wikibase.getEntity(item)
-- Check if entity exists and has P2 claims
if not entity or not entity.claims or not entity.claims.P2 then
return "<i>No authors found.</i>"
end
local authors = entity.claims.P2
local output = '{| class="wikitable" style="border-collapse: collapse;"\n'
output = output .. '|-\n! Author !! Country\n'
-- Loop through each P2 claim
for _, claim in ipairs(authors) do
-- Verify it's an item (wikibase-item datatype)
if claim.mainsnak.datatype == "wikibase-item" and claim.mainsnak.snaktype == "value" then
local authorId = claim.mainsnak.datavalue.value.id
local authorEntity = mw.wikibase.getEntity(authorId)
if authorEntity then
-- Get the author's label (defaults to item ID if no label)
local authorLabel = authorEntity:getLabel() or authorId
-- Initialize country as "Unknown"
local country = "Unknown"
-- Try to get P14 (country) from the author item
if authorEntity.claims and authorEntity.claims.P14 then
local countryClaim = authorEntity.claims.P14[1]
if countryClaim and countryClaim.mainsnak.datatype == "string" then
country = countryClaim.mainsnak.datavalue.value
end
end
-- Add row to table
output = output .. '|-\n| ' .. authorLabel .. ' || ' .. country .. '\n'
end
end
end
output = output .. '|}\n'
return output
end
return p