Module:Person
From ArchivesWiki
Documentation for this module may be created at Module:Person/doc
local PROP_WIKITREE = 'P2949'
local PROP_FAMILYSEARCH = 'P2889'
local PROP_WABI = 'P13035'
local p = {}
p.wikipedia = function ( frame )
if frame.args.wikidata == nil or frame.args.wikidata == '' then
return ''
end
local item = mw.ext.UnlinkedWikibase.getEntity( frame.args.wikidata )
if item ~= nil and item.sitelinks ~= nil and item.sitelinks.enwiki ~= nil then
return item.sitelinks.enwiki.title
end
return ''
end
-- --
-- Get a wikitree ID, optionally linked.
-- e.g.: =p.wikitree({args={wikidata='Q21664073'}})
--
p.wikitree = function ( frame )
-- Find the ID from provided value or Wikidata.
local wikitreeId = nil
if frame.args.wikitree ~= nil and frame.args.wikitree ~= '' then
wikitreeId = frame.args.wikitree
elseif frame.args.wikidata then
local item = mw.ext.UnlinkedWikibase.getEntity( frame.args.wikidata )
if item and item.claims ~= nil and item.claims[PROP_WIKITREE] ~= nil then
wikitreeId = item.claims[PROP_WIKITREE][1].mainsnak.datavalue.value
end
end
-- Return the required formatted output.
if wikitreeId == nil then
return ''
elseif frame.args.format ~= nil and frame.args.format == 'link' then
return '<br />Wikitree: [https://www.wikitree.com/wiki/' .. wikitreeId .. ' ' .. wikitreeId .. ']'
else
return wikitreeId
end
end
p.familysearch = function ( frame )
return getProp( frame, 'familysearch', PROP_FAMILYSEARCH )
end
p.wabi = function ( frame )
return getProp( frame, 'wabi', PROP_WABI )
end
function getProp ( frame, argname, propId )
local propVal = nil
if frame.args[ argname ] ~= nil and frame.args[ argname ] ~= '' then
propVal = frame.args[ argname ]
elseif frame.args.wikidata then
local item = mw.ext.UnlinkedWikibase.getEntity( frame.args.wikidata )
if item and item.claims ~= nil and item.claims[ propId ] ~= nil then
propVal = item.claims[ propId ][ 1 ].mainsnak.datavalue.value
end
end
-- Return the required formatted output.
if propVal == nil then
return ''
elseif frame.args.format ~= nil and frame.args.format == 'link' then
if argname == 'wikitree' then
return '<br />WikiTree: [https://www.wikitree.com/wiki/' .. propVal .. ' ' .. propVal .. ']'
elseif argname == 'wabi' then
return '<br /><abbr title="Western Australian Biographical Index">WABI</abbr>: [https://slwa.wa.gov.au/data/wabi/' .. propVal .. '.jpg ' .. propVal .. ']'
elseif argname == 'familysearch' then
return '<br />FamilySearch: [https://www.familysearch.org/tree/person/details/' .. propVal .. ' ' .. propVal .. ']'
end
else
return propVal
end
end
return p