Jump to content

Module:CU request

From Meta, a Wikimedia project coordination wiki
Module documentation

require('strict')

local p = {}

local MAX_ACCOUNTS = 200
local get_args = require('Module:Arguments').getArgs

local function srcu(user_name, language_code, project_shortcut)
	return ': {{srcu|' .. user_name .. '|' .. language_code .. '|' .. project_shortcut .. '}}'
end

-- An (almost) faithful replication of [[Special:Permalink/22870903]].
function p._main(status, review, discussion, reason, language_code, project_shortcut, user_names)
	local lines = {'<div class="plainlinks">'}
	
	local status_or_default = status ~= nil and status ~= '' and status or 'In progress.'
	local review_or_default = review or ''
	table.insert(lines, '{{status' .. '|' .. status_or_default .. '|review = ' .. review_or_default .. '}}')
	
	table.insert(lines, '; List of users')
	
	local first_user_name = user_names[1] or 'Example'
	table.insert(lines, srcu(first_user_name, language_code, project_shortcut))
	
	for index = 2, #user_names do
		local user_name = user_names[index]
		table.insert(lines, srcu(user_name, language_code, project_shortcut))
	end
	
	table.insert(lines, '* {{CUlog|' .. language_code .. '|' .. project_shortcut .. '}}')
	
	if discussion then
		table.insert(lines, '* Discussion: ' .. discussion)
	end
	
	table.insert(lines, '')
	
	local reason_or_error = reason or '<strong class="error">Please provide a reason.</strong>'
	table.insert(lines, 'Reason(s): ' .. reason_or_error .. '</div>')
	
	return table.concat(lines, '\n')
end

function p.main(frame)
	local args = get_args(frame, {
		trim = true,
		removeBlanks = false
	})
	
	local review, discussion, reason = args.review, args.discussion, args.reason
	local status = args.status or ''
	
	local language_code = args['language code'] or ''
	local project_shortcut = args['project shortcut'] or ''
	
	local user_names = {}
	
	for index = 1, MAX_ACCOUNTS do
		local user_name = args['user name' .. tostring(index)]
		
		if user_name then
			-- No break; legacy template would ignore empty user name parameters.
			table.insert(user_names, user_name)
		end
	end
	
	local wikitext = p._main(
		status, review, discussion, reason,
		language_code, project_shortcut, user_names
	)
	
	return frame:preprocess(wikitext)
end

return p