模組:Mailing list member

文档图示 模块文档[查看] [编辑] [历史] [清除缓存]

概要 编辑

此模块與m:Template:Target相似。這是一個包裝模板(Wrapper Template),方便建立與管理大量訊息發送功能所使用的發送清單格式。

參數及使用方法 编辑

  • {{Mailing list member|user=Example|inactive=使用者開始不活躍的日期|Userblocked=使用者被封禁的日期|notarget=不接收訊息(yes/no)}}
以下是该模板的模板数据,适用于可视化编辑器等工具。

Mailing list member模板数据

這是一個包裝模板(Wrapper Template),方便建立與管理大量訊息發送功能所使用的發送清單格式。

模板参数[编辑模板数据]

参数描述类型状态
Usernameuser

欲加入至大量訊息發送清單的使用者之名稱。請至少在此選項'''或是'''<code>page</code>選項中填入一個參數,不能跟<code>page</code>選項同時使用。

用户可选
Project pagenamepage

欲加入大量訊息發送清單的'''完整頁面名稱'''。請至少在此選項'''或是'''<code>user</code>選項中填入一個參數,不能跟<code>user</code>選項同時使用。

页面名称可选
Inactive userinactive

前述使用者或是計畫頁面開始不活躍的時間。

默认值
no
字符串可选
Blocked userUserblocked

前述使用者開始被封禁的日期,必須跟<code>user</code>選項同時使用。

默认值
no
字符串可选
notargetnotarget

不接收訊息

布尔可选

參見 编辑

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
	['Template:Mailing list member/testcases'] = { '-1 year', '-18 months', '-2 years' },
	['模块讨论: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 = 'Userblock', args = { pargs.user }} .. parenText('自' .. lang:formatDate('Y年Fj日', 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">未定義使用者名稱或頁面名稱。</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 = '開始不活躍時間:'
		if inactiveTS < maxInactive then
			color = 'red'
		elseif inactiveTS < minInactive then
			color = '#555'
		else
			color = '#080'
			text = '最後一次活動時間是在'
		end
		retval = retval .. parenText(string.format(
				'%s%s',
				text,
				lang:formatDate('Y年Fj日', pargs.inactive)
			), color, 'inactive-member')
	end
	if notarget then
		return retval .. parenText('不接收大量傳送的訊息。', '#555')
	end
	frame:callParserFunction('#target', page)
	return retval
end

return p