Module:Signpost poll
Appearance
![]() | This module depends on the following other modules: |
This module implements Wikipedia:Wikipedia Signpost/Templates/Voter.
-- This module implments polls used in articles of the Signpost.
local CONFIG_MODULE = 'Module:Signpost poll/config'
local cfg = {
-- Color definitions:
['foundation-blue'] = '#006699',
['foundation-green'] = '#339966',
['foundation-red'] = '#990000',
['preload-default'] = 'Wikipedia:Wikipedia Signpost/Templates/Voter/Vote preload',
}
--[[
We need:
preload - use a standard preload and pass the option text in by parameter.
image
question
option1
option1vote - the vote text to use for option one - defaults to option1
option1color
option2
option2vote
option2color
...
min_votes
break - if 'all', breaks on all options; if a number, breaks after that number option
overlay
expiry
]]
-------------------------------------------------------------------------------
-- Poll class
-------------------------------------------------------------------------------
local Poll = {}
Poll.__index = Poll
function Poll.new(args, cfg)
local self = setmetatable({}, Poll)
self.args = args
self.cfg = cfg
return self
end
function Poll:message(key, ...)
local msg = self.cfg[key]
if select('#', ...) > 0 then
return mw.message.newRawMessage(msg, ...):plain()
else
return msg
end
end
function Poll:getColor(n)
-- Get the color for option n
local defaults = {
self:message('foundation-blue'),
self:message('foundation-green'),
self:message('foundation-red')
}
local ret = {}
if n <= #defaults then
for i = 1, n do
ret[n] = defaults[n]
end
else
error(string.format(
'attempt to make a color table with %d colors; only %d colors are supported',
n, #defaults
), 2)
end
return ret[n]
end
-------------------------------------------------------------------------------
-- Exports
-------------------------------------------------------------------------------
local p = {}
function p._main(args, cfg)
cfg = cfg or mw.loadData(CONFIG_MODULE)
return tostring(Poll.new(args, cfg))
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Wikipedia:Wikipedia Signpost/Templates/Voter'
})
return p._main(args)
end
return p