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 18:16, 3 February 2022 (WIP). 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 toolEIA(args)
	local span = mw.html.create('span')
	span:attr('class', 'plainlinks')
	local a = mw.html.create('a')
	local url = "https://tools.wmflabs.org/sigma/editorinteract.py?users=" .. args.master
	for i, sock in ipairs(args) do
		url = url .. "&users" .. mw.uri.encode(sock)
	end
	a
		:attr('href', url)
		:wikitext("Editor interaction utility")
	span:node(a)
	return span
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