Difference between revisions of "Module:Mailing list member/sandbox"

From blackwiki
Jump to navigation Jump to search
blackwiki>Technical 13
(notarget=no use case.)
m (11 revisions imported)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 
local yesno = require('Module:Yesno')
 
local yesno = require('Module:Yesno')
+
 
 
local pageCutoffs = {
 
local pageCutoffs = {
 
-- minimum inactive cutoff, notarget cutoff, maximum inactive cutoff
 
-- minimum inactive cutoff, notarget cutoff, maximum inactive cutoff
Line 12: Line 12:
 
['Template:Mailing list member/testcases'] = { '-1 year', '-18 months', '-2 years' }
 
['Template:Mailing list member/testcases'] = { '-1 year', '-18 months', '-2 years' }
 
}
 
}
+
 
 
local defaultCutoffs = { '-1 year', '-1 year', '-2 years' }
 
local defaultCutoffs = { '-1 year', '-1 year', '-2 years' }
+
 
 
local p = {}
 
local p = {}
+
 
local function maybeLink(text, target)
+
local function parenText(text, color, class)
return target and ('[[' .. target .. '|' .. text .. ']]') or text
+
return string.format(
 +
' <span%s style="font-size:0.95em;font-weight:bold;color:%s">(%s)</span>',
 +
class and (' class="' .. class .. '"') or '',
 +
color,
 +
text
 +
)
 
end
 
end
+
 
 
function p.main(frame)
 
function p.main(frame)
 
local pargs = frame:getParent().args
 
local pargs = frame:getParent().args
 
local lang = mw.getContentLanguage()
 
local lang = mw.getContentLanguage()
local page
+
local notarget = yesno(pargs.notarget)
 +
local page, retval
 
if pargs.user then
 
if pargs.user then
 
page = 'User talk:' .. pargs.user
 
page = 'User talk:' .. pargs.user
else
+
if yesno(pargs.blocked, true) then
page = pargs.page
+
retval = frame:expandTemplate{title = 'Userblocked', args = { pargs.user }} .. parenText('Blocked since: ' .. lang:formatDate('F Y', pargs.blocked), 'red', 'blocked-member')
end
+
if notarget == nil then
if yesno(pargs.blocked, true) then
+
notarget = true
if pargs.user then
+
end
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
 
else
return '<span class="error">No user defined</span>'
+
retval = frame:expandTemplate{title = 'User', args = { pargs.user }}
 
end
 
end
end
+
elseif pargs.page then
if not page then
+
page = pargs.page
 +
retval = '[[' .. page .. ']]'
 +
else
 
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
 
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 yesno(pargs.inactive, true) then
 
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
 
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: #'
+
local text, color = 'Inactive since'
if inactiveTS < maxInactive and not notarget then
+
if inactiveTS < maxInactive then
retval = retval .. 'F00;">(Inactive since: ';
+
color = 'red'
elseif inactiveTS < minInactive or (notarget and inactiveTS < maxInactive) then
+
elseif inactiveTS < minInactive then
retval = retval .. '555;">(Inactive since: ';
+
color = '#555'
 
else
 
else
retval = retval .. '080;">(Last active: ';
+
color = '#080'
 +
text = 'Last active'
 
end
 
end
retval = retval .. maybeLink(lang:formatDate('F Y', pargs.inactive), pargs.user and ('Special:Contributions/' .. pargs.user) or pargs.page) .. ')</span>'
+
retval = retval .. parenText(string.format(
else
+
'%s: %s',
retval = ''
+
text,
end
+
lang:formatDate('F Y', pargs.inactive)
if notarget and inactiveTS > maxInactive then
+
), color, 'inactive-member')
retval = retval .. ' <span style="font-size:0.95em;font-weight:bold;color:#F00">(Not receiving mass messages)</span>'
 
else
 
frame:callParserFunction('#target', page)
 
 
end
 
end
if pargs.user then
+
if notarget then
return frame:expandTemplate{title = 'User', args = { pargs.user }} .. retval
+
return retval .. parenText('Not receiving mass messages', '#555')
else
 
return '[[' .. page .. ']]' .. retval
 
 
end
 
end
 +
frame:callParserFunction('#target', page)
 +
return retval
 
end
 
end
+
 
 
return p
 
return p

Latest revision as of 07:51, 27 September 2020

Documentation for this module may be created at Module:Mailing list member/sandbox/doc

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 parenText(text, color, class)
	return string.format(
		' <span%s style="font-size:0.95em;font-weight:bold;color:%s">(%s)</span>',
		class and (' class="' .. class .. '"') or '',
		color,
		text
	)
end

function p.main(frame)
	local pargs = frame:getParent().args
	local lang = mw.getContentLanguage()
	local notarget = yesno(pargs.notarget)
	local page, retval
	if pargs.user then
		page = 'User talk:' .. pargs.user
		if yesno(pargs.blocked, true) then
			retval = frame:expandTemplate{title = 'Userblocked', args = { pargs.user }} .. parenText('Blocked since: ' .. lang:formatDate('F Y', pargs.blocked), 'red', 'blocked-member')
			if notarget == nil then
				notarget = true
			end
		else
			retval = frame:expandTemplate{title = 'User', args = { pargs.user }}
		end
	elseif pargs.page then
		page = pargs.page
		retval = '[[' .. page .. ']]'
	else
		return '<span class="error">No user or page defined</span>'
	end
	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
		local text, color = 'Inactive since'
		if inactiveTS < maxInactive then
			color = 'red'
		elseif inactiveTS < minInactive then
			color = '#555'
		else
			color = '#080'
			text = 'Last active'
		end
		retval = retval .. parenText(string.format(
				'%s: %s',
				text,
				lang:formatDate('F Y', pargs.inactive)
			), color, 'inactive-member')
	end
	if notarget then
		return retval .. parenText('Not receiving mass messages', '#555')
	end
	frame:callParserFunction('#target', page)
	return retval
end

return p