Module:Places: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (24 intermediate revisions by the same user not shown) | |||
| Line 4: | Line 4: | ||
local data = mw.loadJsonData([[Data:Places]]) | local data = mw.loadJsonData([[Data:Places]]) | ||
_m.format_ruler = function(c) | |||
local f = mw.getCurrentFrame() | |||
if not c.ruler then return "" end | |||
if type(c.ruler_title) == "table" then | |||
if type(c.ruler) ~= "table" then | |||
return f:expandTemplate{title="Warning",args={"Malformed data"}} | |||
end | |||
local out = "" | |||
for i, v in ipairs(c.ruler) do | |||
if i ~= 1 then out = out .. "<br />" end | |||
out = out .. "'''" .. (c.ruler_title[i] or f:expandTemplate{title="Warning",args={"Malformed data"}}) .. ":''' [[" .. v .. "]]" | |||
end | |||
return out | |||
else | |||
local out = (c.ruler_title and "'''" .. c.ruler_title .. "''': " or "") | |||
if type(c.ruler) == "table" then for i, v in ipairs(c.ruler) do if i ~= 1 then out = out .. ", " end out = out .. "[[" .. v .. "]]" end | |||
else | |||
out = out .. "[[" .. (c.ruler_link and c.ruler_link .. "|" or "") .. c.ruler .. "]]" | |||
end | |||
return out | |||
end | |||
end | |||
_m.countries = function(frame) | _m.countries = function(frame) | ||
local out = [==[ | local out = [==[ | ||
| Line 11: | Line 33: | ||
<th>Full name</th> | <th>Full name</th> | ||
<th>Ruler</th> | <th>Ruler</th> | ||
<th data-sort-type="date">Date founded</th> | <th data-sort-type="date">Date founded</th> | ||
<th>Capital</th> | <th>Capital</th> | ||
| Line 23: | Line 44: | ||
if not c.not_ngation and not c.condominium and not c.reason_dissolved and not c.reserved then | if not c.not_ngation and not c.condominium and not c.reason_dissolved and not c.reserved then | ||
out = out .. "<tr>" | out = out .. "<tr>" | ||
out = out .. "<td>" .. | out = out .. "<td>" .. _m.style(c) .. "</td>" | ||
out = out .. "<td>" .. (c.name or "") .. "</td>" | out = out .. "<td>" .. (c.name or "") .. "</td>" | ||
out = out .. "<td>" .. _m.format_ruler(c) .. "</td>" | |||
if not c.date_founded then out = out .. "<td></td>" else | if not c.date_founded then out = out .. "<td></td>" else | ||
out = out .. "<td>" .. u.date(c.date_founded[1], c.date_founded[2], c.date_founded[3], true) .. "</td>" | out = out .. "<td>" .. u.date(c.date_founded[1], c.date_founded[2], c.date_founded[3], true) .. "</td>" | ||
| Line 43: | Line 54: | ||
out = out .. "<td>" .. c.code3 .. "</td>" | out = out .. "<td>" .. c.code3 .. "</td>" | ||
out = out .. "<td>" .. (c.ung == "member" and "yes" or "no") .. "</td>" | out = out .. "<td>" .. (c.ung == "member" and "yes" or "no") .. "</td>" | ||
if not c.notes then out = out .. "<td></td>" else | |||
out = out .. [[<td><div class="mw-collapsible mw-collapsed">]] .. c.notes .. "</div></td>" | |||
end | |||
out = out .. "</tr>" | |||
end | |||
end | |||
out = out .. [[</table>]] | |||
return out | |||
end | |||
_m.condominia = function(frame) | |||
out = [=[ | |||
<table class="wikitable sortable"> | |||
<th>Common name</th> | |||
<th>Full name</th> | |||
<th data-sort-type="date">Date founded</th> | |||
<th>Capital</th> | |||
<th>Parent Ŋation(s)</th> | |||
<th>Code-2</th> | |||
<th>Code-3</th> | |||
<th>Notes</th> | |||
</tr> | |||
]=] | |||
for _, c in ipairs(data.places) do | |||
if c.condominium and not c.reason_dissolved then | |||
out = out .. "<tr>" | |||
out = out .. "<td>" .. _m.style(c) .. "</td>" | |||
out = out .. "<td>" .. (c.name or "") .. "</td>" | |||
if not c.date_founded then out = out .. "<td></td>" else | |||
out = out .. "<td>" .. u.date(c.date_founded[1], c.date_founded[2], c.date_founded[3], true) .. "</td>" | |||
end | |||
out = out .. "<td>" .. (c.capital or "") .. "</td>" | |||
out = out .. "<td>" | |||
for i, p in ipairs(c.condominium) do | |||
if i ~= 1 then out = out .. ", " end | |||
out = out .. _m.get_style(p) | |||
end | |||
out = out .. "</td><td>" .. c.code2 .. "</td>" | |||
out = out .. "<td>" .. c.code3 .. "</td>" | |||
if not c.notes then out = out .. "<td></td>" else | if not c.notes then out = out .. "<td></td>" else | ||
out = out .. [[<td><div class="mw-collapsible mw-collapsed">]] .. c.notes .. "</div></td>" | out = out .. [[<td><div class="mw-collapsible mw-collapsed">]] .. c.notes .. "</div></td>" | ||
| Line 53: | Line 102: | ||
end | end | ||
_m. | _m.non_countries = function(frame) | ||
local out = [=[ | |||
<table class="wikitable sortable"> | |||
<th>Common name</th> | |||
<th>Full name</th> | |||
<th data-sort-type="date">Date founded</th> | |||
<th>Capital</th> | |||
<th>Code-2</th> | |||
<th>Code-3</th> | |||
<th>Notes</th> | |||
</tr> | |||
]=] | |||
for _, c in ipairs(data.places) do | |||
if c.not_ngation and not c.reason_dissolved then | |||
out = out .. "<tr>" | |||
out = out .. "<td>" .. _m.style(c) .. "</td>" | |||
out = out .. "<td>" .. (c.name or "") .. "</td>" | |||
if not c.date_founded then out = out .. "<td></td>" else | |||
out = out .. "<td>" .. u.date(c.date_founded[1], c.date_founded[2], c.date_founded[3], true) .. "</td>" | |||
end | |||
out = out .. "<td>" .. (c.capital or "") .. "</td>" | |||
out = out .. "</td><td>" .. c.code2 .. "</td>" | |||
out = out .. "<td>" .. c.code3 .. "</td>" | |||
if not c.notes then out = out .. "<td></td>" else | |||
out = out .. [[<td><div class="mw-collapsible mw-collapsed">]] .. c.notes .. "</div></td>" | |||
end | |||
out = out .. "</tr>" | |||
end | |||
end | |||
out = out .. [[</table>]] | |||
return out | |||
end | end | ||
_m.former = function(frame) | _m.former = function(frame) | ||
return "" | local out = [==[ | ||
<table class="wikitable sortable"> | |||
<tr> | |||
<th>Common name</th> | |||
<th>Full name</th> | |||
<th>Ruler</th> | |||
<th data-sort-type="date">Date founded</th> | |||
<th data-sort-type="date">Date dissolved</th> | |||
<th>Capital</th> | |||
<th>Code-2</th> | |||
<th>Code-3</th> | |||
<th>Context of dissolution</th> | |||
<th>Notes</th> | |||
</tr> | |||
]==] | |||
for _, c in ipairs(data.places) do | |||
if c.reason_dissolved and not c.reserved then | |||
out = out .. "<tr>" | |||
out = out .. "<td>" .. _m.style(c) .. "</td>" | |||
out = out .. "<td>" .. (c.name or "") .. "</td>" | |||
out = out .. "<td>" .. _m.format_ruler(c) .. "</td>" | |||
if not c.date_founded then out = out .. "<td></td>" else | |||
out = out .. "<td>" .. u.date(c.date_founded[1], c.date_founded[2], c.date_founded[3], true) .. "</td>" | |||
end | |||
if not c.date_dissolved then out = out .. "<td></td>" else | |||
out = out .. "<td>" .. u.date(c.date_dissolved[1], c.date_dissolved[2], c.date_dissolved[3], true) .. "</td>" | |||
end | |||
out = out .. "<td>" .. (c.capital or "") .. "</td>" | |||
out = out .. "<td>" .. c.code2 .. "</td>" | |||
out = out .. "<td>" .. c.code3 .. "</td>" | |||
if type(c.reason_dissolved) ~= "string" then out = out .. "<td></td>" else | |||
out = out .. [[<td><div class="mw-collapsible mw-collapsed">]] .. c.reason_dissolved .. "</div></td>" | |||
end | |||
if not c.notes then out = out .. "<td></td>" else | |||
out = out .. [[<td><div class="mw-collapsible mw-collapsed">]] .. c.notes .. "</div></td>" | |||
end | |||
out = out .. "</tr>" | |||
end | |||
end | |||
out = out .. [[</table>]] | |||
return out | |||
end | |||
_m.get = function(it) for _, v in ipairs(data.places) do if it == v.code2 then return v end end end | |||
_m.style = function(c) | |||
local f = mw.getCurrentFrame() | |||
return (c.banner and f:expandTemplate{title = "Banner", args = {c.code2}} or "") .. " [[" .. c.common_name .. "]]" | |||
end | |||
_m.get_style = function(it) | |||
return _m.style(_m.get(u._a(it))) | |||
end | end | ||
_m.get_banner = function( | _m.get_banner = function(it) | ||
for _, c in ipairs(data.places) do | for _, c in ipairs(data.places) do | ||
if c.code2 == | if c.code2 == u._a(it) then return (c.banner or "???") end | ||
end | end | ||
end | end | ||
return _m | return _m | ||
Latest revision as of 11:45, 19 November 2025
Documentation for this module may be created at Module:Places/doc
local _m = {}
local u = require"Module:Utils"
local data = mw.loadJsonData([[Data:Places]])
_m.format_ruler = function(c)
local f = mw.getCurrentFrame()
if not c.ruler then return "" end
if type(c.ruler_title) == "table" then
if type(c.ruler) ~= "table" then
return f:expandTemplate{title="Warning",args={"Malformed data"}}
end
local out = ""
for i, v in ipairs(c.ruler) do
if i ~= 1 then out = out .. "<br />" end
out = out .. "'''" .. (c.ruler_title[i] or f:expandTemplate{title="Warning",args={"Malformed data"}}) .. ":''' [[" .. v .. "]]"
end
return out
else
local out = (c.ruler_title and "'''" .. c.ruler_title .. "''': " or "")
if type(c.ruler) == "table" then for i, v in ipairs(c.ruler) do if i ~= 1 then out = out .. ", " end out = out .. "[[" .. v .. "]]" end
else
out = out .. "[[" .. (c.ruler_link and c.ruler_link .. "|" or "") .. c.ruler .. "]]"
end
return out
end
end
_m.countries = function(frame)
local out = [==[
<table class="wikitable sortable">
<tr>
<th>Common name</th>
<th>Full name</th>
<th>Ruler</th>
<th data-sort-type="date">Date founded</th>
<th>Capital</th>
<th>Code-2</th>
<th>Code-3</th>
<th>UŊ Member</th>
<th>Notes</th>
</tr>
]==]
for _, c in ipairs(data.places) do
if not c.not_ngation and not c.condominium and not c.reason_dissolved and not c.reserved then
out = out .. "<tr>"
out = out .. "<td>" .. _m.style(c) .. "</td>"
out = out .. "<td>" .. (c.name or "") .. "</td>"
out = out .. "<td>" .. _m.format_ruler(c) .. "</td>"
if not c.date_founded then out = out .. "<td></td>" else
out = out .. "<td>" .. u.date(c.date_founded[1], c.date_founded[2], c.date_founded[3], true) .. "</td>"
end
out = out .. "<td>" .. (c.capital or "") .. "</td>"
out = out .. "<td>" .. c.code2 .. "</td>"
out = out .. "<td>" .. c.code3 .. "</td>"
out = out .. "<td>" .. (c.ung == "member" and "yes" or "no") .. "</td>"
if not c.notes then out = out .. "<td></td>" else
out = out .. [[<td><div class="mw-collapsible mw-collapsed">]] .. c.notes .. "</div></td>"
end
out = out .. "</tr>"
end
end
out = out .. [[</table>]]
return out
end
_m.condominia = function(frame)
out = [=[
<table class="wikitable sortable">
<th>Common name</th>
<th>Full name</th>
<th data-sort-type="date">Date founded</th>
<th>Capital</th>
<th>Parent Ŋation(s)</th>
<th>Code-2</th>
<th>Code-3</th>
<th>Notes</th>
</tr>
]=]
for _, c in ipairs(data.places) do
if c.condominium and not c.reason_dissolved then
out = out .. "<tr>"
out = out .. "<td>" .. _m.style(c) .. "</td>"
out = out .. "<td>" .. (c.name or "") .. "</td>"
if not c.date_founded then out = out .. "<td></td>" else
out = out .. "<td>" .. u.date(c.date_founded[1], c.date_founded[2], c.date_founded[3], true) .. "</td>"
end
out = out .. "<td>" .. (c.capital or "") .. "</td>"
out = out .. "<td>"
for i, p in ipairs(c.condominium) do
if i ~= 1 then out = out .. ", " end
out = out .. _m.get_style(p)
end
out = out .. "</td><td>" .. c.code2 .. "</td>"
out = out .. "<td>" .. c.code3 .. "</td>"
if not c.notes then out = out .. "<td></td>" else
out = out .. [[<td><div class="mw-collapsible mw-collapsed">]] .. c.notes .. "</div></td>"
end
out = out .. "</tr>"
end
end
out = out .. [[</table>]]
return out
end
_m.non_countries = function(frame)
local out = [=[
<table class="wikitable sortable">
<th>Common name</th>
<th>Full name</th>
<th data-sort-type="date">Date founded</th>
<th>Capital</th>
<th>Code-2</th>
<th>Code-3</th>
<th>Notes</th>
</tr>
]=]
for _, c in ipairs(data.places) do
if c.not_ngation and not c.reason_dissolved then
out = out .. "<tr>"
out = out .. "<td>" .. _m.style(c) .. "</td>"
out = out .. "<td>" .. (c.name or "") .. "</td>"
if not c.date_founded then out = out .. "<td></td>" else
out = out .. "<td>" .. u.date(c.date_founded[1], c.date_founded[2], c.date_founded[3], true) .. "</td>"
end
out = out .. "<td>" .. (c.capital or "") .. "</td>"
out = out .. "</td><td>" .. c.code2 .. "</td>"
out = out .. "<td>" .. c.code3 .. "</td>"
if not c.notes then out = out .. "<td></td>" else
out = out .. [[<td><div class="mw-collapsible mw-collapsed">]] .. c.notes .. "</div></td>"
end
out = out .. "</tr>"
end
end
out = out .. [[</table>]]
return out
end
_m.former = function(frame)
local out = [==[
<table class="wikitable sortable">
<tr>
<th>Common name</th>
<th>Full name</th>
<th>Ruler</th>
<th data-sort-type="date">Date founded</th>
<th data-sort-type="date">Date dissolved</th>
<th>Capital</th>
<th>Code-2</th>
<th>Code-3</th>
<th>Context of dissolution</th>
<th>Notes</th>
</tr>
]==]
for _, c in ipairs(data.places) do
if c.reason_dissolved and not c.reserved then
out = out .. "<tr>"
out = out .. "<td>" .. _m.style(c) .. "</td>"
out = out .. "<td>" .. (c.name or "") .. "</td>"
out = out .. "<td>" .. _m.format_ruler(c) .. "</td>"
if not c.date_founded then out = out .. "<td></td>" else
out = out .. "<td>" .. u.date(c.date_founded[1], c.date_founded[2], c.date_founded[3], true) .. "</td>"
end
if not c.date_dissolved then out = out .. "<td></td>" else
out = out .. "<td>" .. u.date(c.date_dissolved[1], c.date_dissolved[2], c.date_dissolved[3], true) .. "</td>"
end
out = out .. "<td>" .. (c.capital or "") .. "</td>"
out = out .. "<td>" .. c.code2 .. "</td>"
out = out .. "<td>" .. c.code3 .. "</td>"
if type(c.reason_dissolved) ~= "string" then out = out .. "<td></td>" else
out = out .. [[<td><div class="mw-collapsible mw-collapsed">]] .. c.reason_dissolved .. "</div></td>"
end
if not c.notes then out = out .. "<td></td>" else
out = out .. [[<td><div class="mw-collapsible mw-collapsed">]] .. c.notes .. "</div></td>"
end
out = out .. "</tr>"
end
end
out = out .. [[</table>]]
return out
end
_m.get = function(it) for _, v in ipairs(data.places) do if it == v.code2 then return v end end end
_m.style = function(c)
local f = mw.getCurrentFrame()
return (c.banner and f:expandTemplate{title = "Banner", args = {c.code2}} or "") .. " [[" .. c.common_name .. "]]"
end
_m.get_style = function(it)
return _m.style(_m.get(u._a(it)))
end
_m.get_banner = function(it)
for _, c in ipairs(data.places) do
if c.code2 == u._a(it) then return (c.banner or "???") end
end
end
return _m