local module = {}
local getArgs = require('Module:Arguments').getArgs
local applicableUserGroups = {'维护姬', '管理员', '用户查核员', '监督员', '界面管理员', '机器人', '机器用户', '文件维护员', '普通'}
local nomobileUserGroups = {'管理员', '用户查核员', '监督员', '界面管理员'}
local suffixText = {
['普通'] = '(用于申请优质编辑者、技术编辑员等)'
}
local function has_value(tab, val)
for _, value in ipairs(tab) do
if value == val then
return true
end
end
return false
end
-- 处理位置参数并将其转换为逗号分隔的字符串,保持顺序
local function processPositionalArgs(args)
local positionalArgs = {}
-- 首先收集所有数字键
local numberKeys = {}
for key, _ in pairs(args) do
if type(key) == 'number' then
table.insert(numberKeys, key)
end
end
-- 对数字键进行排序
table.sort(numberKeys)
-- 按顺序收集值
for _, key in ipairs(numberKeys) do
table.insert(positionalArgs, args[key])
end
-- 如果有位置参数,则使用它们
if #positionalArgs > 0 then
return table.concat(positionalArgs, ',')
end
-- 如果没有位置参数,则返回 nil
return nil
end
function module.main(frame)
local args = getArgs(frame)
local htmlTable = {}
local isFirstElement = true
-- 处理位置参数
local positionalUserGroups = processPositionalArgs(args)
-- 优先使用位置参数,如果没有则使用 userGroups 参数,如果都没有则使用默认值
local userGroups = positionalUserGroups or args.userGroups or table.concat(applicableUserGroups, ',')
-- 分割用户组并保持顺序
local userGroupList = mw.text.split(userGroups, ',', true)
for _, userGroup in ipairs(userGroupList) do
userGroup = mw.text.trim(userGroup) -- 去除前后空格
if has_value(applicableUserGroups, userGroup) then
local element = mw.html.create('span')
if (has_value(nomobileUserGroups, userGroup)) then
element:addClass('nomobile')
end
if isFirstElement then
isFirstElement = false
else
element:wikitext('、')
end
element:wikitext(
'[{{fullurl:萌娘百科_talk:讨论版/权限变更|action=edit§ion=new&nosummary=1&preload=Template%3A权限申请%2F' ..
userGroup ..
'申请预载}} <span class="mw-ui-button mw-ui-progressive" role="button">' ..
userGroup .. '申请</span>]'
)
element:wikitext(suffixText[userGroup] or '')
table.insert(htmlTable, tostring(element))
end
end
return frame:preprocess(table.concat(htmlTable, ''))
end
return module