Documentation for this module may be created at Module:Locations/doc
local p = {}
local m = require("Module:Main")
local MessageBox = require("Module:MessageBox")
local list = mw.loadData( 'Module:Locations/List' )
----------------------------------------------------------------------------------------------
local list_of_special_types = {
--Burial Grounds
["Ancient Heavenly Corpse Burial Ground"] = "Burial Grounds",
["Bonesea"] = "Burial Grounds",
["Buddhist Burial Plateau"] = "Burial Grounds",
["Divine Tree Ridge"] = "Burial Grounds",
["Drystone Courtyard"] = "Burial Grounds",
["Great Maelstrom"] = "Burial Grounds",
["Prime Ominous Grave"] = "Burial Grounds",
--Ancient Earths
["Bi'an Beastworld"] = "Ancestral Earths",
["Crystalfowl Immortal Mine"] = "Ancestral Earths",
--Ancient Ominous Grounds
["Ghost Forest"] = "Ancient Ominous Grounds",
--seven forbidden zones
["Black Tides"] = "Forbidden Zones",
["Sword Burial Zone"] = "Forbidden Zones",
}
----------------------------------------------------------------------------------------------
local list_of_tribes_by_race = {
["Blood-Devil Tribe"] = "Blood Race",
["Bronze-Carapace Insect Tribe"] = "Ghost Immortals",
["Dwarven Tribe"] = "Ghost Immortals",
["Four Ghosts Tribe"] = "Ghost Immortals",
["Half-Moon Blood Tribe"] = "Blood Race",
["Heart Ghost Tribe"] = "Ghost Immortals",
["Hundred Bones Sacred Tribe"] = "Ghost Immortals",
["Insect King Ghost Tribe"] = "Ghost Immortals",
["Ironscale School"] = "Sea Demons",
["Nether-Soaring Ghost Tribe"] = "Ghost Immortals",
["Nightwalker Tribe"] = "Blood Race",
["Sky-Devil Tribe"] = "Heavenly Devils",
["Snow-Shadow Tribe"] = "Ghost Immortals",
["War Tribe"] = "Ghost Immortals",
}
----------------------------------------------------------------------------------------------
local singular = {
["Worlds"] = "World",
["Regions"] = "Region",
["Places"] = "Place",
["Tribes"] = "Tribe",
["Sects"] = "Sect",
["Clans"] = "Clan",
["Ancient Kingdoms"] = "Ancient Kingdom",
["Kingdoms"] = "Kingdom",
["Cities"] = "City",
["Countries"] = "Country",
["Nations"] = "Nation",
["Dao Lineages"] = "Dao Lineage",
}
----------------------------------------------------------------------------------------------
function p.superior_place_appearances( frame )
local sText = string.gsub(frame.args[1],"'", "'")
local output = ''
local l = list[sText]
local spec = list_of_special_types[sText]
if l ~= nil and string.find(l[1],'Unknown Region') == nil
then output = m.add_category(l[1]..'/Appearances')
end
if spec ~= nil
then output = output..m.add_category(spec..'/Appearances')
end
return output
end
----------------------------------------------------------------------------------------------
function p.subordinates_count( frame )
local sText = string.gsub(frame.args[1],"'", "'")
local r = ''
local n = 0
local i = 0
for k, v in pairs( list ) do
if v == sText[1]
then
r = r..'|category = '..k..'/Appearances'
i = m.pages_in_category(k..'/Appearances', 'pages')
n = n + i
end
end
i = m.pages_in_category(sText..'/Appearances', 'pages')
if i == n or n == 0
then return tostring(i)
else return tostring(i)..' ('..tostring(n)..')'
end
end
----------------------------------------------------------------------------------------------
function p.types( frame )
local sPagename = mw.title.getCurrentTitle().baseText
local sSubname = mw.title.getCurrentTitle().subpageText
local sList = list[sPagename]
if sList == nil then
-- Prevents script error and adds category to location pages that are not in the Locations/List module
return '[[Category:Locations missing in Locations/List module]]'
end
local sPlace = sList[1]
local sType = sList[2]
local sType2 = sType
local sSpecial = ''
local categories = {}
local admin_tasks = ''
local output = ''
if sType == 'Ancient Kingdoms' or sType == 'Kingdoms' or sType == 'Countries'
then sType = 'Nations'
end
if mw.ustring.find(sPagename, 'Unknown Region') ~= nil
then
s = "This is a temporary category for characters, locations, etc. from the yet unknown region of the [["..sPlace.."]]. Once the region is revealed in novel the corresponding pages should be changed."
if basepagename == subpagename
then admin_tasks = MessageBox.admin_tasks(frame, _, s)
else admin_tasks = MessageBox.admin_tasks(frame, 'yes', s)
end
s = "the unknown region of the '''[["..sPlace.."]]'''"
else s = "the '''[["..sPagename.."]]'''."
end
if sPagename == sSubname
then
if list_of_special_types[sPagename] ~= nil
then table.insert(categories, list_of_special_types[sPagename])
end
output = MessageBox.main({message = 'List of articles related to '..s})
table.insert(categories, sPlace..'/'..sType)
if list_of_tribes_by_race[sPagename] ~= nil
then table.insert(categories, list_of_tribes_by_race[sPagename]..'/Tribes')
else table.insert(categories, sType2)
end
else
output = MessageBox.main({message = 'List of '..mw.ustring.lower(sSubname)..' from '..s})
table.insert(categories, sPagename)
if sSubname == 'Regions'
then
table.insert(categories, Regions)
else
table.insert(categories, sPlace..'/'..sSubname)
if sSubname ~= sType
then table.insert(categories, sSubname..' by '..singular[sType])
end
end
end
return frame:preprocess(admin_tasks..output)..m.add_categories(categories)
end
----------------------------------------------------------------------------------------------
function p.destroyed(sDestroyed, sPagename)
local i
local r = false
sDestroyed = string.gsub(sDestroyed,"'","'")
sDestroyed = mw.text.split(sDestroyed,"@",true )
for i=1,#sDestroyed do
if sDestroyed[i] == sPagename
then
r = true
break
end
end
return r
end
----------------------------------------------------------------------------------------------
function p.navbox( frame )
local sPagename = string.gsub(frame.args[1],"'", "'")
local sChild = frame.args[2] or ''
local sState = frame.args[3]
local sDestroyed = frame:expandTemplate{title = 'List of Destroyed Locations'}
local sPlace = list[sPagename][1]
local sType = list[sPagename][2]
local above = {}
local l = {}
local g = {}
local t = { "Dao Lineages", "Ancient Kingdoms", "Kingdoms", "Countries", "Sects", "Tribes", "Clans", "Cities", "Places" }
local l2 = {}
local i = 0
local j = 1
local s
local x = 0
local y = 0
if not m.empty(sState)
then sState = 'collapsed'
else sState = 'expanded'
end
if sType == "Worlds"
then
if sPagename ~= "Sword Continent"
then
y = "[["..sPagename.."]]"
if sPlace == "Nine Worlds" or (sPlace == "Eight Desolates" and sChild ~= "child")
then
for k, v in pairs( list ) do
if v[1] == sPlace
then table.insert(above, k)
end
end
table.sort(above)
for i = 1,#above do
above[i] = "\n*[["..above[i].."]]"
end
if sPlace == "Nine Worlds"
then y = "[[Nine Worlds]]"
else y = "[[Eight Desolates]]"
end
end
for k, v in pairs( list ) do
if v[1] == sPagename
then
i = i + 1
l[i] = "{{Template:"..k.."|type=child}}"
end
end
table.sort(l)
for i = 1,#l do
l[i] = "|list"..i.." = "..l[i]
end
s = "{{Navbox|name = "..sPagename.."|state = "..sState.."|title = "..y.."|groupwidth = 9em|listclass = hlist|aboveclass = hlist|above = "..table.concat(above)..table.concat(l).."}}"
else
sType = "Regions"
end
end
if sType == "Regions"
then
for k, v in pairs( list ) do
if v[1] == sPlace
then table.insert(above, k)
end
end
table.sort(above)
for i = 1,#above do
if above[i] == sPagename
then
if string.find(above[i], 'Unknown Region') ~= nil
then above[i] = "\n*[["..above[i].."|'''''Unknown Region''''']]"
else above[i] = "\n*'''[["..above[i].."]]'''"
end
elseif string.find(above[i], 'Unknown Region') ~= nil
then above[i] = "\n*[["..above[i].."|''Unknown Region'']]"
else above[i] = "\n*[["..above[i].."]]"
end
end
for j = 1,#t do
l[j] = ""
l2 = {}
for k, v in pairs( list ) do
if v[1] == sPagename and v[2] == t[j]
then
table.insert(l2, k)
end
end
if #l2 ~= 0 then
table.sort(l2)
i = 1
while i <= #l2 do
x = l2[i]
y = string.find(x, ' (', 1, true)
if y ~= nil
then x = string.sub(x, 1, y-1)
end
x = "[["..l2[i].."|"..x.."]]"
if p.destroyed(sDestroyed, l2[i]) == true
then l[j] = l[j].."\n*"..m.dead_or_destroyed({x})
else l[j] = l[j].."\n*"..x
end
i = i + 1
end
end
end
i = 1
for j = 1,#t do
if l[j] ~= ""
then
table.insert(g, "|group"..i.." = "..t[j].."|list"..i.." = "..l[j] )
i = i + 1
end
end
if sChild ~=''
then
if string.find(sPagename, 'Unknown Region') ~= nil
then i = "Unknown region of [["..sPlace.."]]"
else i = "[["..sPagename.."]]"
end
j = ''
else
i = "[["..sPlace.."]]"
j = table.concat(above)
end
if sPagename ~= "Sword Continent"
then
s = "{{Navbox|"..sChild.."|name = "..sPagename.."|state = "..sState.."|title = "..i.."|groupwidth = 9em|listclass = hlist|aboveclass = hlist|above = "..j..table.concat(g).."}}"
else
s = "{{Navbox|name = "..sPagename.."|state = "..sState.."|title = "..i.."|groupwidth = 9em|listclass = hlist|aboveclass = hlist|above = "..j..table.concat(g).."}}"
end
end
return frame:preprocess(s)
end
function p.events_by_location( frame )
local sPagename = mw.title.getCurrentTitle().text
local s = string.gsub(sPagename, 'Events in ', '')
local sPlace = list[s][1]
local sType = list[s][2]
local sType2 = sType
local sSpecial = ""
local categories = {}
local output = ''
local sortname = s
if sType == "Ancient Kingdoms" or sType == "Kingdoms" or sType == "Countries"
then sType = "Nations"
end
sType = singular[sType]
output = '{{MessageBox|Events that occurred in the [['..s..']].}}'
table.insert(categories, s)
if sType ~= 'World'
then table.insert(categories, 'Events in '..sPlace)
end
--if sType == 'World' and sPlace == 'Nine Worlds'
-- then table.insert(categories, 'Events in '..sPlace)
-- else
table.insert(categories, 'Events by '..sType)
--end
output = output..m.add_categories(categories, sortname)
return frame:preprocess(output)
end
return p