Jump to content

Module:Road data/parser/hooks

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mxn (talk | contribs) at 05:16, 13 January 2014 (Hook to avoid red image links for sparse route shield types like Commons:Category:Diagrams of Ohio township route markers). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

function p.split(parameters, args)
	local route = tonumber(args.route) or 0
	if route < parameters.split then
		return parameters.below
	else
		return parameters.above
	end
end

function p.between(parameters, args)
	local lower = parameters.lower
	local upper = parameters.upper
	local route = tonumber(args.route) or 0
	if route < lower or route >= upper then
		return parameters.no
	else
		return parameters.yes
	end
end

-- Return a file name in the argument table based on the value of arg in that
-- table, or the default file name if an existent file name is not found in the
-- table.
function p.fileexists(parameters, args)
	local arg = args[parameters.arg or "route"]
	local pageName = parameters[arg]
	if pageName and mw.title.makeTitle("Media", pageName).fileExists then
		return pageName
	else
		return parameters.default	-- assumed to exist
	end
end

return p