This Lua module is used on many pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them.
This module depends on the following other modules:
--generates auto short description for use in infobox settlementlocalp={}p.categories=""localplain=require('Module:Plain text')._mainlocalgetArgs=require('Module:Arguments').getArgslocaltableTools=require('Module:TableTools')functionp.reverseTable(init)init[1],init[3]=init[3],init[1]returninitendfunctionp.assign(args,argname,num)localvallocalvar={}fori=0,numdo--handle initial "subdivision_foo" without numberifi==0thenval=""elseval=tostring(i)endvar[i+1]=p.validate(plain(args[argname..val]))endreturnvarend--Display short description using {{short description}}functionp.shortdesc(text,frame)returnframe:expandTemplate{title='Short description',args={text,'noreplace'}}endfunctionp.category(cattype)localcategory=string.format('[[Category:Pages using infobox settlement with bad %s]]',cattype)ifcategorythenp.categories=p.categories..categoryend--categorizeend--sanity and other checksfunctionp.validate(parameter,cat)ifnotparameterthenreturnnilendparameter=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 endifparameter:match("[,;]")ornotparameter:match("%a")then--must have some letters, ignore if multiple types/subdivisionsifcatthenp.category(cat)endreturnnilendif(parameter=="")thenreturnnilendreturnparameterend--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 locationfunctionp.cleanupLoc(location)iflocation==""thenreturnnilendlocalreplacements={["England, United Kingdom"]="England",["Scotland, United Kingdom"]="Scotland",["Wales, United Kingdom"]="Wales",["New York City, New York, United States"]="New York City",["^United States$"]="the United States",["London, United Kingdom"]="London, England"}fori,vinpairs(replacements)dolocation=location:gsub(i,v)--series of replacementsendreturnlocationendfunctionp.main(frame)localcategories=""localsubdivision_types={}localsubdivision_names={}localargs=getArgs(frame,{parentOnly=true})localsettlement_type=p.validate(plain(args.settlement_typeorargs.type),"settlement type")or"Place"localshort_description=plain(args.short_description)subdivision_types=p.assign(args,"subdivision_type",2)subdivision_names=p.assign(args,"subdivision_name",2)ifshort_descriptionthenif(short_description=='no')thenreturnelselocallanguage=mw.language.getContentLanguage()returnp.shortdesc(language:ucfirst(short_description),frame)endendifnot(subdivision_names[3]and(string.find(settlement_type,'[nN]eighbo[u]?rhood')orstring.find(settlement_type,'[sS]uburb')))thensubdivision_names[3]=nil--display the third subdivision_type only if suburb or neighborhoodend--if say "Voivodeship" is found within the subdivision_type, then specially handle--by adding Voivodeship to the end if not already presentforx,yinipairs(subdivision_types)dolocalspecial_types={"Voivodeship"}fori,jinipairs(special_types)doifsubdivision_names[x]andstring.find(y,j,1,true)andnotstring.find(subdivision_names[x],j,1,true)thensubdivision_names[x]=subdivision_names[x].." "..jendendendforx,yinipairs(subdivision_names)doifythenifstring.find(settlement_type,y,1,true)then--if the subdivision is found within the settlement typesubdivision_names[x]=nil--don't display redundancyp.category("settlement type")endify==mw.title.getCurrentTitle().textthen--if the title is the same as one of the subdivision_namessubdivision_names[x]=nil--don't display redundancyendendendlocallocation=table.concat(tableTools.compressSparseArray(p.reverseTable(subdivision_names)),', ')location=p.cleanupLoc(location)iflocationthenlocation=" in "..locationelselocation=""endlocallanguage=mw.language.getContentLanguage()returnp.shortdesc(language:ucfirst(settlement_type..location),frame)..p.categoriesendreturnp