FANDOM


-- This module implements {{HK-MTR icon}}, {{HK-MTR colour}}, {{HK-MTR lines}} and {{HK-MTR box}}.
 
local getArgs = require('Module:Arguments').getArgs
local data = mw.loadData('Module:MTR/data')
 
local p = {}
 
local function makeInvokeFunction(funcName)
	-- makes a function that can be returned from #invoke, using
	-- [[Module:Arguments]].
	return function (frame)
		local args = getArgs(frame, {parentOnly = true})
		return p[funcName](args)
	end
end
 
local function getColour(code)
	return data.colours[code] or '000'
end
 
p.colourbyname = makeInvokeFunction('_colourbyname')
 
function p._colorbyname(args)
	local code = args[1] or ''
	code = code:upper()
	return getColour(code)
end
 
local function getLink(code)
	local name = data.names[code]
	link = name
	if data.needs_dab[name] then
		link = link .. ' (MTR)'
	elseif data.lr[name] then
		link = 'MTR Light Rail Route ' .. link
	end
	return link
end
 
local function invalid(code)
	return '<strong class="error">Error: "' .. tostring(code) .. '" is not a valid code.</strong>'
end
 
p.link = makeInvokeFunction('_link')
 
function p._link(args)
	-- Retrieve arguments
	local code = args[1] or ''
	code = code:upper() -- Convert to upper case
	if not code then
		return invalid(code)
	end
	return getLink(code)
end
 
p.icon = makeInvokeFunction('_icon')
 
function p._icon(args)
	local code = args[1] or ''
	local link = args[2] or args.link
	local text = args[3] or args.text
	code = code:upper()
	local colour = getColour(code)
	link = link or getLink(code)
	local name = data.names[code]
	if not name then
		return invalid(code)
	end
 
	-- Format the text
	if text == noint then
		text = name
	else
		text = text or 'Interchange station for the ' .. name
 	end
	-- Build the link
	return '[[' .. link .. '|<span title="' .. text .. '" style="colour:#' .. colour .. ';font-size:120%">█</span>]]'
end
 
p.line = makeInvokeFunction('_line')
 
function p._line(args)
	local code = args[1] or ''
	local link = args[2] or args.link
	local text = args[3] or args.text
	code = code:upper()
	link = link or getLink(code)
	local name = data.names[code]
	if not name then
		return invalid(code)
	end
	text = text or name
 
	return '[[' .. link .. '|' .. text .. ']]'
end
 
p.box = makeInvokeFunction('_box')
 
function p._box(args)
	local code = args[1] or ''
	local link = args[2] or args.link
	local text = args[3] or args.text
	code = code:upper()
	local colour = getColour(code)
	link = link or getLink(code)
	local name = data.names[code]
	if not name then
		return invalid(code)
	end
	text = text or name
 
	return '[[' .. link .. '|<span title="' .. link .. '" style="colour:#' .. colour .. ';font-size:120%">█</span>&nbsp;' .. text .. ']]'
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.