Jump to content

Module:Redirect-multi

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Nihiltres (talk | contribs) at 20:32, 12 May 2016 (If only getArgs were friendlier…). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local mRedirectHatnote = require('Module:Redirect hatnote')
local mArguments = require('Module:Arguments')
local p = {}

function p.redirectMulti (frame)
	local args = mArguments.getArgs(frame)
	--Get maxArg manually because getArgs and table.maxn aren't friends
	local maxArg = 0
	for k, v in pairs(args) do
		if type(k) == 'number' and k > maxArg then maxArg = k end
	end
	--Get number of redirects then remove it from the args table
	local numRedirects = args[1] or 1
	--Manual downshift of arguments; not using table.remove because getArgs is
	--gnarly and it's not a sequence anyway
	for i = 2, maxArg do args[i - 1] = args[i] end
	local options = {selfref = args.selfref}
	return mRedirectHatnote._redirect(args, numRedirects, options)
end

return p