Module:Mass notification
Appearance
This module implements the {{mass notification}} template. It is used to send notifications to a WikiProject or other group of users.
Usage from wikitext
Usually you should use {{mass notification}} rather than calling this module directly from #invoke. However, if you want you can use the syntax {{#invoke:Mass notification|main|group name}}
. See the template documentation for details about group names.
Usage from Lua modules
To use this module from other Lua modules, first load the module.
local mMassNotification = require('Module:Mass notification')
You can then generate the notification links by using the _main function.
mMassNotification._main(groupName)
groupName is the group name, as a string, as explained in the template documentation.
-- This module sends out notifications to multiple users.
local mList = require('Module:List')
local MAX_USERS = math.huge -- Not sure if there is a limit on notifications, so building it in now.
local GROUP_PAGE_PATH = 'Module:Mass notification/groups/'
local NO_NAME_ERROR = 'no group name was specified'
local LOAD_ERROR = 'the group "[[$1|$2]]" was not found'
local MAX_USER_ERROR = 'attempted to send notifications to more than $1 users'
local NO_USER_ERROR = 'could not find any usernames in $1'
local INTRO_BLURB = 'Notifying $1 <small>([[Template:Mass notification|more info]]'
.. " '''·''' "
.. '<span class="plainlinks">[$2 opt out]</span>)</small>:\n'
local LINK_LIST_STYLE = 'font-size: smaller'
local p = {}
local function message(msg, ...)
return mw.message.newRawMessage(msg):params{...}:plain()
end
local function makeWikitextError(msg)
return string.format(
'<strong class="error">Error: %s.</strong>',
msg
)
end
local function makeUserLinks(t)
end
function p._main(groupName)
-- Validate input.
if type(groupName) ~= 'string' then
return makeWikitextError(NO_NAME_ERROR)
end
local groupSubmodule = GROUP_PAGE_PATH .. groupName
-- Load the group submodule and check for errors.
local usernames
do
local success
success, usernames = pcall(mw.loadData, groupSubmodule)
if not success then
return makeWikitextError(message(LOAD_ERROR, groupSubmodule, groupName))
elseif type(usernames) ~= 'table' or not usernames[1] then -- # doesn't work with mw.loadData
return makeWikitextError(message(NO_USER_ERROR, groupName))
elseif usernames[MAX_USERS + 1] then -- # doesn't work with mw.loadData
return makeWikitextError(message(MAX_USER_ERROR, groupName))
end
end
-- Make the intro blurb.
local introBlurb
do
local optOutUrl = tostring(mw.uri.fullUrl(
groupSubmodule,
{action = 'edit'}
))
introBlurb = message(INTRO_BLURB, groupName, optOutUrl)
end
-- Make the user links.
local userLinks
do
local userNamespace = mw.site.namespaces[2].name
local listArgs = {}
for i, username in ipairs(usernames) do
username = tostring(username)
listArgs[i] = string.format(
'[[%s:%s|%s]]',
userNamespace,
username,
username
)
end
listArgs.style = LINK_LIST_STYLE
userLinks = mList.makeList('horizontal', listArgs)
end
return introBlurb .. userLinks
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:Mass notification'
})
local groupName = args[1]
return p._main(groupName)
end
return p