local p =
local format = mw.ustring.formatlocal concat = table.concatlocal insert = table.insert
local roadDataModule = require("Module:Road data")
-- TODO transition-- begin transition codelocal region_special =
local indep_city =
local sub1Config =
local sub1name =
local sub1span =
local sub2params =
local subConfig =
local pspan =
local function sub_special(args, subTypeConfig, specialPrefix, subType) -- Find parameter. local subParam for _,p in ipairs(subTypeConfig) do if args[p .. 1] or args[p] then subParam = p break end end if not subParam then return args[specialPrefix .. "_special"] end local config = subConfig[subParam] or local subs = -- Retrieve wikilinks for subdivisions. local num = 1 while num
1 and args[subParam] saved.sub1dab = args.sub1dab args.sub1dab = args["ctdab" .. num] or args.ctdab or num
1 and config.firstnonum and args.area) local locns = roadDataModule.locations(args, "jctint", true) -- Restore parameters. args[subType] = saved[subType] args.sub1dab = saved.sub1dab args.area = saved.area subs[num] = locns[subType] num = num + 1 end if #subs > 1 then -- Construct wikitext for multiple subs. local textParts = insert(textParts, subs[1]) for i = 2, #subs do insert(textParts, "–") if i % 2 ~= 0 then -- Odd subs after first begin a new line. insert(textParts, "
") end insert(textParts, subs[i]) end local groupSuffix = args[specialPrefix .. "_group"] or config.group if groupSuffix then insert(textParts, format("%s%s", #subs % 2
2 then insert(textParts, " line") elseif #subs
4 then insert(textParts, " quadripoint") else insert(textParts, " multipoint") end return concat(textParts) elseif #subs
local function trackedArray(arr) local origArr = arr arr = local mt = setmetatable(arr, mt) return arrend
function p._jctint(args) local sub1config = sub1Config[args.state] or "county" -- Tracked parameters local msgs = if (args.township or args.township1) and args[sub1config] and not (args.ctdab or args.ctdab1) then insert(msgs, format("", "D")) elseif not (args.location3 or args.township3 or args.town3) and args.ctdab and (args.ctdab1 or args.ctdab2) then insert(msgs, format("", "D")) end if args.township2 and args.township then insert(msgs, format("", "T")) end if args.type
" " then insert(msgs, format("", "B")) break end end local spans = for _,param in ipairs(spans) do if args[param]
-- Track used arguments local origArgs = args args = trackedArray(args)
local lengthUnit = args.unitdef or "mile" -- Extra parameters local moduleArgs = -- Parameters to be renamed local paramSubst = -- Redirect undefined arguments to passed arguments local mt = setmetatable(moduleArgs, mt)
moduleArgs.country = "USA" -- TODO transition -- begin transition code moduleArgs.primary_topic = "no" moduleArgs.sub1name = sub1name[args.state] or "County" moduleArgs.region_special = region_special[args.state] moduleArgs.region = mw.loadData("Module:Jct/statename")[args.state] -- Independent city local indepCityText = sub_special(moduleArgs,, "indep_city", "sub2") if not indepCityText and args.indep_city then local indepCity = args.indep_city local spec = indep_city[args.state] and (indep_city[args.state][indepCity] or indep_city[args.state].default) if spec then local link = format("%s%s%s", spec.linkprefix or "", indepCity, spec.linksuffix or "") local name = format("%s%s%s", spec.nameprefix or "", indepCity, spec.namesuffix or "") indepCityText = format("%s%s", spec.prefix or "", link, name) else -- Specialize independent city to the region. local cityLink = format('%s', indepCity, moduleArgs.region, indepCity) indepCityText = "City of " .. cityLink end args.indep_city = nil end moduleArgs.indep_city_special = indepCityText moduleArgs.sub1_special = sub_special(moduleArgs,, sub1config, "sub1") local sub2Config = if args.sub2param then insert(sub2Config, args.sub2param) end if sub2params[args.state] then for _,param in ipairs(sub2params[args.state]) do insert(sub2Config, param) end end insert(sub2Config, "location") moduleArgs.sub2_special = sub_special(moduleArgs, sub2Config, "location", "sub2") -- end transition code moduleArgs.unitdef = args.unitdef or "mi"
-- Crossing if args.xing then local colType local colAlignType if args.xcspan
"2" then colType = "indep_city_special" colAlignType = "indep_city_align" else colType = "sub2_special" colAlignType = "sub2_align" end moduleArgs[colType] = args.xing moduleArgs[colAlignType] = "center" end
local coreModule = require("Module:Jctint/core") local coreResult = coreModule._jctint(moduleArgs)
-- Report unused arguments local unusedArgs = for key,_ in pairs(origArgs) do insert(unusedArgs, key) end
local msg if #msgs > 0 then local page = mw.title.getCurrentTitle.prefixedText -- Get transcluding page's title msg = mw.ustring.gsub(concat(msgs), "%%page%%", page) end return coreResult .. (msg or ""), unusedArgsend
function p.jctint(frame) -- Import module function to work with passed arguments local getArgs = require('Module:Arguments').getArgs local args = getArgs(frame)
-- Remove parameters already used in the template definition if args.used_params then for param in mw.text.gsplit(args.used_params, ",") do args[param] = nil end args.used_params = nil end
local result, unusedArgs = p._jctint(args)
-- Check for overridden arguments local frameArgs = getArgs(frame,) local parentArgs = getArgs(frame,) for key,_ in pairs(frameArgs) do if parentArgs[key] then insert(unusedArgs, key) end end
-- Report unused arguments local msg if #unusedArgs > 0 then msg = format("" .. '
', "U", concat(unusedArgs, ", ")) local page = mw.title.getCurrentTitle.prefixedText -- Get transcluding page's title msg = mw.ustring.gsub(msg, "%%page%%", page) end return result .. (msg or "")endreturn p