Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

// request.cf · coarse context

A page that knows where it met you.

Only coarse request metadata is shown. This demo does not display or persist visitor IP addresses.

Country
US
Cloudflare location
CMH
Connection
HTTP/2
Language
Not provided

Ray ID: a228c9855c108043

Jump to content

Module:Sandbox/Ahecht

From Wikipedia, the free encyclopedia

local p = {}

local dots = ...

local out_mt = {	-- Append to array by calling it
	__call = function (t, v) t[#t+1] = v end,
	__tostring = function(t) return table.concat(t) end
}

function p.main(frame)
	local output = setmetatable({}, out_mt)
	output('frame: ' .. type(frame) .. ' ')
	if type(frame) == 'table' then
		output(mw.dumpObject(frame))
	end
	output('<br />frame:getParent() ' .. type(frame:getParent()) .. ' ')
	if type(frame:getParent()) == 'table' then
		output(mw.dumpObject(frame:getParent()))
	end

	if frame.args['test'] == 0 then
		output('<br />0 the number')
	elseif frame.args['test'] == '0' then
		output('<br />0 the character')
	end
	
	local thisframe = mw.getCurrentFrame()
	if thisframe then
		output("<br />mw.getCurrentFrame():getTitle(): ")
		output(thisframe:getTitle())
		thisframe = thisframe:getParent()
		if thisframe then
			output("<br />mw.getCurrentFrame():getParent():getTitle(): ")
			output(thisframe:getTitle())
			thisframe = thisframe:getParent()
			if thisframe then
				output("<br />mw.getCurrentFrame():getParent():getParent():getTitle(): ")
				output(thisframe:getTitle())
			end
		end
	end
	return output
end

function p.isnumeric(frame)
	local s = frame.args[1] or frame:getParent().args[1]
	local boolean = (frame.args.boolean or frame:getParent().args.boolean) == 'true'
	if type(s) == 'string' and mw.getContentLanguage():parseFormattedNumber( s ) then
		return boolean and 1 or s
	end
	return boolean and 0 or ''
end

local function error(_, key)
	return "Error! Missing function " .. key
end

local metatable = {['__index'] = error}

setmetatable(p, metatable)

function p.dots()
	return dots
end

function p.prefix(frame)
	local args = {}
	for k,v in pairs(frame.args) do
		if k ~= '_prefix' and k ~= '_template' then
			table.insert(args, '| ' .. (frame.args['_prefix'] or '') .. k .. " = " .. v)
		end
	end
	return table.concat(args, '\n')
end

return setmetatable(p, {__index =
	function(_, key)														-- this anonymous function called as function(TABLE, KEY)
		return function (frame) return error (frame, key) end;				-- which in turn returns a function that calls cite() with the KEY name
	end
})