-- This is Template:Infobox_Australian_place converted to Lua
local p = local lframe
local shortDescription = require('Module:GetShortDescription').mainlocal plainText = require('Module:Plain text')._mainlocal infobox = require('Module:Infobox').infoboxlocal getArgs = require('Module:Arguments').getArgslocal infoboxImage = require('Module:InfoboxImage').InfoboxImage-- [upgrade] Australian place map is now internal-- local australianPlaceMap = require('Module:Australian place map').mainlocal coordinates = require('Module:Coordinates').coordinsertlocal populationFromWikidata = require('Module:PopulationFromWikidata').ListForInfoboxlocal url = require('Module:URL')._urllocal check = require('Module:Check for unknown parameters')._check
local lang = mw.language.getContentLanguage
local function inb(s) -- is not blank return s and s ~= end
local function isnot_blankorno(s) if s
local function backcolour(typ) local colour if typ
'town' then colour = '#e9f9d2' elseif typ
'lga' then colour = '#d2d5f9' elseif typ
'cadastral' then colour = '#ffffe0' elseif typ
'other' then colour = 'transparent' else colour = '#ccc' end return colourend
local function state_longname(state) state = string.lower(state) local longname if state
'vic' then longname = 'Victoria' elseif state
'qld' then longname = 'Queensland' elseif state
'wa' then longname = 'Western Australia' elseif state
'act' then longname = 'Australian Capital Territory' elseif state
'ni' then longname = 'Norfolk Island' elseif state
local function coords_region(state) state = string.lower(state) local region if state
'vic' then region = 'AU-VIC' elseif state
'qld' then region = 'AU-QLD' elseif state
'wa' then region = 'AU-WA' elseif state
'act' then region = 'AU-ACT' elseif state
'ni' then region = 'NF' else region = 'AU' end return regionend
local function location(loc, dir, dist, list) if not (inb(loc) and inb(dist)) then return end local sloc = if list then table.insert(sloc, '
local function lgas_article(state) state = string.lower(state) local art if state
'vic' then art = 'LGA(s)' elseif state
'qld' then art = 'LGA(s)' elseif state
'wa' then art = 'LGA(s)' elseif state
'act' then art = 'District' else art = 'LGA(s)' end return artend
local function pageExists(pagename) local pageTitle = mw.title.makeTitle("", pagename) if pageTitle then return pageTitle.exists end return falseend
local function state_protectedPage(state) state = string.lower(state) local prot if state
'vic' then prot = 'Protected areas of Victoria' elseif state
'qld' then prot = 'Protected areas of Queensland' elseif state
'wa' then prot = 'List of protected areas of
Western Australia' elseif state
'act' then prot = 'Australian Capital Territory
protected areas' else prot = nil end return protend
local function australianPlaceMap(args) local statenames = local mapwidths = local place_type = (args.type or ):lower local map_type = (args.map_type or 'auto'):lower local state_abbr = (args.state or ):lower local map_width = 270 local coords = args.coordinates or local map_name if inb(coords) then else map_type = 'nomap' end
-- [upgrade] map_type has priority over legacy parms, and for 'flag' parms 'no' means 'no' -- the valid normal values for map_type are 'nomap', 'national', 'australia', 'state', 'lga' and 'auto'.
'national' or map_type
'state' then map_name = 'Australia ' .. (statenames[state_abbr] or ) map_width = mapwidths[state_abbr] or 270 elseif map_type
'auto' or map_type
'lga' then -- default for LGAs is no map map_type = 'nomap' else -- default for all other place types is the state map map_name = 'Australia ' .. (statenames[state_abbr] or ) map_width = mapwidths[state_abbr] or 270 end else -- args.map_type assumed to be a valid map name, or a series of valid map names separated by '#' map_name = args.map_type map_type = 'altmap' end -- Build the map if map_type ~= 'nomap' then local caption = args.pushpin_map_caption or if caption ~= then caption = '
' .. caption .. '
' end
-- [upgrade] for 'flag' parms: 'no' means 'no' local relf = if isnot_blankorno(args.relief) then relf = args.relief end return lframe:expandTemplate end return end
local function shortDesc(args) local sd =
-- only set short description in article namespace, and for articles where not already set local title = mw.title.getCurrentTitle if title.namespace
then table.insert(sd, '') end
return table.concat(sd)end
local function ibox(args) local tmp
local InfoboxArgs = local typ = (args.type or ):lower local city = args.city or local state = (args.state or ):lower local state_long = state_longname(state) local name = args.name or
InfoboxArgs.bodyclass = 'vcard'
InfoboxArgs.abovestyle = 'font-size: 125%; line-height: 1.3em; background-color:' .. backcolour(typ)-- [upgrade] error messages for unrecognised or missing |type now at top of the infobox tmp = if typ
'town' or typ
'lga' or typ
'cadastral' or typ
'other') then tmp = '
' .. lframe:expandTemplate .. '' .. args.native_name .. '
' end tmp = tmp .. '
' if city ~= then tmp = tmp .. lframe:expandTemplate .. ', ' end tmp = tmp .. state_long ..'' end InfoboxArgs.above = tmp InfoboxArgs.aboveclass = 'adr' InfoboxArgs.subheaderstyle = 'font-size: 100%;' if typif inb(args.image) then-- [upgrade] remove response to obsolete parameters image_size and imagesize--[=[ local siz if inb(args.image_size) then siz = args.image_size elseif inb(args.imagesize) then siz = args.imagesize end ]=] local upr = '1.23' if inb(args.image_upright) then upr = args.image_upright end local ialt if inb(args.image_alt) then ialt = args.image_alt-- [upgrade] remove response to obsolete parameter alt--[=[ elseif inb(args.alt) then ialt = args.alt ]=] end InfoboxArgs.image = infoboxImage end InfoboxArgs.imagestyle = nil InfoboxArgs.caption = (args.caption or ) InfoboxArgs.captionstyle = nil if inb(args.image2) then-- [upgrade] remove response to obsolete parameters image_size2 and imagesize2--[=[ local siz if inb(args.image_size2) then siz = args.image_size2 elseif inb(args.imagesize2) then siz = args.imagesize2 end ]=] local upr = '1.23' if inb(args.image2_upright) then upr = args.image2_upright end local ialt if inb(args.image2_alt) then ialt = args.image2_alt-- [upgrade] remove response to obsolete parameter alt2--[=[ elseif inb(args.alt2) then ialt = args.alt2 ]=] end InfoboxArgs.image2 = infoboxImage end InfoboxArgs.caption2 = (args.caption2 or )
InfoboxArgs.headerstyle = 'background-color:#ddf;' InfoboxArgs.labelstyle = 'width:40%; background-color:' .. backcolour(typ) InfoboxArgs.datastyle = nil
-- [upgrade] allow local map to have a caption set--[=[ InfoboxArgs.data1 = australianPlaceMap(lframe) InfoboxArgs.data2 = nil if inb(args.local_map) then InfoboxArgs.data2 = lframe:expandTemplate{ title = 'Infobox mapframe', args = {zoom = (args.zoom or ''), id = (args.local_map_id or '')} } end ]=]-- [upgrade] use upgraded Australian place map (now an internal function)-- InfoboxArgs.image3 = australianPlaceMap(lframe) InfoboxArgs.image3 = australianPlaceMap(args)
InfoboxArgs.image4 = nil if isnot_blankorno(args.local_map) then InfoboxArgs.image4 = lframe:expandTemplate end InfoboxArgs.caption4 = (args.local_map_caption or )
InfoboxArgs.label3 = '
Nearest town or city' InfoboxArgs.data3 = nil if typInfoboxArgs.label4 = 'Coordinates' InfoboxArgs.data4 = nil if inb(args.coordinates) then -- the type: and region: parameters to Module:Coordinates seem to be over-ridden by this code, even though they could be in the call that produces the content of the coordinates parameter local mtyp = -- [upgrade] difference between |type=protected and other types removed--[=[ if typ == 'protected' then mtyp = 'landmark' else mtyp = 'city' end ]=] mtyp = 'city' InfoboxArgs.data4 = coordinates .. (args.coord_ref or ) end
InfoboxArgs.label6 = 'Population' tmp = if inb(args.pop) then-- [upgrade] |pop2 shown no matter how |pop is derived--[=[ if inb(args.pop2) then tmp = '<ul style="margin-top: 0px; margin-bottom: 0px;"><li>' else tmp = '' end ]=] if tonumber(args.pop) then -- pop looks like a number tmp = tmp .. lang:formatNum(tonumber(args.pop)) else -- just show it tmp = tmp .. args.pop end if inb(args.pop_year) then tmp = tmp .. ' (' .. args.pop_year .. ')' end tmp = tmp .. (args.pop_footnotes or ) if inb(args.poprank) then tmp = tmp .. ' (' .. args.poprank .. ')' end-- [upgrade] |pop2 shown no matter how |pop is derived--[=[ if inb(args.pop2) then tmp = tmp .. '</li><li> ' if tonumber(args.pop2) then -- pop2 looks like a number tmp = tmp .. lang:formatNum(tonumber(args.pop2)) else -- just show it tmp = tmp .. args.pop2 end if inb(args.pop2_year) then tmp = tmp .. ' (' .. args.pop2_year .. ')' end tmp = tmp .. (args.pop2_footnotes or '') tmp = tmp .. '</li></ul>' end ]=] else local wdpop = populationFromWikidata if inb(wdpop) then-- [upgrade] show |poprank after wikidata derived pop info if inb(args.poprank) then wdpop = wdpop .. ' (' .. args.poprank .. ')' end-- [upgrade] make geography abbreviation tooltops more explanatory wdpop = string.gsub(wdpop, 'urban centre and locality', 'urban area (Urban Centre and Locality)') if typ
-- The
here prevents the output from populationFromWikidata appearing above the infobox instead of within it. -- I don't know why, but the output from in the template version is treated properly, -- but the output from calling require('Module:PopulationFromWikidata').ListForInfobox in this module is not, requiring this fix. tmp = '
' .. wdpop .. '
' end end-- [upgrade] |pop2 shown no matter how |pop is derived if inb(args.pop2) then local list = false if inb(tmp) then tmp = '
InfoboxArgs.label7 = ' • Density' tmp = nil if inb(args.density) then-- [upgrade] space between density and density_footnotes removed-- tmp = lframe:expandTemplate .. ' ' .. (args.density_footnotes or ) tmp = lframe:expandTemplate .. (args.density_footnotes or ) else if inb(args.pop) and lang:parseFormattedNumber(args.pop) and inb(args.area) then-- tmp = lframe:expandTemplate .. ' ' .. (args.density_footnotes or ) tmp = lframe:expandTemplate .. (args.density_footnotes or ) end end InfoboxArgs.data7 = tmp
InfoboxArgs.label8 = 'Established' tmp = nil if inb(args.established) then tmp = args.established .. (args.established_footnotes or ) elseif inb(args.est) then tmp = args.est .. (args.established_footnotes or ) end InfoboxArgs.data8 = tmp
InfoboxArgs.label9 = 'Abolished' InfoboxArgs.data9 = args.abolished or InfoboxArgs.label10 = 'Gazetted' InfoboxArgs.data10 = args.gazetted or InfoboxArgs.label11 = 'Postcode(s)' InfoboxArgs.data11 = args.postcode or InfoboxArgs.label12 = 'Elevation' if inb(args.elevation) then InfoboxArgs.data12 = lframe:expandTemplate .. (args.elevation_footnotes or ) end InfoboxArgs.label13 = 'Area' if inb(args.area) then InfoboxArgs.data13 = lframe:expandTemplate .. (args.area_footnotes or ) end
InfoboxArgs.label14 = 'Time zone' if inb(args.timezone) then InfoboxArgs.data14 = args.timezone .. ' ' .. '(UTC' .. (args.utc or ) .. ')' end
InfoboxArgs.label15 = ' • Summer (DST)' if inb(args['timezone-dst']) then InfoboxArgs.data15 = args['timezone-dst'] .. ' ' .. '(UTC' .. (args['utc-dst'] or ) .. ')' end
InfoboxArgs.label16 = (args.mayortitle or 'Mayor') if typ
InfoboxArgs.label17 = 'Location' tmp = if inb(args.dist2) then tmp = '' tmp = tmp .. location(args.location1, args.dir1, args.dist1, true) tmp = tmp .. location(args.location2, args.dir2, args.dist2, true) tmp = tmp .. location(args.location3, args.dir3, args.dist3, true) tmp = tmp .. location(args.location4, args.dir4, args.dist4, true) tmp = tmp .. location(args.location5, args.dir5, args.dist5, true) tmp = tmp .. '
' elseif inb(args.location1) then tmp = location(args.location1, args.dir1, args.dist1, false) end InfoboxArgs.data17 = tmp
InfoboxArgs.label18 = lgas_article(state) tmp = nil if inb(args.lga) then local lga2 = args.lga2 or if lga2 ~= then tmp = '
InfoboxArgs.label20 = 'Region' if inb(args.region) then InfoboxArgs.data20 = lframe:expandTemplate end
InfoboxArgs.label21 = 'County' if inb(args.county) then InfoboxArgs.data21 = lframe:expandTemplate end InfoboxArgs.label22 = 'Parish' InfoboxArgs.data22 = args.parish or if typ
'act' or state
'jbt' then InfoboxArgs.label26 = 'Territory electorates(s)' else InfoboxArgs.label26 = 'State electorate(s)' end tmp = nil if inb(args.stategov) then local stategov2 = (args.stategov2 or ) if stategov2 ~= then tmp = '
InfoboxArgs.label27 = 'Federal division(s)' tmp = nil if inb(args.fedgov) then local fedgov2 = args.fedgov2 or if fedgov2 ~= then tmp = '
if inb(args.logo) then local siz-- [upgrade] remove response to obsolete parameter logosize--[=[ if inb(args.logosize) then siz = args.logosize end ]=] local upr = '0.8' if inb(args.logo_upright) then upr = args.logo_upright end-- [upgrade] remove response to obsolete parameter logoalt--[=[ local lalt if inb(args.logo_alt) then lalt = args.logo_alt end ]=] InfoboxArgs.data28 = infoboxImage end-- [upgrade] allow a caption on the logo image InfoboxArgs.data29 = args.logo_caption or
InfoboxArgs.label30 = 'Visitation' if typ
InfoboxArgs.label32 = 'Website' if inb(args.url) then InfoboxArgs.data32 = url(args.url, name) .. ' ' end
tmp = nil if inb(args.maxtemp) or inb(args.mintemp) or inb(args.rainfall) then tmp = '
' .. '\'\'\'Mean max temp\'\'\ .. (args.maxtemp_footnotes or ) .. ' | \'\'\'Mean min temp\'\'\ .. (args.mintemp_footnotes or ) .. ' | \'\'\'Annual rainfall\'\'\ .. (args.rainfall_footnotes or ) .. ' | ' .. '\'\'\'Mean max temp\'\'\ .. (args.maxtemp_footnotes or ) .. ' | \'\'\'Mean min temp\'\'\ .. (args.mintemp_footnotes or ) .. ' | \'\'\'Annual rainfall\'\'\ .. (args.rainfall_footnotes or ) .. ' |
' if inb(args.maxtemp) then tmp = tmp .. lframe:expandTemplate .. ' | ' if inb(args.mintemp) then tmp = tmp .. lframe:expandTemplate .. ' | ' if inb(args.rainfall) then tmp = tmp .. lframe:expandTemplate .. ' |
tmp = nil if inb(args['near']) or inb(args['near-nw']) or inb(args['near-n']) or inb(args['near-ne']) or inb(args['near-w']) or inb(args['near-e']) or inb(args['near-sw']) or inb(args['near-s']) or inb(args['near-se']) then tmp = '
\'\'\ tmp = tmp .. '\'\'\ if typ | 'cadastral' then tmp = tmp .. 'Lands administrative divisions' elseif typ'lga' then tmp = tmp .. 'LGAs' elseif typ 'suburb' then if city ~= then if pageExists('List of ' .. city .. ' suburbs') then tmp = tmp .. 'Suburbs' elseif pageExists('Category:Suburbs of the City of ' .. city) then tmp = tmp .. '' elseif pageExists('Category:Suburbs of ' .. city) then tmp = tmp .. '' else tmp = tmp .. 'Suburbs' end else tmp = tmp .. 'Suburbs' end else tmp = tmp .. 'Localities' end tmp = tmp .. ' around ' if name ~= then tmp = tmp .. name else tmp = tmp .. lframe:expandTemplate end tmp = tmp .. '\'\'\'' .. (args['near-nw'] or ) .. ' | ' .. (args['near-n'] or ) .. ' | ' .. (args['near-ne'] or ) .. ' | ' .. (args['near-w'] or ) .. ' | ' .. (args['near'] or name) .. ' | ' .. (args['near-e'] or ) .. ' | ' .. (args['near-sw'] or ) .. ' | ' .. (args['near-s'] or ) .. ' | ' .. (args['near-se'] or ) .. ' | |
InfoboxArgs.label35 = 'Footnotes' InfoboxArgs.data35 = args.footnotes or
InfoboxArgs.label36 = 'See also' if typ
-- [upgrade] error message for unrecognised or empty |type now at top of infobox--[=[ tmp = nil if typ == '' then tmp = lframe:expandTemplate{ title = 'Error', args = {'Error: <code>|type=</code> not defined ([[Template:Infobox Australian place#type|help]])'} } elseif not (typ
'town' or typ
'lga' or typ
'cadastral' or typ
'other') then tmp = lframe:expandTemplate end InfoboxArgs.data37 = tmp]=] return infobox(InfoboxArgs)end
local function categories(args) local cats = local typ = string.lower(args.type or ) local state = string.lower(args.state or ) if mw.title.getCurrentTitle.namespace
'town' then if state
'vic' then table.insert(cats, '') elseif state
'qld' then table.insert(cats, '') elseif state
'wa' then table.insert(cats, '') elseif state
'act' then table.insert(cats, '') elseif state
'suburb' then local city = args.city or if pageExists('Category:Suburbs of the City of ' .. city) then table.insert(cats, '') elseif pageExists('Category:Suburbs of ' .. city) then table.insert(cats, '') else if state
'vic' and pageExists('Category:Suburbs of ' .. city .. ', Victoria') then table.insert(cats, '') elseif state
'qld' and pageExists('Category:Suburbs of ' .. city .. ', Queensland') then table.insert(cats, '') elseif state
'wa' and pageExists('Category:Suburbs of ' .. city .. ', Western Australi') then table.insert(cats, '') elseif state
'act' and pageExists('Category:Suburbs of ' .. city .. ', ACT') then table.insert(cats, '') end end-- [upgrade] articles put in categories for |established and |est, and for all types--[=[ elseif inb(args.est) and typ == 'lga' then if pageExists('Category:Populated places established in ' .. (args.est or '')) then table.insert(cats, '[[Category:Populated places established in ' .. (args.est or '') .. '|' .. name .. ']]') elseif pageExists('Category:Populated places established in the ' .. (args.est or )) then table.insert(cats, '') elseif pageExists('Category:' .. (args.est or ) .. ' establishments in Australia') then table.insert(cats, '') end]=] end if inb(args.established) or inb(args.est) then if pageExists('Category:Populated places established in ' .. (args.established or args.est or )) then table.insert(cats, '') elseif pageExists('Category:Populated places established in the ' .. (args.established or args.est or )) then table.insert(cats, '') end if pageExists('Category:' .. (args.established or args.est or ) .. ' establishments in Australia') then table.insert(cats, '') end end end
-- Tracking categories if args['1'] then -- The '1' parameter occurs when there is a missing equals sign, or spurious pipes. Usually harmless, but can mask other issues, so it is better to track them. table.insert(cats, '') end if (args.type or )
then table.insert(cats, '') end if inb(args.pop) then if (args.pop_year or )
then table.insert(cats, '') end end if inb(args.pop2) then if (args.pop2_year or )
then table.insert(cats, '') end end if (args.density or )
'number' then -- density calculation should be OK else table.insert(cats, '') end end-- [upgrade] remove special categories treatment of obsolete parameters--[=[ if args.imagesize or args.image2size or args.imagesize2 or args.image_alt2 then table.insert(cats, '[[Category:Australian place articles using missing parameters|I]]') end if args.logosize then table.insert(cats, '') end if args.official_site then table.insert(cats, '') end]=] if args.coordinates then if typ
or string.lower(args.map_type or )
function p.main(frame) lframe = frame local getArgs = require('Module:Arguments').getArgs local args = getArgs(frame) return shortDesc(args) .. ibox(args) .. categories(args)end
return p