Difference between revisions of "Module:Mailing list member"
Jump to navigation
Jump to search
blackwiki>Jackmcbarn (allow overriding notarget) |
blackwiki>Jackmcbarn (make it work even for active users) |
||
| Line 40: | Line 40: | ||
return '<span class="error">No user or page defined</span>' | return '<span class="error">No user or page defined</span>' | ||
end | end | ||
| + | local notarget = yesno(pargs.notarget) | ||
| + | local retval | ||
if yesno(pargs.inactive, true) then | if yesno(pargs.inactive, true) then | ||
local cutoffs = pageCutoffs[mw.title.getCurrentTitle().prefixedText] or defaultCutoffs | local cutoffs = pageCutoffs[mw.title.getCurrentTitle().prefixedText] or defaultCutoffs | ||
| Line 46: | Line 48: | ||
local notargetInactive = tonumber(lang:formatDate('U', cutoffs[2])) | local notargetInactive = tonumber(lang:formatDate('U', cutoffs[2])) | ||
local maxInactive = tonumber(lang:formatDate('U', cutoffs[3])) | local maxInactive = tonumber(lang:formatDate('U', cutoffs[3])) | ||
| − | |||
if notarget == nil then | if notarget == nil then | ||
notarget = inactiveTS < notargetInactive | notarget = inactiveTS < notargetInactive | ||
end | end | ||
| − | + | retval = ' <span class="inactive-member" style="font-size: 0.95em; font-weight: bold; color: #' | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
if inactiveTS < maxInactive then | if inactiveTS < maxInactive then | ||
retval = retval .. 'F00'; | retval = retval .. 'F00'; | ||
| Line 68: | Line 60: | ||
end | end | ||
retval = retval .. ';">(Inactive since: ' .. maybeLink(lang:formatDate('F Y', pargs.inactive), not notarget and (pargs.user and ('Special:Contributions/' .. pargs.user) or pargs.page)) .. ')</span>' | retval = retval .. ';">(Inactive since: ' .. maybeLink(lang:formatDate('F Y', pargs.inactive), not notarget and (pargs.user and ('Special:Contributions/' .. pargs.user) or pargs.page)) .. ')</span>' | ||
| − | |||
| − | |||
else | else | ||
| − | return frame:callParserFunction('#target', page) | + | retval = '' |
| + | end | ||
| + | if not notarget then | ||
| + | return frame:callParserFunction('#target', page) .. retval | ||
| + | elseif pargs.user then | ||
| + | return frame:expandTemplate{title = 'User', args = { pargs.user }} .. retval | ||
| + | else | ||
| + | return '[[' .. page .. ']]' .. retval | ||
end | end | ||
end | end | ||
return p | return p | ||
Revision as of 19:20, 17 December 2014
Template:Template for discussion/dated Implements {{Mailing list member}}
local yesno = require('Module:Yesno')
local pageCutoffs = {
-- minimum inactive cutoff, notarget cutoff, maximum inactive cutoff
-- - minimum inactive cutoff and maximum inactive cutoff control
-- the colours used to highlight an inactive member
-- - notarget cutoff controls when a member is no longer sent a mass
-- mailing
['Wikipedia:WikiProject Maine/members'] = { '-10 years', '-10 years', '-10 years' },
['Wikipedia:WikiProject Articles for creation/Participants/Message'] = { '-1 year', '-1 year', '-2 years' },
['Wikipedia:WikiProject Baseball/Outreach/Newsletter/Subscriber list'] = { '-1 year', '-2 months', '-2 years' },
['Template:Mailing list member/testcases'] = { '-1 year', '-18 months', '-2 years' }
}
local defaultCutoffs = { '-1 year', '-1 year', '-2 years' }
local p = {}
local function maybeLink(text, target)
return target and ('[[' .. target .. '|' .. text .. ']]') or text
end
function p.main(frame)
local pargs = frame:getParent().args
local lang = mw.getContentLanguage()
local page
if pargs.user then
page = 'User talk:' .. pargs.user
else
page = pargs.page
end
if yesno(pargs.blocked) then
if pargs.user then
return frame:expandTemplate{title = 'Userblocked', args = { pargs.user }} .. ' <span class="blocked-member" style="font-size: 0.95em; font-weight: bold; color: #E33;">(Blocked since: ' .. lang:formatDate('F Y', pargs.blocked) .. ')</span>'
else
return '<span class="error">No user defined</span>'
end
end
if not page then
return '<span class="error">No user or page defined</span>'
end
local notarget = yesno(pargs.notarget)
local retval
if yesno(pargs.inactive, true) then
local cutoffs = pageCutoffs[mw.title.getCurrentTitle().prefixedText] or defaultCutoffs
local inactiveTS = tonumber(lang:formatDate('U', pargs.inactive))
local minInactive = tonumber(lang:formatDate('U', cutoffs[1]))
local notargetInactive = tonumber(lang:formatDate('U', cutoffs[2]))
local maxInactive = tonumber(lang:formatDate('U', cutoffs[3]))
if notarget == nil then
notarget = inactiveTS < notargetInactive
end
retval = ' <span class="inactive-member" style="font-size: 0.95em; font-weight: bold; color: #'
if inactiveTS < maxInactive then
retval = retval .. 'F00';
elseif inactiveTS < minInactive then
retval = retval .. '555';
else
retval = retval .. '080';
end
retval = retval .. ';">(Inactive since: ' .. maybeLink(lang:formatDate('F Y', pargs.inactive), not notarget and (pargs.user and ('Special:Contributions/' .. pargs.user) or pargs.page)) .. ')</span>'
else
retval = ''
end
if not notarget then
return frame:callParserFunction('#target', page) .. retval
elseif pargs.user then
return frame:expandTemplate{title = 'User', args = { pargs.user }} .. retval
else
return '[[' .. page .. ']]' .. retval
end
end
return p