Modul:Németországi járás települései

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

Németországi járás települései[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">Németországi járás települései: ' .. 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 then
		return ""
	end
	if wd.isOfType(item, 'Q262166') then  -- Gemeinde
		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(s.mainsnak.datavalue.value.id)
				if wd.isOfType(item, "Q106658") then  -- Landkreis
					if statement then
						return formatError"Több érték a járás 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 járás"
			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.isOfType(item, "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 .. " települései",
		['listaosztály'] = "hlist",
		['állapot'] = "expanded",
		['lista1'] = wd.formatStatements(frame, { property = "P150", ["felsorolás"] = "lista", sort = "" }, district)
	} .. renderTrackingCategories()
end

return p