Module:Global lock: Difference between revisions

From WickedGov Meta-Wiki
Jump to navigation Jump to search
update CA reason due to form design change and add lock all reason (script required)
 
customize for wickedgov
 
(One intermediate revision by the same user not shown)
Line 93: Line 93:
' ',
' ',
'(',
'(',
'[[' .. interwiki .. 'User talk:' .. username .. '|' ..  hide('talk') .. ']]',
'[[' .. interwiki .. 'User talk:' .. username .. '|' ..  hide('t') .. ']]',
middot,
middot,
'[[' .. interwiki .. 'Special:Contributions/' .. username .. '|' .. hide('contribs') .. ']]',
'[[' .. interwiki .. 'Special:Contributions/' .. username .. '|' .. hide('c') .. ']]',
middot,
middot,
'[[' .. interwiki .. 'Special:Block/' .. username .. '|' .. hide('block') .. ']]',
'[[' .. interwiki .. 'Special:Block/' .. username .. '|' .. hide('lblock') .. ']]',
middot,
(
IpOrRange == 'range' and
link(
'xtools:globalcontribs/ipr-' .. username,
nil,
'xwiki-contribs',
'XTools'
) or
link(
'toolforge:guc',
{
user = username,
blocks = true
},
'xwiki-contribs',
'GUC by wiki'
) ..
middot ..
link(
'toolforge:guc',
{
user = username,
by = 'date',
blocks = true
},
'xwiki-date',
'GUC by date'
) ..
' ' ..
'<sup>(' ..
link('xtools:globalcontribs/' .. username, nil, 'alt', 'XTools') ..
')</sup>'
),
middot,
middot,
link(
link(
Line 155: Line 121:
'global block'
'global block'
),
),
middot,
link('toolforge:meta/stalktoy/' .. username, nil, 'ST', 'Stalk toy'),
middot,
middot,
extlink(
extlink(
tostring(mw.uri.new('//login.wikimedia.org/w/index.php'):extend({
tostring(mw.uri.new('//login.wickedgov.org/w/index.php'):extend({
title = 'Special:CheckUser',
title = 'Special:CheckUser',
user = username,
user = username,
Line 165: Line 129:
reason = reason,
reason = reason,
})),
})),
'<b>lwcheckuser</b>',
'lwcu',
'Login Wiki CheckUser'
'Login Wiki CheckUser'
),
),

Latest revision as of 02:47, 22 February 2025

Documentation for this module may be created at Module:Global lock/doc

local p = {}

local getArgs = require('Module:Arguments').getArgs
local isIpOrRange = require('Module:IPAddress').isIpOrRange

local middot = '&nbsp;•&#32;'
local reason = 'per [[:m:Special:Redirect/page/' .. mw.title.getCurrentTitle().id .. '|request]]';

local extlink = function(url, text, title)
	return '<span title="' ..  title .. '">[' .. tostring(url) .. (text and ' ' .. text or '') .. ']</span>'
end
local link = function(page, param, text, title)
	return extlink(mw.uri.fullUrl(page, param), text, title)
end

function p.multi_lock(frame)
	local args = getArgs(frame)
	local text = ''
	local users = {}
	local params = {}
	local wpTarget = ''
	
	for k, v in pairs(args) do
		if v and (v ~= '') then
			if type(k) == 'number' then
				users[k] = mw.text.trim(v)
			else
				params[k] = mw.text.trim(v)
			end
		end
	end
	
	if #users == 0 then
		error('You must specify at least one user', 0)
	end
	
	for k, v in pairs(users) do
		wpTarget = wpTarget .. v .. '\n'
		params[1] = v
		text = text .. '<li>' .. p._lock_hide(params) .. '</li>'
	end
	
	wpTarget = mw.text.trim(wpTarget)
	
	local link = tostring(mw.uri.fullUrl('Special:MultiLock', {wpReason=reason, wpTarget=wpTarget}));  -- reason for scripts that support it
	
	text = '<b class="plainlinks tpl-permalink-reason" data-linktype="MultiLock">[' .. link .. ' Lock all]:</b><ul>' .. text .. '</ul>'
	
	return text
end

function p.lock_hide(frame)
	local args = getArgs(frame, {
		trim = true,
		removeBlanks = true
	})
	return p._lock_hide({
		[1] = args[1],
		[2] = args[2],
		hidename = args['hidename']
	})
end

-- For attribution: [[Template:LockHide]]
function p._lock_hide(args)
	local username = args[1] or 'Example user'
	local interwiki = args[2] or ''
	local hidename = not not args['hidename'] or false
	local hide = function(text, fallback)
		return hidename and '<abbr title="name hidden">' .. (
			fallback and '<i>' .. text .. '</i>' or text
		) .. '</abbr>' or (fallback or text)
	end
	
	local srga = mw.title.getCurrentTitle():isSubpageOf(
		mw.title.new('Steward requests/Global')
	)
	if srga then
		return '[[Special:CentralAuth/' .. username .. '|' .. (
			hide('name hidden', username)
		) .. ']]'
	end
	
	local IpOrRange = isIpOrRange({args = {username}});
	
	local text = {
		'<span class="plainlinks tpl-permalink-reason">',
		extlink(
			mw.title.new(interwiki .. 'User:' .. username):fullUrl(),
			hidename and '<i>name hidden</i>' or username,
			hidename and 'name hidden' or interwiki .. 'User:' .. username
		),
		'&nbsp;',
		'(',
		'[[' .. interwiki .. 'User talk:' .. username .. '|' ..  hide('t') .. ']]',
		middot,
		'[[' .. interwiki .. 'Special:Contributions/' .. username .. '|' .. hide('c') .. ']]',
		middot,
		'[[' .. interwiki .. 'Special:Block/' .. username .. '|' .. hide('lblock') .. ']]',
		middot,
		link(
			'Special:CentralAuth',
			{
				target = username,
				wpReason = 'other',
				['wpReason-other'] = reason,  -- reason for scripts that support it
			},
			'CA',
			'CentralAuth'
		),
		middot,
		link(
			'Special:GlobalBlock',
			{
				wpAddress = username,
				wpExpiry = IpOrRange == '' and 'infinite' or 'other',
				wpReason = 'other',
				['wpReason-other'] = reason,
			},
			'gblock',
			'global block'
		),
		middot,
		extlink(
			tostring(mw.uri.new('//login.wickedgov.org/w/index.php'):extend({
				title = 'Special:CheckUser',
				user = username,
				uselang = 'en',
				reason = reason,
			})),
			'lwcu',
			'Login Wiki CheckUser'
		),
		')',
		'</span>',
		'__NOINDEX__'
	}
	return table.concat(text, '')
end

return p