Modul:SK: razlika između inačica
Prijeđi na navigaciju
Prijeđi na pretraživanje
mNema sažetka uređivanja |
mNema sažetka uređivanja |
||
| Redak 1: | Redak 1: | ||
-------------------------------------------------------------------- | -------------------------------------------------------------------- | ||
-- SK PRO | -- SK PRO + SK Stats Medium Loader (A3-2) | ||
-- | -- Optimizirano za enciklopedija.cc | ||
-------------------------------------------------------------------- | -------------------------------------------------------------------- | ||
| Redak 9: | Redak 7: | ||
-------------------------------------------------------------------- | -------------------------------------------------------------------- | ||
-- 1) Tematske boje | -- 1) Tematske boje | ||
-------------------------------------------------------------------- | -------------------------------------------------------------------- | ||
| Redak 22: | Redak 20: | ||
-------------------------------------------------------------------- | -------------------------------------------------------------------- | ||
-- 2) Profesionalni infookvir | -- 2) Profesionalni infookvir | ||
-------------------------------------------------------------------- | -------------------------------------------------------------------- | ||
| Redak 47: | Redak 45: | ||
-------------------------------------------------------------------- | -------------------------------------------------------------------- | ||
-- 3) Profesionalni navbox | -- 3) Profesionalni navbox | ||
-------------------------------------------------------------------- | -------------------------------------------------------------------- | ||
| Redak 72: | Redak 70: | ||
-------------------------------------------------------------------- | -------------------------------------------------------------------- | ||
-- 4) | -- 4) Badge | ||
-------------------------------------------------------------------- | -------------------------------------------------------------------- | ||
| Redak 85: | Redak 83: | ||
-------------------------------------------------------------------- | -------------------------------------------------------------------- | ||
-- 5) | -- 5) SK Stats Medium — učitavanje 6 data modula | ||
-------------------------------------------------------------------- | |||
p.db = {} | |||
local modules = { | |||
"Modul:SK/Data1", | |||
"Modul:SK/Data2", | |||
"Modul:SK/Data3", | |||
"Modul:SK/Data4", | |||
"Modul:SK/Data5", | |||
"Modul:SK/Data6", | |||
} | |||
for _, name in ipairs(modules) do | |||
local ok, raw = pcall(require, name) | |||
if ok and type(raw) == "string" then | |||
for line in raw:gmatch("[^\n]+") do | |||
local code, name, pop, male, female, area, elev, postal, year = | |||
line:match("([^|]+)|([^|]+)|([^|]+)|([^|]+)|([^|]+)|([^|]+)|([^|]+)|([^|]+)|([^|]+)") | |||
if code then | |||
pop = tonumber(pop) | |||
male = tonumber(male) | |||
female = tonumber(female) | |||
area = tonumber(area) | |||
elev = tonumber(elev) | |||
year = tonumber(year) | |||
local density = (pop and area) and string.format("%.1f", pop / area) or "?" | |||
p.db[code] = { | |||
naziv = name, | |||
pop = pop, | |||
male = male, | |||
female = female, | |||
area = area, | |||
elev = elev, | |||
postal = postal, | |||
year = year, | |||
density = density, | |||
} | |||
end | |||
end | |||
end | |||
end | |||
-------------------------------------------------------------------- | |||
-- 6) Format funkcije (hrwiki kompatibilno) | |||
-------------------------------------------------------------------- | |||
function p.format(code, mode) | |||
local d = p.db[code] | |||
if not d then return "" end | |||
if mode == "p" then return d.naziv end | |||
if mode == "a" then return d.pop end | |||
if mode == "m" then return d.male end | |||
if mode == "f" then return d.female end | |||
if mode == "d" then return d.area end | |||
if mode == "y" then return d.density end | |||
if mode == "e" then return d.elev end | |||
if mode == "z" then return d.postal end | |||
if mode == "g" then return d.year end | |||
return "" | |||
end | |||
-------------------------------------------------------------------- | |||
-- 7) Glavna funkcija | |||
-------------------------------------------------------------------- | |||
function p.sk(frame) | |||
local args = frame.args | |||
local mode = args[1] | |||
local code = args[2] | |||
if not mode or not code then return "" end | |||
return p.format(code, mode) | |||
end | |||
-------------------------------------------------------------------- | |||
-- 8) Fallback | |||
-------------------------------------------------------------------- | -------------------------------------------------------------------- | ||
Posljednja izmjena od 25. ožujak 2026. u 11:59
Dokumentacija modula
== About ==
Get statistic data about Slovak municipalities.
This template is a sibling of Predložak:SK.
This template use the data from CC-BY database.
Original first author: meta.wikimedia.org/wiki/User:Dušan Kreheľ
Reference implementation is on hrwiki.
Parameters
First paramer
| Meaning | Parameter | Code | Code output |
|---|---|---|---|
| Population | p | {{#invoke:SK|sk|p|SK0417524395}} | |
| Population (source URL) |
P | {{#invoke:SK|sk|P|SK0417524395}}<br>{{#invoke:SK|sk|P|SK}}<br>{{#invoke:SK|sk|P|SK0106}} | |
| Population (ex. for table) |
p | {{#invoke:SK|sk|o|SK0417524395}} | |
| Population Id | r | {{#invoke:SK|sk|r|SK0417524395}} | |
| Area | a | {{#invoke:SK|sk|a|SK0417524395}} | |
| Area (source URL) |
A | {{#invoke:SK|sk|A|SK0417524395}} | |
| Area Id | b | {{#invoke:SK|sk|b|SK0417524395}} | |
| Population density (as population/area) |
d | {{#invoke:SK|sk|d}} | |
| Data year | y | {{#invoke:SK|sk|y}} | |
| Last acces | l | {{#invoke:SK|sk|l}} | |
| Last update | u | {{#invoke:SK|sk|u}} | |
| Is slovak municipality (none support %i) |
i | {{#invoke:SK|sk|i|SK0417524395}} | |
| Get NUTS/LAU code (none support %e) |
e |
You can used both the format string like printf() with parameters from table.
| Code: | {{#invoke:SK|sk|%p (source: %P)|SK0417524395}} |
| Output: |
Second parameter
It is a STUN or LAU code for place sup-place (ex. SK0417524395). If none, then code is automatic based on the actual page.
--------------------------------------------------------------------
-- SK PRO + SK Stats Medium Loader (A3-2)
-- Optimizirano za enciklopedija.cc
--------------------------------------------------------------------
local p = {}
--------------------------------------------------------------------
-- 1) Tematske boje
--------------------------------------------------------------------
p.colors = {
primary = "#003366",
secondary = "#336699",
accent = "#6699cc",
light = "#eef5ff",
dark = "#001a33",
border = "#aaccee",
}
--------------------------------------------------------------------
-- 2) Profesionalni infookvir
--------------------------------------------------------------------
function p.infobox(frame)
local args = frame:getParent().args
local title = args["naslov"] or args["title"] or "Infookvir"
local out = {}
table.insert(out, '{| class="infobox" style="width:260px; border:1px solid ' .. p.colors.border .. '; background:' .. p.colors.light .. ';"')
table.insert(out, '|-')
table.insert(out, string.format('| style="background:%s; color:white; text-align:center; font-size:120%%; padding:6px;" | %s',
p.colors.primary, title))
for k, v in pairs(args) do
if k ~= "naslov" and k ~= "title" and v ~= "" then
table.insert(out, '|-')
table.insert(out, string.format('| style="font-weight:bold; width:35%%;" | %s || %s', k, v))
end
end
table.insert(out, '|}')
return table.concat(out, "\n")
end
--------------------------------------------------------------------
-- 3) Profesionalni navbox
--------------------------------------------------------------------
function p.navbox(frame)
local args = frame:getParent().args
local title = args["naslov"] or "Navigacija"
local out = {}
table.insert(out, '{| class="navbox" style="width:100%; border:1px solid ' .. p.colors.border .. '; background:' .. p.colors.light .. ';"')
table.insert(out, '|-')
table.insert(out, string.format('| style="background:%s; color:white; text-align:center; font-size:110%%; padding:4px;" | %s',
p.colors.primary, title))
for k, v in pairs(args) do
if k ~= "naslov" and v ~= "" then
table.insert(out, '|-')
table.insert(out, string.format('| style="padding:4px;" | %s', v))
end
end
table.insert(out, '|}')
return table.concat(out, "\n")
end
--------------------------------------------------------------------
-- 4) Badge
--------------------------------------------------------------------
function p.badge(frame)
local args = frame:getParent().args
local text = args[1] or "Oznaka"
local color = args["boja"] or p.colors.primary
return string.format('<span style="background:%s; color:white; padding:2px 6px; border-radius:4px; font-size:90%%;">%s</span>',
color, text)
end
--------------------------------------------------------------------
-- 5) SK Stats Medium — učitavanje 6 data modula
--------------------------------------------------------------------
p.db = {}
local modules = {
"Modul:SK/Data1",
"Modul:SK/Data2",
"Modul:SK/Data3",
"Modul:SK/Data4",
"Modul:SK/Data5",
"Modul:SK/Data6",
}
for _, name in ipairs(modules) do
local ok, raw = pcall(require, name)
if ok and type(raw) == "string" then
for line in raw:gmatch("[^\n]+") do
local code, name, pop, male, female, area, elev, postal, year =
line:match("([^|]+)|([^|]+)|([^|]+)|([^|]+)|([^|]+)|([^|]+)|([^|]+)|([^|]+)|([^|]+)")
if code then
pop = tonumber(pop)
male = tonumber(male)
female = tonumber(female)
area = tonumber(area)
elev = tonumber(elev)
year = tonumber(year)
local density = (pop and area) and string.format("%.1f", pop / area) or "?"
p.db[code] = {
naziv = name,
pop = pop,
male = male,
female = female,
area = area,
elev = elev,
postal = postal,
year = year,
density = density,
}
end
end
end
end
--------------------------------------------------------------------
-- 6) Format funkcije (hrwiki kompatibilno)
--------------------------------------------------------------------
function p.format(code, mode)
local d = p.db[code]
if not d then return "" end
if mode == "p" then return d.naziv end
if mode == "a" then return d.pop end
if mode == "m" then return d.male end
if mode == "f" then return d.female end
if mode == "d" then return d.area end
if mode == "y" then return d.density end
if mode == "e" then return d.elev end
if mode == "z" then return d.postal end
if mode == "g" then return d.year end
return ""
end
--------------------------------------------------------------------
-- 7) Glavna funkcija
--------------------------------------------------------------------
function p.sk(frame)
local args = frame.args
local mode = args[1]
local code = args[2]
if not mode or not code then return "" end
return p.format(code, mode)
end
--------------------------------------------------------------------
-- 8) Fallback
--------------------------------------------------------------------
setmetatable(p, {
__index = function()
return function() return "" end
end
})
return p