Jump to content

Module:Request for permission links

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Pppery (talk | contribs) at 17:07, 16 May 2024 (Protected "Module:Request for permission links": High-risk template or module ([Edit=Require autoconfirmed or confirmed access] (indefinite) [Move=Require autoconfirmed or confirmed access] (indefinite))). 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)
	-- Equivalent of {{{User|{{{1|Example}}}}}}.
	local username = args['User'] or args['1'] or 'Example'
	local permission = args['permission']
	-- Count the number of subpages of WP:PERM with requests for this user.
	local requested = 0
	-- Equivalent of {{FULLPAGENAME}}.
	local current = mw.allToString(mw.title.getCurrentTitle())
	-- Title of WP:PERM
	local base = 'Wikipedia:Requests for permissions'
	-- Equivalent of {{SUBPAGENAME}}, if the current title is a subpage of WP:PERM.
	-- If not, then the equivalent of {{FULLPAGENAME}}.
	local subtitle = mw.ustring.gsub(current, base..'/', '')
	-- The 13 WP:PERM subpages currently used for requesting permissions.
	local subpages = {'Account creator', 'Autopatrolled', 'AutoWikiBrowser', 'Confirmed', 'Event coordinator', 'Extended confirmed', 'File mover', 'Mass message sender', 'New page reviewer', 'Page mover', 'Pending changes reviewer', 'Rollback', 'Template editor'}
	-- Check whether the given permission (if any) is a valid perm (one of the subpages).
	local unknown = true
	local check = {['Account creator']=true, ['Autopatrolled']=true, ['AutoWikiBrowser']=true, ['Confirmed']=true, ['Event coordinator']=true, ['Extended confirmed']=true, ['File mover']=true, ['Mass message sender']=true, ['New page reviewer']=true, ['Page mover']=true, ['Pending changes reviewer']=true, ['Rollback']=true, ['Template editor']=true}

	if check[permission] then
		unknown = false
	else
		permission = nil	
	end

	local intext = {}
	-- If at WP:PERM base page,
	if current == base then
		-- then check each subpage for a request for this user.
		local text = {}
		local onepermission = ''
		for i=1,#subpages do
			text[i] = mw.title.new( base .. '/' .. subpages[i]):getContent() or ''
			intext[i] = text[i] ~= mw.ustring.gsub(text[i], mw.ustring.gsub('{{rfplinks|1='..username..'}}', "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" ), '')
			if intext[i] then
				requested = requested + 1
				-- Keep track of one of the permissions (for use if there is only one).
				onepermission = subpages[i]
			end
		end
		-- If there is only one permission, then assign that to "permission".
		if requested == 1 then
			permission = onepermission
			unknown = false
		end
	-- If the page is one of the subpages, and the subpage is one of the 
	-- listed subpages, then use that as the permission.
	elseif subtitle ~= current and check[subtitle] and not permission then
		permission = subtitle
		unknown = false
	end

	-- Now we start forming the return string.
	local ret = '[[User:' .. username .. '|' .. username .. ']]'
	if permission and permission ~= '' and requested == 0 then
		requested = 1
	end

	if requested ~= 0 then
		if requested == 1 then
			-- If requesting one perm, but viewed on a page other than that 
			-- perm's subpage of WP:PERM, then show the permission requested.
			if current ~= base..'/'..permission then
				ret = ret .. ' (<small>requesting  [['..base..'/'..permission..'#User:'..username..'|'..permission..']]</small>)'
			end
		else
			-- If requesting multiple perms at WP:PERM, then show all
			-- permissions requested.
			ret = ret .. ' (<small>requesting '
			local first = true
			for i=1,#subpages do
				if intext[i] then
					if not first then
						ret = ret .. ', '
					else
						first = false
					end
					ret = ret .. '[['..base..'/'..subpages[i]..'#User:'..username..'|'..subpages[i]..']]'
				end
			end
			ret = ret .. '</small>)'
		end
	end

	-- Some frequently repeated strings to be used in the return string.
	local dot = " '''&middot;''' "
	local urlun = frame:callParserFunction('urlencode', username)
	local urlsite = '[https://en.wikipedia.org/w/index.php?title='

	-- User talk page link
	ret = ret..' <span class="plainlinks">([[User talk:'..username..'|t]]'
	-- User talk page history link
	..dot..'[[Special:History/User talk:'..username..'|th]]'
	-- Contributions link
	..dot..'[[Special:Contribs/'..username..'|c]]'

	if permission == 'Template editor' then
		-- Template edits
		ret = ret..' <sup>('..urlsite..'Special:Contributions&target='
		..urlun..'&namespace=10 template space]'
		-- Template talk edits
		..dot..urlsite..'Special:Contributions&target='
		..urlun..'&namespace=11 edit requests])</sup>'
	elseif permission == 'Page mover' then
		-- Edits at WP:RM/TR (technical move requests)
		ret = ret..' <sup>([https://sigma.toolforge.org/usersearch.py?name='..urlun
		..'&page=Wikipedia%3ARequested+moves%2FTechnical+requests&max=500&server=enwiki RM/TR]'
		-- Edits with summaries containing "requested move" (comments, closes, etc.)
		..dot..'[https://sigma.toolforge.org/summary.py?name='..urlun
		..'&search=requested+move&server=enwiki RMs])</sup>'
	elseif permission == 'File mover' then
		ret = ret..' <sup>('..urlsite..'Special:Contributions&target='
		..urlun..'&namespace=6 file space])</sup>'
	end

	-- Deleted contributions 
	-- (This link is mostly only visible to admins. See [[Help:-show classes]].) 
	ret = ret..dot..'<span class="sysop-show">[[Special:DeletedContributions/'..username..'|del]]'
	..dot..'</span>[[:luxo:'..urlun..'|cross-wiki]]'
	..dot..'[[Special:CentralAuth/'..username..'|SUL]]'
	..dot..'[https://xtools.wmflabs.org/ec/en.wikipedia.org/'..urlun..' edit counter]'

	if permission == 'Event coordinator' then
		ret = ret..dot..urlsite..'Special:Log&type=newusers&user='
		..urlun..'&limit=5000 accounts created]'
	elseif permission == 'Template editor' then
		ret = ret..dot..'[https://xtools.wmflabs.org/pages?project=en.wikipedia.org&username='
		..urlun..'&namespace=10 templates created]'
	else 
		-- Xtools (pages created)
		ret = ret..dot..'pages created ([https://xtools.wmflabs.org/pages?user='
		..urlun..'&project=en.wikipedia.org&namespace=all&redirects=noredirects xtools]'
		-- Sigma (pages created)
		..dot..'[https://sigma.toolforge.org/created.py?name='
		..urlun..'&server=enwiki&ns=,,&redirects=none sigma])'
	end

	ret = ret..dot..'[https://xtools.wmflabs.org/autoedits/en.wikipedia.org/'
	..urlun..' non-automated edits]'
	..dot..'[https://xtools.wmflabs.org/categoryedits/en.wikipedia.org/'
	..urlun..'/Living_people BLP edits]'
	-- Undo/revert/rollback
	..dot..urlsite..'Special%3AContributions&target='
	..urlun..'&namespace=all&tagfilter=mw-undo undos]'
	..dot..urlsite..'Special%3AContributions&target='
	..urlun..'&namespace=all&tagfilter=mw-manual-revert manual reverts]'
	..dot..urlsite..'Special%3AContributions&target='
	..urlun..'&namespace=all&tagfilter=mw-rollback rollbacks]'
	-- Logs
	..dot..urlsite..'Special:Log&user='..urlun..' logs]'
	-- Block log
	..' <sup>('..urlsite..'Special:Log/block&page=User:'..urlun..' blocks]'
	-- Rights log
	..dot..urlsite..'Special:Log/rights&page=User:'..urlun..' rights]'
	-- Move log
	..dot..urlsite..'Special:Log/move&user='..urlun..' moves])</sup>'

	if permission == 'New page reviewer' then
		ret = ret..dot..urlsite..'Special:Log/pagetriage-curation&user='..urlun..' curation log]'
		..dot..urlsite..'Special:Log/patrol&user='..urlun..'&subtype=patrol patrol log]'
		..dot..'[https://afdstats.toolforge.org/afdstats.py?name='..urlun..'&max=&startdate=&altname= AFD stats]'
		..dot..'[https://apersonbot.toolforge.org/afchistory/?user='..urlun..' AFC stats]'
		..dot..'[[User:'..username..'/CSD log|CSD log]]'
		..dot..'[[User:'..username..'/PROD log|PROD log]]'
		..dot..'[[User:'..username..'/Draftify log|Draftify log]]'
		..dot..'[https://xtools.wmcloud.org/ec-namespacetotals/en.wikipedia.org/'
		..urlun..' Mainspace edits]'
	end

	-- Requests for arbitration, sockpuppet investigations, contributor copyright investigations
	ret = ret..dot..'[[WP:Arbitration/Requests/Case/'..username..'|rfar]]'
	..dot..'[[WP:Sockpuppet investigations/'..username..'|spi]]'
	..dot..'[[WP:Contributor copyright investigations/'..username..'|cci]])'
	
	-- Now the links for assigning permissions/notifying users
	-- (Again, mostly only visible to admins. See [[Help:-show classes]].)
	ret = ret..' <span class="sysop-show perm-assign-permissions">('
	if permission == 'AutoWikiBrowser' then
		ret = ret..urlsite..'Wikipedia:AutoWikiBrowser/CheckPageJSON&action=edit edit CheckPage])'
	else
		ret = ret..'[[Special:UserRights/'..username
		.."|<span style='color: #03B;'>'''assign permissions'''</span>]])"
	end

	if permission ~= 'AutoWikiBrowser' and permission ~= 'Confirmed' and 
	permission ~= 'Event coordinator' and permission ~= 'Extended confirmed' then
		ret = ret..'<sup>('
	end

	local notify = urlsite..'User_talk:'..urlun..'&action=edit&section=new&preloadtitle='
	if permission == 'Account creator' or unknown then
		ret = ret..notify..'Account%20creator%20granted&preload=Template:Account%20creator%20granted'
		if unknown then
			ret = ret..' acc]'..dot
		end
	end

	if permission == 'Autopatrolled' or unknown then
		ret = ret..notify..'Autopatrolled%20granted&preload=Template:Autopatrolled%20granted'
		if unknown then
			ret = ret..' ap]'..dot
		end
	end

	if permission == 'File mover' or unknown then
		ret = ret..notify..'File%20move%20granted&preload=Template:File%20mover%20granted'
		if unknown then
			ret = ret..' fm]'..dot
		end
	end

	if permission == 'Mass message sender' or unknown then
		ret = ret..notify..'Mass%20message%20sender%20granted&preload=Template:Mass%20message%20sender%20granted'
		if unknown then
			ret = ret..' mms]'..dot
		end
	end

	if permission == 'New page reviewer' or unknown then
		ret = ret..notify..'New%20page%20reviewer%20granted&preload=Template:New%20page%20reviewer%20granted'
		if unknown then
			ret = ret..' npr]'..dot
		end
	end

	if permission == 'Page mover' or unknown then
		ret = ret..notify..'Page%20mover%20granted&preload=Template:Page%20mover%20granted'
		if unknown then
			ret = ret..' pm]'..dot
		end
	end

	if permission == 'Pending changes reviewer' or unknown then
		ret = ret..notify..'Pending%20changes%20reviewer%20granted&preload=Template:Pending%20changes%20reviewer%20granted'
		if unknown then
			ret = ret..' pcr]'..dot
		end
	end

	if permission == 'Rollback' or unknown then
		ret = ret..notify..'Rollback%20granted&preload=Template:Rollback%20granted'
		if unknown then
			ret = ret..' rb])</sup>'
		end
	end

	if not unknown and permission ~= 'AutoWikiBrowser' and permission ~= 'Confirmed'
	and permission ~= 'Event coordinator' and permission ~= 'Extended confirmed' then
		ret = ret..' notify])</sup>'
	end

	ret = ret..'</span></span>'
	return ret
end

return p