Dokumentacijo za ta modul lahko ustvarite na strani Modul:Wikidata/Places/dok.

local categorizeByPlaceOfBirthAndDeath = true;

local p = {}

--Property:P19, Property:P20
function p.formatPlaceWithQualifiers( context, options, statement )
	local entriesToLookupCategory = {};

	local circumstances = context.getSourcingCircumstances( statement );
	local result = context.formatSnak( options, statement.mainsnak, circumstances );
	insertFromSnak( statement.mainsnak, entriesToLookupCategory )

	if ( statement.qualifiers ) then
		--parent divisions
		if ( statement.qualifiers.P131 ) then
			for i, qualifier in ipairs( statement.qualifiers.P131 ) do
				result = result .. ', ' .. context.formatSnak( options, qualifier );
				insertFromSnak( qualifier, entriesToLookupCategory )
			end
		end

		--country
		if ( statement.qualifiers.P17 ) then
			for i, qualifier in ipairs( statement.qualifiers.P17 ) do
				result = result .. ', ' .. context.formatSnak( options, qualifier );
				insertFromSnak( qualifier, entriesToLookupCategory )
			end
		end
	end

	result =  result .. context.formatRefs( options, statement );

	if ( categorizeByPlaceOfBirthAndDeath ) then
		local property = mw.ustring.upper( options.property );
		if ( property == 'P19' ) then
			result = result .. getCategory( 'P1464', entriesToLookupCategory );
		end
		if ( property == 'P20' ) then
			result = result .. getCategory( 'P1465', entriesToLookupCategory );
		end
	end

	return result;
end

-- append entity id from snak to result
function insertFromSnak( snak, result )
	if ( not categorizeByPlaceOfBirthAndDeath ) then
		return;
	end
	if ( snak 
			and snak.datavalue
			and snak.datavalue.type == 'wikibase-entityid'
			and snak.datavalue.value
			and snak.datavalue.value['entity-type'] == 'item' ) then
		table.insert( result, 'Q' .. snak.datavalue.value['numeric-id'] );
	end
end

function getCategory( propertyToSearch, entriesToLookupCategoryFor )
	local data = mw.loadData( 'Module:Wikidata:Dictionary/' .. propertyToSearch );
	for _, placeId in ipairs( entriesToLookupCategoryFor ) do
		if ( data[ placeId ] ) then
			return '[[w:' .. data[ placeId ][1] .. '|' .. data[ placeId ][1] .. ']]';
		end
	end
	return '';
end

return p;