Module:WikiProject Genealogy

Lua
CodeDiscussionLinksLink count SubpagesDocumentationTestsResultsSandboxLive code All modules

Documentation for this module may be created at Module:WikiProject Genealogy/doc

Code

local p = {}

function p.numdescendants(frame)
	local person=frame:getParent().args[1]
	local content=mw.title.makeTitle( 4, 'WikiProject Genealogy/numbers/descendants/' .. person ):getContent()
	redir_title = content and require('Module:Redirect').getTargetFromText(content)
	if redir_title then
		content=mw.title.makeTitle( 0, redir_title ):getContent()
	end
	if content then
		if  mw.ustring.find(content, "| descendants = ", 1, true) then
			content=mw.ustring.sub( content,mw.ustring.find(content, "| descendants = ", 1, true)+15)
			return mw.ustring.sub( content,1,mw.ustring.find(content, "}}", 1, true)-1)
		else
			return 'fail to parse [[Wikidata:WikiProject Genealogy/numbers/descendants/' .. person .. ']]'
		end
	else
		if frame:getParent().args[2] == "-" then
			return '-'
		else
			return 'create [[Wikidata:WikiProject Genealogy/numbers/descendants/' .. person .. ']]'
		end
	end
end

function p.notable_list(frame)
	local getLabel=require('Module:Wikidata label')._getLabel
	local formatStatementsE=require('Module:Wikidata').formatStatementsE
	local props={}
	local coverage={}
	local people=frame.args
	for v in string.gmatch(mw.title.makeTitle( 4, 'WikiProject Genealogy' ):getContent(),"{{TR genea prop|(%d+)}}") do
		table.insert(props,v)
	end
	local content=''
	local ct=0
	local contentline = ""
	for l, j in ipairs( people ) do
		for k, i in ipairs( props ) do
			local statement = formatStatementsE({item=j, property='P' .. i})
			if statement then
				coverage[i]=(coverage[i] or 0)+1
			end
		end
	end	
	for l, j in ipairs( people ) do
		content=content .. '<tr><td>' .. getLabel(j, nil, 'wikidata') .. '</td>'
		content=content .. '<td align="right">' .. (formatStatementsE({item=j, property='P569'}) or '').. '</td>'
		content=content .. '<td align="right">' .. (formatStatementsE({item=j, property='P570'}) or '') .. '</td>'
		ct=0
		contentline = ""
		for k, i in ipairs( props ) do
			if (coverage[i] or 0) ~= 0 then
				local statement = formatStatementsE({item=j, property='P' .. i})
				contentline = contentline .. '<td style="font-size:smaller">' .. (statement or '') .. '</td>'
				if statement then
					ct = ct + 1
				end
			end
		end
		content=content .. '<td align="right">' .. ct .. '</td>' .. contentline
		content=content .. '</tr>'
	end
	content=content .. '</table>'
	local empty = ""
	local content1='<table style="white-space:nowrap" class="wikitable sortable"><tr><th>&nbsp;</th><th>born</th><th>died</th><th>count<br>&nbsp;</th>'
	for k, i in ipairs( props ) do
		if (coverage[i] or 0) ~= 0 then
			content1=content1 .. '<th style="font-size:smaller">' .. getLabel('P' .. i) .. '<br>(' .. (coverage[i] or 0) .. ')</th>'
		else
			empty = empty .. "\n*" .. getLabel('P' .. i)
		end
	end
	content1=content1 .. '</tr>'
	return content1 .. content .. "\n" .. getLabel('Q22910791') ..  empty
end
 
return p