Jump to content

Module:WMF elections questions

Permanently protected module
From Meta, a Wikimedia project coordination wiki
Module documentation
local p = {}

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

local function param(args, param, fallback)
	if fallback == nil then
		return args[param] or '{{{' .. param .. '}}}'
	else
		return args[param] or fallback
	end
end

function p.main(frame)
	local args = getArgs(frame, {
		trim = true,
		removeBlanks = true
	})
	local ret = {
		frame:extensionTag('templatestyles', '', {
			src = 'Template:WMF elections/Questions/styles.css'
		}),
		'<div class="WMF-EQ-question">',
		'<div>[[File:Question.svg|100px]]</div>',
		'<div>',
		'<span class="WMF-EQ-question-content">' ..
			param(args, 'question') ..
		'</span>' .. (
			param(args, 'questionauthors', false) and
			'\n:<span class="WMF-EQ-question-author">' ..
				'<i>' .. param(args, 'questionauthors') .. '</i>' ..
			'</span>' or
			''
		),
		'</div>',
		'</div>',
		'<div class="WMF-EQ-candidates">',
	}
	for i = 1, 50 do
		if args['candidate' .. i] then
			table.insert(ret, (function()
				local answer = ''
				if param(args, param(args, 'candidate' .. i .. 'username'), false) then
					answer = param(args, param(args, 'candidate' .. i .. 'username'))
				else
					answer = '<i>No response yet.</i>'
				end
				local div = mw.html.create('div')
					:attr('class', 'WMF-EQ-candidate-box dshuf dshufset' .. param(args, 'qnum'))
					:node(
						mw.html.create('div')
							:attr('class', 'WMF-EQ-candidate-box-header')
							:wikitext(
								'\n' ..
								param(args, 'candidate' .. i) ..
								' ([[' .. param(args, 'candidate' .. i .. 'link') .. '|' ..
								param(args, 'candidate' .. i .. 'username') .. ']])' ..
								'\n'
							)
					)
					:node(
						mw.html.create('div')
							:attr('class', 'WMF-EQ-candidate-box-answer')
							:wikitext('\n' .. answer .. '\n')
					)
				return tostring(div)
			end)())
		end
	end
	table.insert(ret, '</div>')
	
	return table.concat(ret, '\n');
end

return p