Jump to content

Module:Infobox road/sandbox2

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Fredddie (talk | contribs) at 04:44, 13 December 2021. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}

local getArgs = require('Module:Arguments').getArgs
local roadDataModule = require("Module:Road data")
local yesno = require('Module:Yesno')
local routeModule = require("Module:Infobox road/route")
local mapModule = require("Module:Infobox road/map")
local lengthModule = require("Module:Infobox road/length/sandbox")
local sectionModule = require("Module:Infobox road/sections")
local locationModule = require("Module:Infobox road/locations/sandbox")
local parserModule = require("Module:Road data/parser")
local parser = parserModule.parser
local format = mw.ustring.format
local frame = mw.getCurrentFrame()

local function country(args)
	local state = args.state or args.province
	local country
	local countryModule = mw.loadData("Module:Road data/countrymask")
	local country = args.country or countryModule[state]
	
	return country
end

-- HEADER COLORS

function p.headerStyle(frame)
	local args = getArgs(frame)
	local deleted = args.decommissioned or args.deleted
	local uc = args.header_type == "under construction" or args.header_type == "const" or args.header_type == "uc"
	local minor = args.header_type == "minor"
	local hist = args.header_type == "hist" or args.header_type == "historic" or args.header_type == "historical" or args.header_type == "scenic"
	local color = parser(args, 'color')
	
	if uc then
		return "header-uc"
	elseif minor then
		return "header-minor"
	elseif deleted then
		return "header-deleted"
	elseif hist then
		return "header-hist"
	elseif color then
		return "header-" .. color
	elseif args.state or args.province or args.country then
		local country = country(args)
		return "header-" .. country or "header-default"
	else
		return "header-default"
	end
end

-- MAIN INFOBOX BELOW --

local function infobox(args)
	local statejct = args.state or args.province
	local countyjct = args.county
	local parentType = args.spur_type
	local parentRoute = args.spur_of
	local aux = parser(args, 'aux') or "Auxiliary route" or nil
	local photo = args.photo or args.image
	local width = args.photo_wide or args.image_width or "290px"
	local alt = args.photo_alt or args.image_alt or photo
	local lang = parser(args, 'lang') or args.lang
	local translation = args.translation or parser(args, 'translation')
	local law = parser(args, 'law') or nil
	local maint = args.maint or parser(args, 'maint') or nil
	local formed = args.established or args.formed or nil
	local deleted = args.decommissioned or args.deleted or nil
	local ntitle = parser(args, 'nbrowse') or nil
	local nlist = parser(args, 'nbrowselinks') or nil
	local title = parser(args, 'browse') or nil
	local list = parser(args, 'browselinks') or nil
	local previousRoute = args.previous_route
	local nextRoute = args.next_route
	local extended = args.browse
	
	local infobox_args = {
		['child'] = "yes"
	}
	
	if not translation then
		return nil
	else
		infobox_args['subheader1'] = frame:expandTemplate{ title = 'lang', args = { lang, translation }}
	end
	
	if country == 'AUS' then
		return nil
	else
		infobox_args['subheader2'] = args.alternate_name
	end
	
	local function map(args)
		if yesno (args.mapframe) == yes then
			return  frame:callParserFunction{ name = '#invoke', args = { 'Infobox mapframe', 'auto' } }
			else return mapModule.map(args)
		end
	end
	
	infobox_args['image'] = map(args)
	infobox_args['caption'] = args.map_notes
	
	local function photo(args)
		if photo == nil or country == "USA" then
			return nil
		else
			infobox_args['image2'] = string.format('[[File:%s|%s|alt=%s]]', photo, width, alt)
		end
	end

	infobox_args['caption2'] = args.photo_notes or args.image_notes
	
	infobox_args['data1'] = "Hello world!"
	
	--ROUTE INFORMATION --
	if maint ~= nil or args.section or args.spur_of or args["e-road"] or args.ahn or args.tahn or args.mrn or args.length_mi or args.length_km or args.time_period or args.formed or
		args.allocation or args.history or args.restrictions or args.tourist or args.status or args.margary then
			
		infobox_args['header2'] = "Route information"
	else
		return nil
	end
	
	local jct = frame:expandTemplate{
			title = 'jct', args = {
				state = statejct,
				country = country,
				county1 = countyjct,
				parentType,
				parentRoute,
				noshield1 = "yes"
			}
		}

	if not parentType and not parentRoute then
		return nil
	elseif type(aux) == "table" then
		infobox_args['data3'] = "Auxiliary route of " .. jct
	else
		infobox_args['data3'] = tostring(aux) .. " of " .. jct
	end
	
	if args["e-road"] then
		local eshield = args["e-road-shield"] or ''
		infobox_args['data4'] = eshield .. " Part of " .. args["e-road"]
	end
	if args.ahn then
		local ashield = args["ahn-shield"] or ''
		infobox_args['data5'] = ashield .. " Part of " .. args.ahn
	end
	if args.tahn then
		local tshield = args["tahn-shield"] or ''
		infobox_args['data6'] = tshield .. " Part of " .. args.tahn
	end
	if args.mrn then
		local mshield = args["mrn-shield"] or ''
		infobox_args['data7'] = mshield .. " Part of " .. args.mrn
	end
	
	infobox_args['label8'] = "Legal definition"
	infobox_args['data8'] = law
	infobox_args['label8'] = "Maintenance"
	
	if maint == "none" or nil then
		return nil
	else
		infobox_args['data8'] =  maint
	end
	
	if args.time_period then
		infobox_args['label9'] = "Established by" 
		infobox_args['data9'] = args.established_by
	end
	
	infobox_args['label12'] = "Length"
	infobox_args['data12'] = lengthModule._length
	infobox_args['label14'] = "Planned length"
	infobox_args['data14'] = lengthModule._length({desc = planned})
	infobox_args['label16'] = "Untolled length"
	infobox_args['data16'] = lengthModule._length({desc = free})
	infobox_args['label18'] = "Tolled length"
	infobox_args['data18'] = lengthModule._length({desc = tolled})
	infobox_args['label20'] = "Length under construction"
	infobox_args['data20'] = lengthModule._length({desc = constr})
	infobox_args['label22'] = "Overall length"
	infobox_args['data22'] = lengthModule._length({desc = overall})
	
	infobox_args['label25'] = "Status"
	infobox_args['data25'] = args["status"]
	infobox_args['label26'] = "Existed"
	if formed == nil then
		return nil
	elseif deleted == nil then
		infobox_args['data26'] = formed .. "–present"
	else
		infobox_args['data26'] =  formed .. "–" .. deleted
	end
	
	infobox_args['label27'] = "History"
	infobox_args['data27'] = args.history
	infobox_args['label28'] = "Time period"
	infobox_args['data28'] = args.time_period
	
	if args.time_period then
		infobox_args['label29'] = "Cultural significance"
		infobox_args['data29'] = args.significance
		infobox_args['label30'] = "Known for"
		infobox_args['data30'] = args.known_for
		infobox_args['label31'] = "Related routes"
		infobox_args['data31'] = args.related
	else
		infobox_args['label30'] = "Known for"
		infobox_args['data30'] = args.known_for
	end
	
	if country == "AUS" then
		infobox_args['label31'] = "[[Route number#Australia|Allocation]]"
	else
		infobox_args['label31'] = "Component<br>highways"
	end
	infobox_args['data31'] = args.allocation
	
	infobox_args['label32'] = "Tourist routes"
	infobox_args['data32'] = args.tourist
	infobox_args['label33'] = "Restrictions"
	infobox_args['data33'] = args.restrictions
	
	-- MAJOR INTERSETIONS --
	infobox_args['header35'] = sectionModule.main
	
	infobox_args['header36'] = sectionModule.section({num = 1}, args)
	infobox_args['header37'] = sectionModule.section({num = 2}, args)
	infobox_args['header38'] = sectionModule.section({num = 3}, args)
	infobox_args['header39'] = sectionModule.section({num = 4}, args)
	infobox_args['header40'] = sectionModule.section({num = 5}, args)
	infobox_args['header41'] = sectionModule.section({num = 6}, args)
	infobox_args['header42'] = sectionModule.section({num = 7}, args)
	infobox_args['header43'] = sectionModule.section({num = 8}, args)
	infobox_args['header44'] = sectionModule.section({num = 9}, args)
	infobox_args['header45'] = sectionModule.section({num = 10}, args)
	
	-- LOCATION --
	infobox_args['header50'] = locationModule.location
	
	-- HIGHWAY SYSTEM --
	if args.nobrowse or country == nil then
		return nil
	elseif country == "GBR" or country == "ENG" or country == "NIR" or country == "SCT" or country == "WLS" or country == "GGY" or country == "IMN" or country == "JEY" or
		country == "AIA" or country == "BMU" or country == "IOT" or country == "VGB" or country == "CYM" or country == "FLK" or country == "GIB" or country == "MSR" or
		country == "PCN" or country == "SHN" or country == "SGS" or country == "TCA" then
		
		infobox_args['header55'] = "Road network"
	else
		infobox_args['header55'] = "Highway system"
	end
	
	-- LINKS AND BROWSE SECTION --

	if args.nobrowse then
		return nil
	else
		if ntitle ~= nil then
			infobox_args['rowclass60'] = "hlist"
			infobox_args['rowstyle60'] = "font-weight: bold;"
			infobox_args['data60'] = ntitle
		end
		if nlist ~= nil then
			infobox_args['rowclass61'] = "hlist"
			infobox_args['data61'] = nist
		end
		if title ~= nil then
			infobox_args['rowclass62'] = "hlist"
			infobox_args['rowstyle62'] = "font-weight: bold;"
			infobox_args['data62'] = title
		end
		if list ~= nil then
			infobox_args['rowclass62'] = "hlist"
			infobox_args['data62'] = list
		end
	end
	
	infobox_args['data63'] = args.system
	
	if args.nobrowse then
		return nil
	else
		if previousRoute or nextRoute then
			infobox_args['rowstyle65'] = "width:100%; background:none; border-collapse:collapse; display:inline-table;"
			local boxModule = require "Module:Road data/browse/sandbox" -- remove "/sandbox" when live!
			infobox_args['data65'] = boxModule._browse(args)
		end
	end
	
	if args.nobrowse or extended == nil then
		return nil 
	else
		infobox_args['rowstyle67'] = "width:100%; background:none; border-collapse:collapse; display:inline-table;"
		infobox_args['data67'] = extended
	end
	
	infobox_args['data70'] = args.nhrp or args.embedded
	infobox_args['subbox'] = yesno(args.child)
	
	local infoboxModule = require 'Module:Infobox'
    return infoboxModule.infobox(infobox_args)
		
end

function p.infobox(frame)
	local args = getArgs(frame)
	return infobox(args)
end

return p