Module:Infobox road

local p = {}local getArgs = require('Module:Arguments').getArgslocal util = require("Module:Road data/util")local yesno = require('Module:Yesno')local langModule = require('Module:Lang')local routeModule = require("Module:Infobox road/route")local parserModule = require("Module:Road data/parser")local parser = parserModule.parserlocal format = mw.ustring.formatlocal frame = mw.getCurrentFrame()local function country(args)local state = args.state or args.provincelocal countrylocal countryModule = mw.loadData("Module:Road data/countrymask")local country = args.country or countryModule[state]return countryend-- HEADER COLORSfunction p.headerStyle(frame)local args = getArgs(frame)local header if args.header_type == nil thenheader = args.header_typeelseheader = string.lower(args.header_type)endlocal deleted = args.decommissioned or args.deleted or header == "former"local uc = header == "under construction" or header == "const" or header == "uc"local minor = header == "minor"local hist = header == "hist" or header == "historic" or header == "historical" or header == "scenic"local color = parser(args, 'color') or args['header_color']local freeway = header == "freeway"if freeway thenreturn "header-MUTCDblue"elseif uc thenreturn "header-uc"elseif minor thenreturn "header-minor"elseif deleted and header == 'hist' or deleted and color == 'hist' thenreturn "header-deleted-hist"elseif deleted thenreturn "header-deleted"elseif hist thenreturn "header-hist"elseif color thenreturn "header-" .. colorelseif args.state or args.province or args.country thenlocal country = country(args)return "header-" .. country or "header-default"elsereturn "header-default"endend-- SECOND IMAGElocal function photo(args)local country = country(args)local photo = args.photo or args.imagelocal width = args.photo_wide or args.image_width or "290px"local alt = args.photo_alt or args.image_alt or photoif photo == nil thenreturn nilelseif country == "USA" thenreturn nilelse return string.format('[[File:%s|%s|alt=%s]]', photo, width, alt)endendfunction p.photo(frame)local args = getArgs(frame)return photo(args)end-- TRANSLATIONlocal function translate(args, lang)local lang = parser(args, 'lang') or args.lang or 'none'local translation = args.translation or parser(args, 'translation') or ''if country(args) == "PAK" and translation ~= '' thenlocal route = args.routeif route ~= nil thenlocal arabicModule = require( "Module:Convert to eastern arabic numerals" )local arabic = arabicModule._convert({route})local translated = string.gsub( translation, route, arabic)return frame:expandTemplate{title = 'Nastaliq', args = {translated}}elsereturn frame:expandTemplate{title = 'Nastaliq', args = {translation}}endelseif translation ~= '' and lang == 'none' thenreturn translationelseif country(args) == "CHN" and args.type == "Expwy" thenlocal trans = require( "Module:Road data/masks/CHN/Expwy translations" )local route = args.routereturn langModule._lang({lang, trans[route]})elseif country(args) == "HUN" thenlocal nominal = require( "Module:Road data/masks/HUN" )local routeNumlocal leadingif string.len(args.route) > 2 thenrouteNum = string.match(args.route, "%d%d$", 0)leading = string.match(args.route, "(%d*)%d%d$", 0)elserouteNum = args.routeleading = ''endif args.type == "M" thenreturn langModule._lang({"hu", "M" .. leading .. nominal[routeNum] .. " autópálya"})elseif args.type == "Mb" thenreturn langModule._lang({"hu", "M" .. leading .. nominal[routeNum] .. " autóút"})elseif args.type == "MR" thenreturn langModule._lang({"hu", leading .. nominal[routeNum] .. " főút"})elseif args.type == "Mb" thenreturn langModule._lang({"hu", leading .. nominal[routeNum] .. " közút"})endelseif lang == "ar" and translation ~= '' thenlocal route = args.routelocal arabicModule = require( "Module:Convert to eastern arabic numerals" )local arabic = arabicModule._convert({route})local translated = string.gsub( translation, route, arabic)return langModule._lang({lang, translated})elseif translation ~= '' and lang ~= 'none' thenreturn langModule._lang({lang, translation})elsereturn nilendendfunction p.translate(frame)local pframe = frame:getParent()    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself    local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template        local lang = config.langreturn translate(args, lang)end-- MAINTAINED BYlocal function maint(args)local maint = args.maint or parser(args, 'maint') or ''if maint == "none" or maint == '' thenreturn nilelsereturn "Maintained by " .. maintendendfunction p.maint(frame)local args = getArgs(frame)return maint(args)end-- DEFINED BY LAWlocal function law(args)local law = parser(args, 'law') or ''if args.section == '' thenreturn nilelsereturn "Defined by " .. lawendendfunction p.law(frame)local args = getArgs(frame)return law(args)end-- EXISTEDfunction p._existed(args)local formed = args.established or args.formed or ''local deleted = args.decommissioned or args.deleted or ''if formed == '' thenreturn nilelseif deleted == '' thenreturn formed .. "–present"elsereturn formed .. "–" .. deletedendendfunction p.existed(frame)local args = getArgs(frame)return p._existed(args)end-- TIME PERIODlocal function period(args)local infobox_args = {}infobox_args['bodystyle'] = 'display:inline-table;'infobox_args['child'] = 'yes'infobox_args['decat'] = 'yes'infobox_args['label1'] = "Time period"infobox_args['data1'] = args.time_periodif args.time_period theninfobox_args['label2'] = "Cultural significance"infobox_args['data2'] = args.significanceinfobox_args['label3'] = "Known for"infobox_args['data3'] = args.known_forinfobox_args['label4'] = "Related routes"infobox_args['data4'] = args.relatedelseinfobox_args['label3'] = "Known for"infobox_args['data3'] = args.known_forendreturn frame:expandTemplate ({title='Infobox', args = infobox_args})endlocal function period_params(args)if args.time_period or args.known_for thenreturn trueelsereturn falseendendfunction p.period(frame)local args = getArgs(frame)if period_params(args) == false thenreturn nilelsereturn period(args)endend-- ALLOCATIONlocal function allocation(args)local country = country(args)if country == "AUS" thenreturn "[[Route number#Australia|Allocation]]"else return "Component<br>highways"endendfunction p.allocation(frame)local args = getArgs(frame)return allocation(args)end-- SPUR OFlocal function spurOf(args)local state = args.state or args.provincelocal country = args.countrylocal county = args.countylocal parentType = args.spur_typelocal parentRoute = args.spur_oflocal aux = parser(args, 'aux') or "Auxiliary route" or nillocal jct = frame:expandTemplate{title = 'jct', args = {state = state,country = country,county1 = county,parentType,parentRoute,noshield1 = "yes"}}if not parentType and not parentRoute thenreturn nilelseif type(aux) == "table" thenreturn "Auxiliary route of " .. jctelse return tostring(aux) .. " of " .. jctendendfunction p.spurOf(frame)local args = getArgs(frame)return spurOf(args)end-- PART OFlocal function partOf(args)if args["e-road"] or args.ahn or args.tahn or args.mrn thenlocal infobox_args = {}infobox_args['bodystyle'] = 'display:inline-table;'infobox_args['child'] = 'yes'infobox_args['decat'] = 'yes'if args["e-road"] thenlocal eshield = args["e-road-shield"] or ''infobox_args['data1'] = eshield .. " Part of " .. args["e-road"]endif args.ahn thenlocal ashield = args["ahn-shield"] or ''infobox_args['data2'] = ashield .. " Part of " .. args.ahnendif args.tahn thenlocal tshield = args["tahn-shield"] or ''infobox_args['data3'] = tshield .. " Part of " .. args.tahnendif args.mrn thenlocal mshield = args["mrn-shield"] or ''infobox_args['data4'] = mshield .. " Part of " .. args.mrnendreturn frame:expandTemplate ({title='Infobox', args = infobox_args})else return nilendendfunction p.partOf(frame)local args = getArgs(frame)return partOf(args)end--BROWSE LINKSlocal function browse(args)if args.nobrowse then return nil endlocal previousRoute = args.previous_routelocal nextRoute = args.next_routeif previousRoute or nextRoute thenlocal box = mw.html.create('table'):cssText("width:100%; background:none; border-collapse:collapse; display:inline-table;")local boxModule = require "Module:Road data/browse"local primary = boxModule._browse(args)box:wikitext(primary)return tostring(box)endendfunction p.browse(frame)local args = getArgs(frame)return browse(args)endlocal function extended(args)local extended = args.browseif args.nobrowse or extended == nil thenreturn nil elselocal box = mw.html.create('table'):cssText("width:100%; background:none; border-collapse:collapse; display:inline-table;")box:wikitext(extended)return tostring(box)endendfunction p.extended(frame)local args = getArgs(frame)return extended(args)end-- HIGHWAY SYSTEM LINKSlocal function system(args)if args.system1 thenlocal infobox_args = {['child'] = "yes",['decat'] = "yes",['bodystyle'] = "border-collapse:collapse;"}local i = 1while (1) dolocal systemClassn = "class" .. ilocal systemDatan = "data" .. ilocal systemArgn = args['system' .. i]infobox_args[systemClassn] = "hlist"infobox_args[systemDatan] = systemArgnif i == 10 thenbreakelsei = i + 1endendreturn frame:expandTemplate ({title='Infobox', args = infobox_args})endendfunction p.system(frame)local args = getArgs(frame)return system(args)end-- ROUTE INFORMATION HEADERlocal function info(args)local maint = maint(args)local law = law(args)local period = period_params(args)local existed = args.established or args.formed or nillocal spur = args.spur_type or args.spur_of or nillocal part = partOf(args)if period == true or spur ~= nil or part ~= nil or existed ~= nil or maint ~= nil or args.section or args.length_mi or args.length_km or args.allocation or args.history or args.restrictions or args.tourist or args.status or args.margary thenreturn "Route information"elsereturn nilendendfunction p.info(frame)local args = getArgs(frame)return info(args)end-- HIGHWAY SYSTEM HEADERlocal function highwaySystem(args)if args.nobrowse then return nil endlocal country = country(args) or args.countriesif country == nil thenreturn nilelseif country == "GBR" or country == "ENG" or country == "NIR" or country == "SCT" or country == "WLS" orcountry == "GGY" or country == "IMN" or country == "JEY" or country == "AIA" or country == "BMU" orcountry == "IOT" or country == "VGB" or country == "CYM" or country == "FLK" or country == "GIB" orcountry == "MSR" or country == "PCN" or country == "SHN" or country == "SGS" or country == "TCA" thenreturn "Road network"else return "Highway system"endendfunction p.highwaySystem(frame)local args = getArgs(frame)return highwaySystem(args)endreturn p