更多操作
此模块的文档可以在模块:Cat/doc创建
local p = {}
local yesno = require 'Module:Yesno'
local data = require 'Module:Cat/data'
local function matchPatternsInList(list, str)
for _, pattern in ipairs(rules.blacklist) do
if string.find(str, pattern) then
return true
end
end
return false
end
local function shouldBeSupressed(rules, title)
-- 根据命名空间筛选是否添加分类
if rules.ns_mode == 'blacklist' then
if rules.nsid_blacklist[title.namespace] then
return true
end
elseif rules.ns_mode == 'whitelist' then
if not rules.nsid_whitelist[title.namespace] then
return true
end
end
-- 根据条目名模式筛选是否添加分类
if rules.title_mode == 'blacklist' then
if matchPatternsInList(rules.title_blacklist, title.text) then
return true
end
elseif rules.title_mode == 'whitelist' then
if not matchPatternsInList(rules.title_whitelist, title.text) then
return true
end
end
end
function p.main()
local frame = mw.getCurrentFrame()
-- 处理 nocat
local nocat = yesno(frame.args.nocat, nil)
if nocat then
return nil
elseif nocat == false then
return frame.args[1]
end
local title = mw.title.getCurrentTitle()
if shouldBeSupressed(data.rulesMap['*'], title) then
return nil
end
local kind = frame.args[2] or frame.args['kind'] or 'unspecified'
local rules = data.rulesMap[kind] or data.rulesMap['unspecified']
if shouldBeSupressed(rules, title) then
return nil
end
return frame.args[1]
end
return p