Module:Sandbox/Tol/TolBot tasks

Module documentation


Usage

edit

On User:TolBot and task subpages. User:Tol/Template/TolBot tasks invokes Module:Sandbox/Tol/TolBot tasks to create a list of tasks or details of a single task using data from User:Tol/Template/TolBot tasks/tasks.json.

Example template use

edit
All tasks
{{User:Tol/Template/TolBot tasks}}
Single task
{{User:Tol/Template/TolBot tasks|task number}}

Example module use

edit
All tasks (two tables)
{{#invoke:Sandbox/Tol/TolBot tasks|main}}
One task table
{{#invoke:Sandbox/Tol/TolBot tasks|task|task number}}

Dependencies

edit


local list = require('Module:List')

local p = {}

local data_title = mw.title.new(
	'User:Tol/Template/TolBot tasks/tasks.json'
)
local data_content = data_title:getContent()
local data = mw.text.jsonDecode(data_content)

function p.main()
	-- Split into active and inactive
	local active_tasks = {}
	local inactive_tasks = {}
	for _, task in ipairs(data) do
		if task['active'] then
			table.insert(active_tasks, task)
		else
			table.insert(inactive_tasks, task)
		end
	end
	-- Create tables
	local out = ''
	out = out .. -- Start active tasks wikitable
		'{| class="wikitable" ' ..
		'style="margin-left:auto; margin-right:auto; border:none;"\n' ..
		'|+ Active tasks\n! #\n! Wiki\n! Status\n! Summary\n! Period\n'
	for _, task in ipairs(active_tasks) do -- Add active task rows
		out = out .. mw.getCurrentFrame():expandTemplate{
			title = 'User:Tol/Template/Bot status/Row',
			args = {
				task['task'],
				task['status'],
				task['summary'],
				task['period'],
				wiki = task['wiki']
			}
		} .. '\n'
	end
	out = out .. '|}\n' -- End active tasks wikitable
	out = out .. -- Start inactive tasks wikitable
		'{| class="wikitable" ' ..
		'style="margin-left:auto; margin-right:auto; border:none;"\n' ..
		'|+ Inactive tasks\n! #\n! Wiki\n! Status\n! Summary\n! Period\n'
	for _, task in ipairs(inactive_tasks) do -- Add inactive task rows
		out = out .. mw.getCurrentFrame():expandTemplate{
			title = 'User:Tol/Template/Bot status/Row',
			args = {
				task['task'],
				task['status'],
				task['summary'],
				task['period'],
				wiki = task['wiki']
			}
		} .. '\n'
	end
	out = out .. '|}' -- End inactive tasks wikitable
	return out
end

function p.task()
	local task = data[tonumber(mw.getCurrentFrame().args[1])]
	local out = ''
	out = out .. -- Start wikitable
		'{| class="wikitable" ' ..
		'style="margin-left: auto; margin-right: auto;"\n' ..
		'|+ TolBot: Task ' .. task['task']
	out = out .. -- Status row
		'\n|-\n! Status\n|' ..
		mw.getCurrentFrame():expandTemplate{
			title = 'User:Tol/Template/Bot status',
			args = {
				'TolBot',
				task['task'],
				task['wiki'],
				task['status']
			}
		}
	if not task['active'] then
		out = out .. ' <small>(inactive)</small>'
	end
	if task['wiki'] == 'x' then -- Wiki (interwiki) row
		out = out ..
		'\n|-\n! Wiki\n|' .. task['wiki'] .. ''
	else
		out = out ..
			'\n|-\n! Wiki\n|[[:' .. task['wiki'] .. ':]]'
	end
	out = out .. -- Summary row
		'\n|-\n! Summary\n|' .. task['summary']
	out = out .. -- Page(s) row
		'\n|-\n! Page(s)\n|'
	if task['pages']['page'] then
		if type(task['pages']['page']) == 'string' then
			out = out ..
				'Page: ' ..
				task['pages']['page'] ..
				'\n'
		elseif type(task['pages']['page']) == 'table' then
			out = out ..
				'Pages:' ..
				list['bulleted'](task['pages']['page']) ..
				'\n'
		end
	end
	if task['pages']['category'] then
		if type(task['pages']['category']) == 'string' then
			out = out ..
				'Category: ' ..
				task['pages']['category'] ..
				'\n'
		elseif type(task['pages']['category']) == 'table' then
			out = out ..
				'Categories:' ..
				list['bulleted'](task['pages']['category']) ..
				'\n'
		end
	end
	if task['pages']['prefix'] then
		if type(task['pages']['prefix']) == 'string' then
			out = out ..
				'Prefix: ' ..
				task['pages']['prefix'] ..
				'\n'
		elseif type(task['pages']['prefix']) == 'table' then
			out = out ..
				'Prefixes:' ..
				list['bulleted'](task['pages']['prefix']) ..
				'\n'
		end
	end
	if task['pages']['namespace'] then
		if type(task['pages']['namespace']) == 'number' then
			out = out ..
				'Namespace <small>([[:mw:Help:Namespaces|?]])</small>: ' ..
				task['pages']['namespace'] ..
				'\n'
		elseif type(task['pages']['namespace']) == 'table' then
			out = out ..
				'Namespaces <small>([[:mw:Help:Namespaces|?]])</small>:' ..
				list['bulleted'](task['pages']['namespace']) ..
				'\n'
		end
	end
	out = out .. -- Period row
		'\n|-\n! Period\n|' .. task['period']
	out = out .. -- Language row
		'\n|-\n! [[:d:Q9143|Language]]\n|' .. task['language']
	out = out .. -- Supervision row
		'\n|-\n! Supervision\n|' .. task['supervision']
	if task['exclusion_compliant'] then -- Exclusion compliance row
		out = out ..
			'\n|-\n! [[:w:en:WP:BOTDICT#Exclusion compliant|Excl. compl.]]?\n|Yes'
	elseif task['exclusion_compliant'] == false then
		out = out ..
			'\n|-\n! [[:w:en:WP:BOTDICT#Exclusion compliant|Excl. compl.]]?\n|No'
	end
	out = out .. '\n|}'
	return out
end

function p.bot_status()
	local name = mw.getCurrentFrame().args[1]
	local task = mw.getCurrentFrame().args[2]
	local wiki = mw.getCurrentFrame().args[3]
	local code = mw.getCurrentFrame().args[4]
	local link = ''
	if wiki == 'x' then
		link = ':m:User:' .. name .. '/Task ' .. task
	elseif wiki == 'w:en' then
		link = ':w:en:WP:Bots/Requests for approval/' .. name .. ' ' .. task
	elseif wiki == 'd' then
		link = ':d:WD:Requests for permissions/Bot/' .. name .. ' ' .. task
	elseif mw.getCurrentFrame().args['link'] ~= '' then
		link = mw.getCurrentFrame().args['link']
	else
		link = ':m:User:' .. name .. '/Task ' .. task
	end
	local out = ''
	out = out .. '[[File:'
	if code == 'a' then out = out .. 'Symbol confirmed.svg'
	elseif code == 't' then out = out .. 'Symbol keep vote.svg'
	elseif code == 'w' then out = out .. 'Symbol abstain vote grey.svg'
	elseif code == 'e' then out = out .. 'Image-Symbol wait old.svg'
	elseif code == 'h' then out = out .. 'Symbol wait.svg'
	elseif code == 'd' then out = out .. 'Symbol delete vote darkened.svg'
	elseif code == 'r' then out = out .. 'Symbol no support vote.svg'
	elseif code == 'c' then out = out .. 'Document-properties.svg'
	elseif code == 'f' then out = out .. 'Symbol possible vote.svg'
	elseif code == 'u' then out = out .. 'Symbol neutral vote.png'
	end
	out = out .. '|18px|alt=|link=' .. link .. ']]&nbsp;[[' .. link .. '|'
	if code == 'a' then out = out .. 'Approved'
	elseif code == 't' then out = out .. 'Trial'
	elseif code == 'w' then out = out .. 'Withdrawn'
	elseif code == 'e' then out = out .. 'Expired'
	elseif code == 'h' then out = out .. 'On hold'
	elseif code == 'd' then out = out .. 'Denied'
	elseif code == 'r' then out = out .. 'Revoked'
	elseif code == 'c' then out = out .. 'Coding'
	elseif code == 'f' then out = out .. 'Filed'
	elseif code == 'u' then out = out .. 'Unapproved'
	end
	out = out .. ']]'
	return out
end

return p