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 22:02, 11 February 2022 (`hidden` param). 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
local isIpOrRange = require('Module:IPAddress')._isIpOrRange
local yesno = require('Module:Yesno')

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

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

function toolEIA(args)
	local url = "https://tools.wmflabs.org/sigma/editorinteract.py?users="
		.. mw.uri.encode(args.master)
	for i, sock in ipairs(args) do
		url = url .. "&users=" .. mw.uri.encode(sock)
	end
	return "[" .. url .. " Editor interaction utility]"
end

function toolTimeline(args)
	local url = "https://tools.wmflabs.org/interaction-timeline?wiki=enwiki&user="
		.. mw.uri.encode(args.master) .. "&user=" .. mw.uri.encode(args[1] or "")
	return "[" .. url .. " Interaction Timeline]"
end

function toolCompare(args)
	local url = "https://tools.wmflabs.org/betacommand-dev/UserCompare/"
		.. mw.uri.encode(args.master)
	return "[" .. url .. " User compare report]"
end

function p._main(frame, args)
	local socklist = mw.html.create('ul')
	if yesno(args.hidden) then
		socklist:attr('style', 'display:none;')
	end
	if args[1] then
		for i, sock in ipairs(args) do
			if args.master ~= sock or not yesno(args.remove_master or 'no') then
				socklist:node(listEntry(
					frame,
					args.account_template or args.template or 'checkuser',
					args.IP_template or args.template or 'checkip',
					sock,
					args.master)
				)
	end end end
	if yesno(args.tools_link) then
		local tools = mw.html.create('li')
		tools
			:attr('class', 'plainlinks')
			:wikitext("<b>Tools</b>: ")
			:node(toolEIA(args))
			:wikitext(" • ")
			:node(toolTimeline(args))
			:wikitext(" • ")
			:node(toolCompare(args))
			:wikitext(" <small>''Auto-generated every hour.''</small>")
		socklist:node(tools)
	end
	return socklist
end

return p