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 Rschen7754 (talk | contribs) at 09:20, 13 January 2014 (Protected Module:Road data/parser/hooks: Highly visible template ([Edit=Allow only autoconfirmed users] (indefinite) [Move=Allow only autoconfirmed users] (indefinite))). 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 pattern = "%%(%w+)%%"
	local pageName = parameters[1] or parameters[args[parameters.arg or "route"]]
	pageName = pageName and mw.text.trim(mw.ustring.gsub(pageName, pattern, args))
	if pageName and mw.title.makeTitle("Media", pageName).fileExists then
		return pageName
	else
		return parameters.default	-- assumed to exist
	end
end

return p