Documentation for this module may be created at Module:Sandbox/Nardog/12/doc

local p = {}

function p.main(frame)
	if not frame.args[1] then
		return nil
	end
	local lang = mw.getContentLanguage()
	local t = { '{|class="wikitable sortable"\n!User!!R!!Blocked!!Admin!!Reason\n' }
	for v in mw.text.gsplit(frame.args[1], '%s*\n%s*') do
		if v ~= '' then
			local date = mw.ustring.match(v, '%d%d:%d%d,%s%d%d?%s%u%l+%s%d%d%d%d')
			local admin = mw.ustring.match(v, '%d%d%d%d%s(.-)%stalk%scontribs%s')
			local user = mw.ustring.match(v, 'talk%scontribs%sblocked%s(.-)%stalk')
				or mw.ustring.match(v, 'changed%sblock%ssettings%sfor%s(.-)%stalk')
				or mw.ustring.match(v, '"User:(.-)@global"')
				or mw.ustring.match(v, '/wiki/Special:[^/]-/(.+)')
				or mw.ustring.match(v, '[&%?]user=([^&#]+)')
				or mw.ustring.match(v, '%x+:%x-:[%x:]*/?%d*')
				or mw.ustring.match(v, '%d+%.%d+%.%d+%.%d+/?%d*')
				or mw.ustring.match(v, '^[^#<>%[%]|{}/@:]+$')
			local reason = mw.ustring.match(v, '%)%s%((.+)%)')
			if user then
				local template = 'checkuser'
				local red = ''
				if user:find('^%x+:%x-:[%x:]*/?%d*$') or user:find('^%d+%.%d+%.%d+%.%d+/?%d*$') then
					template = 'checkip'
				else
					user = mw.uri.decode(user, 'WIKI')
					red = p.r(user, 13)
				end
				user = frame:expandTemplate{ title = template, args = { user } }
				date = date and 'data-sort-type=' .. lang:formatDate('U', date) .. '|' .. date or ''
				admin = admin or ''
				reason = reason or ''
				table.insert(t, string.format('|-\n|%s||%s||%s||%s||%s\n', user, red, date, admin, reason))
			end
		end
	end
	table.insert(t, '|}')
	return table.concat(t)
end

function p.r(s, n)
	local t = {}
	for char in mw.ustring.gmatch(s, '.') do
		local cp = mw.ustring.codepoint(char)
		local dec
		if (cp >= 65 and cp < 77) or (cp >= 97 and cp <= 109) then
			dec = cp + n
		elseif (cp >= 78 and cp <= 90) or (cp >= 110 and cp <= 122) then
			dec = cp - n
		end
		dec = dec and mw.ustring.char(dec)
		table.insert(t, dec or char)
	end
	return table.concat(t)
end

return p