Jump to content

Module:Sock list

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Tamzin (talk | contribs) at 17:55, 3 February 2022 (working prototype of arbitrary-length sock list. isIPOrRange © User:Chlod). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}
local getArgs = require('Module:Arguments').getArgs

function p.main(frame)
	local args = getArgs(frame)
	return p._main(frame, args)
end

function isIpOrRange(s)
    local modip = require('Module:IP')
    local success, ip = pcall(modip.IPAddress.new, s)
    if success then
        return 'ip'
    end
    success, ip = pcall(modip.Subnet.new, s)
    if success then
        return 'range'
    end
    return nil
end

function listEntry(frame, sock, master)
	local template = isIpOrRange(sock) and "checkip" or "checkuser"
	local li = mw.html.create('li')
	li:wikitext(frame:expandTemplate{title=template, args={sock, ['master name']=master}})
	return li
end

function p._main(frame, args)
	local ul = mw.html.create('ul')
	for i, sock in ipairs(args) do
		ul:node(listEntry(frame, sock, args.master))
	end
	return ul
end

return p