更多操作
此模块的文档可以在模块: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
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()
local kind = frame.args[2] or frame.args['kind'] or ''
local rules = data[kind] or data['']
-- 根据命名空间筛选是否添加分类
if rules.ns_mode == 'blacklist' then
if rules.nsid_blacklist[title.namespace] then
return nil
end
elseif rules.ns_mode == 'whitelist' then
if not rules.nsid_whitelist[title.namespace] then
return nil
end
end
-- 根据条目名模式筛选是否添加分类
if rules.title_mode == 'blacklist' then
if matchPatternsInList(rules.title_blacklist, title.text) then
return nil
end
elseif rules.title_mode == 'whitelist' then
if not matchPatternsInList(rules.title_whitelist, title.text) then
return nil
end
end
return frame.args[1]
end
return p