Modul:Osztrák tartomány járásai
Osztrák tartomány járásai[mi ez?] • [dokumentáció: mutat, ] • [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">Osztrák tartomány járásai: ' .. msg .. '</strong>' ..
'[[Kategória:Figyelmet igénylő Wikidata-adatok]]'
end
local function templateLabel(label)
label = label:gsub("^Bezirk ", "")
label = mw.ustring.gsub(label, "i járás$", "")
label = label:gsub("%-$", "")
label = label:gsub("^[Aa]z? ", "")
return label
end
local function comp(s1, s2)
if s1.mainsnak.snaktype ~= "value" or s2.mainsnak.snaktype ~= "value" then
return nil
end
local sortKey
local type = s1.mainsnak.datavalue.type
if type == "wikibase-entityid" then
sortKey = function (statement)
local id = "Q" .. statement.mainsnak.datavalue.value["numeric-id"]
local key = mw.wikibase.label(id)
if not key then
key = mw.wikibase.sitelink(id)
end
if not key then
return id
end
return mw.language.getContentLanguage():caseFold(templateLabel(key))
end
end
return sortKey(s1) < sortKey(s2)
end
function p.main(frame)
local state, title
local item = mw.wikibase.getEntity()
if not item then
return nil
end
if wd.containsPropertyWithValue(item, "P31", "Q871419") then -- Bezirk
local municipality = item
if not municipality.claims.P131 then
return nil
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", "Q261543") then -- Bundesland
if statement then
return formatError"Több érték a tartomány megállapításakor"
end
statement = s
state = item
end
end
end
if not statement then
return nil
end
title = wd.formatStatement(statement)
if not title then
title = state:getLabel"de"
if not title then
title = "A tartomány"
end
end
elseif wd.containsPropertyWithValue(item, "P31", "Q261543") then -- Bundesland
state = item
title = state:getLabel()
if not title then
title = state:getSitelink()
end
else
return nil
end
if not state.claims.P150 then
return nil
end
local flagImage = state:getBestStatements"P41"[1].mainsnak.datavalue.value
local coaImage = state:getBestStatements"P94"[1].mainsnak.datavalue.value
return require"Modul:Navbox"._navbox{
['navbar'] = "plain",
['cím'] = "[[Fájl:" .. flagImage .. "|25px|keret]] " .. title ..
" járásai ''(Bezirk)'' és önálló tartományi városai ''(Statutarstadt)''",
['listaosztály'] = "hlist",
['kép'] = "[[Fájl:" .. coaImage .. "|50px|" .. title .. " címere]]",
['lista1'] = wd.formatStatements(frame, {
property = "P150",
["felsorolás"] = "lista",
sort = comp,
["value-module"] = "Osztrák tartomány járásai",
["value-function"] = "formatItemId"
}, state),
['lista2stílus'] = "text-align:right"
} .. renderTrackingCategories()
end
local function predictLink(templateLabel)
if templateLabel:find" " then
templateLabel = templateLabel .. "-"
end
return templateLabel .. "i járás"
end
function p.formatItemId(value)
local itemId = "Q" .. value["numeric-id"]
local label = mw.wikibase.label(itemId)
local link = mw.wikibase.sitelink(itemId)
if not label and not link then
return nil
end
label = label or link
link = link or mw.ustring.match(label, "járás$") and label
label = templateLabel(label)
link = link or predictLink(label)
return "[[" .. link .. "|" .. label .. "]]"
end
return p