Модуль:Wikidata/positions

З Вікіпедыі, свабоднай энцыклапедыі

Дакументацыю да гэтага модуля можна стварыць у Модуль:Wikidata/positions/Дакументацыя

local p = {}

function p.formatPositionClaim( context, options, statement )
	if (not context) then error('context is not specified') end;
	if (not options) then error('options is not specified') end;
	if (not statement) then error('statement is not specified') end;

	local args = {}
	
	if not statement.qualifiers or not statement.qualifiers['P580'] or not statement.qualifiers['P580'][1] then
		return '' -- няма даты пачатку
	end
	options.substTopicList = 1
	args['пасада_'] = '<span class="ts-wikidata-positions-uppercasefirst">' .. context.formatSnak( options, statement.mainsnak ) .. '</span>'
	if statement.qualifiers and statement.qualifiers['P642'] then -- адносіцца да/of
		local organizations = {}
		for _, v in pairs(statement.qualifiers['P642']) do
			table.insert(organizations, context.formatSnak( options, v ))
		end
		args['пасада_'] = args['пасада_'] .. ' (' .. mw.text.listToText(organizations) .. ')'
	end
	
	local params = {
		['перыядпачатак_'] = 'P580',
		['перыядканец_'] = 'P582',
		['папярэднік_'] = 'P1365',
		['пераемнік_'] = 'P1366',
		['суправіцель1_'] = 'P1706',
		['дыяцэзія_'] = 'P708',
	}
	if statement.qualifiers then
		for k, v in pairs(params) do
			if statement.qualifiers[v] then
				args[k] = context.formatSnak( options, statement.qualifiers[v][1] )
			end
		end
	end
	
	local plainparams = {
		['парадак_'] = 'P1545',
	}
	if statement.qualifiers then
		for k, v in pairs(plainparams) do
			if statement.qualifiers[v] and statement.qualifiers[v][1] and statement.qualifiers[v][1].datavalue then
				args[k] = statement.qualifiers[v][1].datavalue.value
			end
		end
	end
	
	local res = options.frame:extensionTag( 'templatestyles', '', { src = 'Шаблон:Wikidata/positions/styles.css' } );
	res = res .. options.frame:expandTemplate{ title = 'Дзяржаўны дзеяч/Пасада', args = args }; 
	return res
end

return p