Module:Person

local PROP_WIKITREE = 'P2949' local PROP_FAMILYSEARCH = 'P2889' local p = {}

-- -- -- 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 ' Wikitree: [https://www.wikitree.com/wiki/' .. wikitreeId .. ' ' .. wikitreeId .. ']'	else return wikitreeId end end

p.familysearch = function ( frame ) return getProp( frame, 'familysearch', PROP_FAMILYSEARCH ) 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 ' Wikitree: [https://www.wikitree.com/wiki/' .. propVal .. ' ' .. propVal .. ']'		elseif argname == 'familysearch' then return ' FamilySearch: [https://www.familysearch.org/tree/person/details/' .. propVal .. ' ' .. propVal .. ']'		end else return propVal end end

return p