🇮🇷 Iran Proxy | https://www.wikipedia.org/wiki/Module:User:MEN_KISSING/redirectThing
Jump to content

Module:User:MEN KISSING/redirectThing

From Wikipedia, the free encyclopedia
local p = {}

-- Given a prefix and digits, outputs prefix .. digits, but with each digit being a link to the entire string up to and including that digit.
-- Ex: "3.1", "415" outputs "3.1415", where the digits 4, 1, and 5 at the end each link to 3.14, 3.141, and 3.1415.

-- Warning: the amount of bytes produced grows quadratically. The maximum of 255 will result in ~35 kilobytes when expanded. Not sure if that is acceptable.

function p.decimalRedirects(frame)
	local prefix = frame.args[1]
	local digits = frame.args[2]
	local t = prefix
	for i = 1, string.len(digits) do
		t = t .. "[[" .. prefix .. string.sub(digits, 1, i) .. "|" .. string.sub(digits, i, i) .. "]]"
	end
	return t
end

-- Same sort of thing, except it displays it in a neatly formatted 32x8 square.

function p.decimalRedirectSquare(frame)
	local prefix = frame.args[1]
	local digits = frame.args[2]
	local preflen = string.len(prefix)
	local total = prefix .. digits
	local totallen = string.len(total)
	local res = "'''"
	for y = 1, 8 do
		local upto1 = (y-1)*32 + 1
		local part1 = string.sub(total, 1, upto1 - 1)
		local thisline = "<code>"
		for x = 1, 32 do
			local upto2 = upto1 - 1 + x
			if upto2 <= preflen then
				thisline = thisline .. string.sub(total, upto2, upto2)
			elseif upto2 > totallen then
				thisline = thisline .. " "
			else
				thisline = thisline .. ("[[" .. part1 .. string.sub(total, upto1, upto2) .. "|" .. string.sub(total, upto2, upto2) .. "]]")
			end
		end
		thisline = thisline .. "</code>" .. ((y == 8 and "'''") or "<br>")
		res = res .. thisline
	end
	return res
end
return p