Jump to content

Module:Other people/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Nihiltres (talk | contribs) at 00:58, 16 May 2016 (Have to make sure table downshift iteration runs at least once, on args[2], to keep things working.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local mOtheruses = require('Module:Other uses')
local mArguments = require('Module:Arguments')
local p = {}

function p.otherPeople (frame)
	--Get arguments and simply compress the array while preserving named args
	--and gaps below 2
	local origArgs = mArguments.getArgs(frame)
	local args = {}
	for k, v in pairs(origArgs) do
		if type(k) == 'number' and k > 1 then
			args[math.max(table.maxn(args) + 1, 2)] = v
		else
			args[k] = v
		end
	end
	-- Assemble arguments and return
	local title = args[1] or mw.title.getCurrentTitle().text
	local options = {
		title = title,
		defaultPage = args[2],
		otherText = (args[2] and not args[1] and 'people with the same name') or
			string.format('people %s %s', args.named or 'named', title)
	}
	-- Don't pass args[1] through as a target page. Manual downshift because Lua
	-- expectation of sequences means table.remove() doesn't work
	for i = 2, math.max(table.maxn(args), 2) do
		args[i - 1] = args[i]
		args[i] = nil
	end
	return mOtheruses._otheruses(args, options)
end

return p