Модуль:Песочница/Lockal/где

Материал из Википедии — свободной энциклопедии
Перейти к навигации Перейти к поиску
Документация
local p = {}

local ListOfCountries = mw.loadData( 'Модуль:Wikidata:Dictionary/P1464');

local function MakeWherePlaces(places)
	local res = ''
	for i, place in pairs(places) do
		if i > 1 then
			if next(places, _) == nil then
			    res = res .. ' и ';
			else
			    res = res .. ', ';
			end
		end
		
		if place.mainsnak.datavalue then -- если значение свойства "значение неизвестно", то datavalue nil
			local id = 'Q' .. place.mainsnak.datavalue.value['numeric-id']
			
			if ListOfCountries[id] then
				local sitelink = mw.wikibase.sitelink(id)
				local prep, linktext = string.match(ListOfCountries[id][1], '^Категория:Родившиеся ([^ ]+) (.+)$');
				
				if sitelink then
					res = res .. prep .. ' ' .. "[[" .. sitelink .. "|" .. linktext .. "]]";
				else
					res = res .. prep .. ' ' .. linktext;
				end
			end
		end
	end
    return res
end

function p.mainFunction(frame)
	local args = {}
	if frame == mw.getCurrentFrame() then
		args = frame.args;
	else
		args = frame
	end
		
	local result = ''
	local entity = mw.wikibase.getEntity()
	
	if entity ~= nil and entity.claims ~= nil then
		countries = entity.claims[ args[1] ]
		if countries ~= nil then
			result = result .. MakeWherePlaces(countries)
		end
	end
	return result
end
 
return p