Modul:Amerikai állam megyéi

A Wikipédiából, a szabad enciklopédiából

Amerikai állam megyéi[mi ez?] • [dokumentáció: mutat, szerkeszt] • [tesztek: létrehozás]

require('strict')
local wd = require"Modul:Wikidata"

local p = {}

local cats = {}

local function renderTrackingCategories()
	local result = {}
	for _, cat in ipairs(cats) do
		table.insert(result, "[[Kategória:" .. cat .. "]]")
	end
	return table.concat(result)
end

local function formatError(msg)
	return '<strong class="error">Amerikai állam megyéi: ' .. msg .. '</strong>' .. 
		'[[Kategória:Figyelmet igénylő Wikidata-adatok]]'
end

function p.main(frame)
	local district, title
	local item = mw.wikibase.getEntity()
	if not item or not item.claims then
		return ""
	end
	if wd.containsPropertyWithValue(item, "P31", "47168") or true then  -- megye
		local municipality = item
		if not municipality.claims.P131 then
			return ""
		end
		local statement
		for _, s in ipairs(municipality:getBestStatements"P131") do
			if s.mainsnak.snaktype == "value" then
				local item = mw.wikibase.getEntity("Q" .. s.mainsnak.datavalue.value["numeric-id"])
				if wd.containsPropertyWithValue(item, "P31", "Q35657") then  -- Landkreis
					if statement then
						return formatError"Több érték a megye megállapításakor"
					end
					statement = s
					district = item
				end
			end
		end
		if not statement then
			return ""
		end
		title = wd.formatStatement(statement)
		if not title then
			title = district:getLabel"de"
			if not title then
				title = "A megye"
			else
				if mw.ustring.sub(title, 1, 10) == "Landkreis " then
					title = mw.ustring.sub(title, 11)
				end
				if mw.ustring.sub(title, -6) == "-Kreis" then
					title = mw.ustring.sub(title, 1, -7)
				end
				title = title .. " járás"
			end
		end
	elseif wd.containsPropertyWithValue(item, "P31", "Q106658") then  -- Landkreis
		district = item
		title = district:getLabel()
		if not title then
			title = district:getSitelink()
		end
	else
		return ""
	end
	if not district.claims.P150 then
		return ""
	end
	return require"Modul:Navbox"._navbox{
		['navbar'] = "plain",
		['cím'] = title .. " megyéi",
		['listaosztály'] = "hlist",
		['lista1'] = wd.formatStatements(frame, {property = "P150", ["felsorolás"] = "lista", sort = ""}, district)
	} .. renderTrackingCategories()
end

return p