Jump to content

Module:User:Morwen/validator

From Wikipedia, the free encyclopedia
local p = {}

local getArgs = require('Module:Arguments').getArgs

local function extractKey(arg)
	-- theoretically this should be a full wikitext->plain text renderer, but
	-- apparently this doesn't exist at this level.	
	local initialPatterns = {"^%s+", "^%[%[", "^''"}
	local endingPatterns = {"%s+$", "%]%]$", "''$"}

	while true do
		local old = arg
		for _, pattern in ipairs(initialPatterns) do
			arg = arg:gsub(pattern, "")
		end
		for _, pattern in ipairs(endingPatterns) do
			arg = arg:gsub(pattern, "")
		end
		if old == arg then
			break
		end
	end
	
	return arg
end

function p._render(args)
	local text = args[1]
	local compare = extractKey(text)
	local i = 2
	while args[i] do
		if compare == args[i] then
			return text
		end
		text = text .. "<br />comparing " .. compare .. "/" .. args[i]
		i = i + 1
	end
	text = text .. "<br />[[Wikipedia articles triggering test schema validator error]]"
	return text
end

function p.render(frame)
    local args = getArgs(frame, {
        wrappers = 'User:Morwen/validator/template'
    })

    return p._render(args)
end

return p