--generates auto short description for use in infobox settlementlocal p = p.categories = ""local plain = require('Module:Plain text')._mainlocal getArgs = require('Module:Arguments').getArgslocal tableTools = require ('Module:TableTools')
function p.reverseTable (init) init[1], init[3] = init[3], init[1] return initend
function p.assign (args, argname, num) local val local var = for i = 0,num do --handle initial "subdivision_foo" without number if i
--Display short description using function p.shortdesc(text, frame) return frame:expandTemplateend
function p.category (cattype) local category = string.format('', cattype) if category then p.categories = p.categories..category end --categorizeend
--sanity and other checksfunction p.validate (parameter, cat) if not parameter then return nil end parameter = parameter:gsub('%b', ) --remove things in brackets as extraneous information :gsub('%s+', ' ') --fix possible extra spaces from previous cleanup :gsub('^%s+', ) --trim spaces from beginning :gsub('%s+$', ) --trim spaces from end if parameter:match("[,;]") or not parameter:match("%a") then --must have some letters, ignore if multiple types/subdivisions if cat then p.category (cat) end return nil end if (parameter
--removes redundancy like "England, United Kingdom" and fixes issues like "Foo in United States" (to "Foo in the United States")--also used in Module:Type in locationfunction p.cleanupLoc (location) if location
function p.main(frame) local categories = "" local subdivision_types = local subdivision_names = local args = getArgs (frame,) local settlement_type = p.validate(plain(args.settlement_type or args.type), "settlement type") or "Place" local short_description = plain(args.short_description) subdivision_types = p.assign(args, "subdivision_type", 2) subdivision_names = p.assign(args, "subdivision_name", 2) if short_description then if (short_description
mw.title.getCurrentTitle.text then --if the title is the same as one of the subdivision_names subdivision_names[x] = nil --don't display redundancy end end end
local location = table.concat(tableTools.compressSparseArray(p.reverseTable(subdivision_names)), ', ') location = p.cleanupLoc (location) if location then location = " in " .. location else location = "" end local language = mw.language.getContentLanguage return p.shortdesc(language:ucfirst(settlement_type..location), frame)..p.categoriesend
return p