Module:phi-placelist
Appearance
- The following documentation is located at Module:phi-placelist/documentation. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module is used by {{list:places in the Philippines/en}}
.
Data modules
- phi-placelist/data/BARMM
- phi-placelist/data/BARMM/Basilan
- phi-placelist/data/BARMM/Cotabato City
- phi-placelist/data/BARMM/Lanao del Sur
- phi-placelist/data/BARMM/Maguindanao del Norte
- phi-placelist/data/BARMM/Maguindanao del Sur
- phi-placelist/data/BARMM/Special Geographic Area
- phi-placelist/data/BARMM/Tawi-Tawi
- phi-placelist/data/CAR
- phi-placelist/data/CAR/Abra
- phi-placelist/data/CAR/Apayao
- phi-placelist/data/CAR/Baguio
- phi-placelist/data/CAR/Benguet
- phi-placelist/data/CAR/Ifugao
- phi-placelist/data/CAR/Kalinga
- phi-placelist/data/CAR/Mountain Province
- phi-placelist/data/I
- phi-placelist/data/I/Ilocos Norte
- phi-placelist/data/I/Ilocos Sur
- phi-placelist/data/I/La Union
- phi-placelist/data/I/Pangasinan
- phi-placelist/data/II
- phi-placelist/data/II/Batanes
- phi-placelist/data/II/Cagayan
- phi-placelist/data/II/Isabela
- phi-placelist/data/II/Nueva Vizcaya
- phi-placelist/data/II/Quirino
- phi-placelist/data/III
- phi-placelist/data/III/Angeles City
- phi-placelist/data/III/Aurora
- phi-placelist/data/III/Bataan
- phi-placelist/data/III/Bulacan
- phi-placelist/data/III/Nueva Ecija
- phi-placelist/data/III/Olongapo
- phi-placelist/data/III/Pampanga
- phi-placelist/data/III/Tarlac
- phi-placelist/data/III/Zambales
- phi-placelist/data/IV-A
- phi-placelist/data/IV-A/Batangas
- phi-placelist/data/IV-A/Cavite
- phi-placelist/data/IV-A/Laguna
- phi-placelist/data/IV-A/Lucena
- phi-placelist/data/IV-A/Quezon
- phi-placelist/data/IV-A/Rizal
- phi-placelist/data/IX
- phi-placelist/data/IX/Isabela City
- phi-placelist/data/IX/Zamboanga City
- phi-placelist/data/IX/Zamboanga Sibugay
- phi-placelist/data/IX/Zamboanga del Norte
- phi-placelist/data/IX/Zamboanga del Sur
- phi-placelist/data/MIMAROPA
- phi-placelist/data/MIMAROPA/Marinduque
- phi-placelist/data/MIMAROPA/Occidental Mindoro
- phi-placelist/data/MIMAROPA/Oriental Mindoro
- phi-placelist/data/MIMAROPA/Palawan
- phi-placelist/data/MIMAROPA/Puerto Princesa
- phi-placelist/data/MIMAROPA/Romblon
- phi-placelist/data/NCR
- phi-placelist/data/NCR/Caloocan
- phi-placelist/data/NCR/Las Piñas
- phi-placelist/data/NCR/Makati
- phi-placelist/data/NCR/Malabon
- phi-placelist/data/NCR/Mandaluyong
- phi-placelist/data/NCR/Manila
- phi-placelist/data/NCR/Marikina
- phi-placelist/data/NCR/Muntinlupa
- phi-placelist/data/NCR/Navotas
- phi-placelist/data/NCR/Parañaque
- phi-placelist/data/NCR/Pasay
- phi-placelist/data/NCR/Pasig
- phi-placelist/data/NCR/Pateros
- phi-placelist/data/NCR/Quezon City
- phi-placelist/data/NCR/San Juan
- phi-placelist/data/NCR/Taguig
- phi-placelist/data/NCR/Valenzuela
- phi-placelist/data/NIR
- phi-placelist/data/NIR/Bacolod
- phi-placelist/data/NIR/Negros Occidental
- phi-placelist/data/NIR/Negros Oriental
- phi-placelist/data/NIR/Siquijor
- phi-placelist/data/Sulu
- phi-placelist/data/V
- phi-placelist/data/V/Albay
- phi-placelist/data/V/Camarines Norte
- phi-placelist/data/V/Camarines Sur
- phi-placelist/data/V/Catanduanes
- phi-placelist/data/V/Masbate
- phi-placelist/data/V/Sorsogon
- phi-placelist/data/VI
- phi-placelist/data/VI/Aklan
- phi-placelist/data/VI/Antique
- phi-placelist/data/VI/Capiz
- phi-placelist/data/VI/Guimaras
- phi-placelist/data/VI/Iloilo
- phi-placelist/data/VI/Iloilo City
- phi-placelist/data/VII
- phi-placelist/data/VII/Bohol
- phi-placelist/data/VII/Cebu
- phi-placelist/data/VII/Cebu City
- phi-placelist/data/VII/Lapu-Lapu City
- phi-placelist/data/VII/Mandaue
- phi-placelist/data/VIII
- phi-placelist/data/VIII/Biliran
- phi-placelist/data/VIII/Eastern Samar
- phi-placelist/data/VIII/Leyte
- phi-placelist/data/VIII/Northern Samar
- phi-placelist/data/VIII/Samar
- phi-placelist/data/VIII/Southern Leyte
- phi-placelist/data/VIII/Tacloban
- phi-placelist/data/X
- phi-placelist/data/X/Bukidnon
- phi-placelist/data/X/Cagayan de Oro
- phi-placelist/data/X/Camiguin
- phi-placelist/data/X/Iligan
- phi-placelist/data/X/Lanao del Norte
- phi-placelist/data/X/Misamis Occidental
- phi-placelist/data/X/Misamis Oriental
- phi-placelist/data/XI
- phi-placelist/data/XI/Davao City
- phi-placelist/data/XI/Davao Occidental
- phi-placelist/data/XI/Davao Oriental
- phi-placelist/data/XI/Davao de Oro
- phi-placelist/data/XI/Davao del Norte
- phi-placelist/data/XI/Davao del Sur
- phi-placelist/data/XII
- phi-placelist/data/XII/Cotabato
- phi-placelist/data/XII/General Santos
- phi-placelist/data/XII/Sarangani
- phi-placelist/data/XII/South Cotabato
- phi-placelist/data/XII/Sultan Kudarat
- phi-placelist/data/XIII
- phi-placelist/data/XIII/Agusan del Norte
- phi-placelist/data/XIII/Agusan del Sur
- phi-placelist/data/XIII/Butuan
- phi-placelist/data/XIII/Dinagat Islands
- phi-placelist/data/XIII/Surigao del Norte
- phi-placelist/data/XIII/Surigao del Sur
-- Author: [[User:Yivan000]]
-- This is the maximum number of levels/divisions
local maxLevel = 10
-----------------
local function getKeysOfTable(table)
return require("Module:table").keysToList(table);
end
-----------------
-- Main function
local function getTableFromData( args )
local inputtedDivisions = {} -- save here the inputted divisions, in order of less specific to more specific
local level = 0
while ( level < maxLevel ) do
argLevel = args[level]
if argLevel ~= nil then -- get all positional arguments from 0 to `maxLevel`
inputtedDivisions[level] = argLevel
end
level = level + 1
end
-- get the division from data modules
local list = {}
local _region = ""
for i, v in ipairs( inputtedDivisions ) do
if (i == 1 and #inputtedDivisions == 1) then -- if the first and only the first one, get from region data module
list = require("Module:phi-placelist/data/" .. v)
elseif (i == 1) then --if the first one, it is the region, store it
_region = v
elseif (i == 2) then --if the second one, get from data module
-- list = require("Module:phi-placelist/data/" .. _region .. "/" .. v)
--=====
-- TEMPORARY SOLUTION for Sulu since it doesn't have a region,
-- remove this once Sulu has a designated regoon
if _region == "Sulu" then
list = require("Module:phi-placelist/data/" .. _region)[v]
else
list = require("Module:phi-placelist/data/" .. _region .. "/" .. v)
end
--=====
elseif (i == #inputtedDivisions and args["type"] == "hyponyms") then
--special case if hyponyms, get the "hyponyms" table
list = list["hyponyms"][v]
else
list = list[v]
end
end
-- error check so that the last inputted parameter is one division up
if type(list) ~= "table" then
error(inputtedDivisions[#inputtedDivisions] .. " has no divisions.")
end
-- get the keys from the data module & prepare for template call
local divisionName = list["divisions"]
if args["type"] == "hyponyms" then
divisionName = "specific places"
end
local excludesText = nil
if list["excludes"] ~= nil then
excludesText = list["excludes"]
end
-- erase from list before processing the final list
list["divisions"] = nil
list["hyponyms"] = nil
list["excludes"] = nil
-- get final list
local finalList = nil
if args["type"] == "hyponyms" then
finalList = list
else
finalList = getKeysOfTable(list)
end
-- I am mixed on whether to autosort the list.
-- For now, let's not sort due to performance.
--table.sort(finalList)
return finalList, inputtedDivisions, divisionName, excludesText
end
local a = {}
-- for use in the definition lines
function a.linksInDefinition( frame )
local args = frame:getParent().args
local templateToCall = args["type"]
if templateToCall == nil then
templateToCall = "coordinate terms"
end
-- get table
local finalList, inputtedDivisions, divisionName, excludesText = getTableFromData(args)
-- prepare parameters for the {{coordinate terms}} (or others) template call
table.insert(finalList, 1, "en") -- the language parameter
finalList["lb"] = divisionName .. " of " .. inputtedDivisions[#inputtedDivisions] -- the label parameter
if excludesText ~= nil then
finalList["lb"] = finalList["lb"] .. " <small>(excluding " .. excludesText .. ")</small>"
end
return frame:expandTemplate{ title = templateToCall , args = finalList }
end
-- for use in `See also` headings
function a.linksInSeeAlso( frame )
local args = frame:getParent().args
-- get table
local finalList, inputtedDivisions, divisionName, excludesText = getTableFromData(args)
-- prepare parameters for the {{col3}} template call
table.insert(finalList, 1, "en") -- the language parameter
local label = divisionName .. " of " .. inputtedDivisions[#inputtedDivisions] -- label
if excludesText ~= nil then
label = label .. " <small>(excluding " .. excludesText .. ")</small>"
end
-- no need to use {{q}} to reduce lua usage
return "(''" .. label .. "''): " .. frame:expandTemplate{ title = "col3-u" , args = finalList }
end
return a;