Jump to content

Module:Settlement short description

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Galobtter (talk | contribs) at 14:40, 19 January 2019 (save). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

--generates auto short description for use in infobox settlement
local p = {}
local plain = require('Module:Plain text')._main
local getArgs = require('Module:Arguments').getArgs
local categoryHandler = require( 'Module:Category handler' ).main
local tableTools = require ('Module:TableTools')

function p.shortdesc(text, frame)
	return frame:expandTemplate{title = 'Short description', args = {text}}
end

function p.main(frame)
	local args = getArgs (frame, {frameOnly = true})
	local settlement_type = plain(args[1])
	local short_description = plain(args[2])
	local subdivision_name = plain(args[3])
	local subdivision_name1 = plain(args[4])
	local subdivision_name2 = plain(args[5])
	if short_description then
		if (short_description == 'no') then
			return
		else
			return p.shortdesc(short_description, frame)
		end
	end
	if not settlement_type then settlement_type = 'Place' end
	if not subdivision_name then return p.shortdesc(settlement_type, frame, 1, true) end
	if (string.find(settlement_type, subdivision_name)
		or (subdivision_name1 and string.find(settlement_type, subdivision_name1, 1, true))) then
		return categoryHandler{'[[Category:Infobox settlement pages with bad settlement type]]', nocat = args.nocat}
	else
		if not(subdivision_name2 and string.find(settlement_type, '[nN]eighbo[u]?rhood')) then
			subdivision_name2 = nil
		end
		return p.shortdesc(string.format('%s in %s', settlement_type,
			table.concat(tableTools.compressSparseArray({subdivision_name2, subdivision_name1, subdivision_name}), ', ')), frame)
	end
end
return p