打开/关闭菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模块:Cat:修订间差异

来自Cookie☆Wiki
(先放上来, 其他明天再说…)
 
无编辑摘要
第14行: 第14行:
end
end


function p.main()
local function shouldBeSupressed(rules, title)
    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.ns_mode == 'blacklist' then
         if rules.nsid_blacklist[title.namespace] then
         if rules.nsid_blacklist[title.namespace] then
             return nil
             return true
         end
         end
     elseif rules.ns_mode == 'whitelist' then
     elseif rules.ns_mode == 'whitelist' then
         if not rules.nsid_whitelist[title.namespace] then
         if not rules.nsid_whitelist[title.namespace] then
             return nil
             return true
         end
         end
     end
     end
第43行: 第29行:
     if rules.title_mode == 'blacklist' then
     if rules.title_mode == 'blacklist' then
         if matchPatternsInList(rules.title_blacklist, title.text) then
         if matchPatternsInList(rules.title_blacklist, title.text) then
             return nil
             return true
         end
         end
     elseif rules.title_mode == 'whitelist' then
     elseif rules.title_mode == 'whitelist' then
         if not matchPatternsInList(rules.title_whitelist, title.text) then
         if not matchPatternsInList(rules.title_whitelist, title.text) then
             return nil
             return true
         end
         end
     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]
     return frame.args[1]

2019年4月7日 (日) 10:47的版本

此模块的文档可以在模块: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