Edge Rewrite
// 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: a21f317dba451de6

Jump to content

Module:Infobox sort

From Wikipedia, the free encyclopedia
local p = {}

function p.asc(frame)
    local list = {}
    
	for key,value in pairs(frame.args) do
		-- Remove newlines
		local stripped = mw.text.trim((string.gsub(value, "\n", "")))
		
		if stripped:match("%S") ~= nil then
		    table.insert(list, stripped)
		end
	end
	
    table.sort( list, function (a, b)
    	local indexA = a:find("%%")
    	local indexB = b:find("%%")
    	local numberA = tonumber(a:sub(1, indexA - 1))
    	local numberB = tonumber(b:sub(1, indexB - 1))
    	return numberA < numberB 
    end )
    
    return mw.text.trim(table.concat( list, "<br>" ))
end

function p.desc(frame)
	local list = {}
	
	for key,value in pairs(frame.args) do
		-- Remove newlines
		local stripped = mw.text.trim((string.gsub(value, "\n", "")))
		
		if stripped:match("%S") ~= nil then
			table.insert(list, stripped)
		end
	end
	
    table.sort( list, function (a, b)
    	local indexA = a:find("%%")
    	local indexB = b:find("%%")
    	local numberA = tonumber(a:sub(1, indexA - 1))
    	local numberB = tonumber(b:sub(1, indexB - 1))
    	return numberA > numberB 
    end )
    
    return mw.text.trim(table.concat( list, "<br>" ))
end

return p