Module:NBD
Jump to navigation
Jump to search
local p = {}
function p.NBD(frame)
local pframe = frame:getParent()
local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template
local entity = mw.wikibase.getEntityObject()
if not entity then -- no Wikidata item
return "[[Category:NBD not in Wikidata]]"
end
local property = "P31"
local value = 19389637
local claims = entity.claims or {}
local hasProp = claims[property]
if not hasProp then -- no claim of that property
return "[[Category:NBD item without P31]]"
end
if (hasProp and hasProp[1] and hasProp[1].mainsnak.snaktype == "value" and hasProp[1].mainsnak.datavalue.type == "wikibase-entityid" and hasProp[1].mainsnak.datavalue.value["numeric-id"] and hasProp[1].mainsnak.datavalue.value["numeric-id"] == value) then
result = "[[Category:NBD articles]]"
local property = "P921"
hasProp = claims[property]
if not hasProp then
return "[[Category:NBD articles]] [[Category:NBD articles without P921]]"
else
local qid2 = "Q" .. hasProp[1].mainsnak.datavalue.value["numeric-id"]
local entity2 = mw.wikibase.getEntityObject( qid2 )
local claims2 = entity2.claims or {}
local result = '<div style="float:right">[[d:' .. qid2 .. "|" .. entity2:getLabel( 'en' ) .. ']] <br>('
if claims2["P569"] then result = result .. entity2:formatPropertyValues( 'P569' ).value end
result = result .. "-"
if claims2["P570"] then result = result .. entity2:formatPropertyValues( 'P570' ).value end
result = result .. ")<br>"
if claims2["P27"] then result = result .. entity2:formatPropertyValues( 'P27' ).value .. '<br>' end
if claims2["P410"] then result = result .. "Rank: " .. entity2:formatPropertyValues( 'P410' ).value .. '<br>' end
result = result .. "</div>"
-- return result .. "[[Category:NBD articles]] [[Category:NBD articles with P921]]"
return "[[Category:NBD articles]] [[Category:NBD articles with P921]]"
end
else
return "[[Category:NBD non-article pages]]"
end
end
return p
-- Test pages
-- A Naval Biographical Dictionary/Yule, Charles Bampfield
-- A Naval Biographical Dictionary/Black, William