Module:Lua banner: Difference between revisions

    (Add parameter to disable protection level tracking, useful when a template only includes part of a module)
    (Putting that logic in the correct place)
    Line 74: Line 74:
    if titleObj.namespace == 10
    if titleObj.namespace == 10
    and not subpageBlacklist[titleObj.subpageText]
    and not subpageBlacklist[titleObj.subpageText]
    and not args.noprotcat
    then
    then
    local category = args.category
    local category = args.category
    Line 89: Line 88:
    end
    end
    cats[#cats + 1] = category
    cats[#cats + 1] = category
    local protLevels = {
    if not args.noprotcat then
    autoconfirmed = 1,
    local protLevels = {
    extendedconfirmed = 2,
    autoconfirmed = 1,
    templateeditor = 3,
    extendedconfirmed = 2,
    sysop = 4
    templateeditor = 3,
    }
    sysop = 4
    local currentProt
    }
    if titleObj.id ~= 0 then
    local currentProt
    -- id is 0 (page does not exist) if am previewing before creating a template.
    if titleObj.id ~= 0 then
    currentProt = titleObj.protectionLevels["edit"][1]
    -- id is 0 (page does not exist) if am previewing before creating a template.
    end
    currentProt = titleObj.protectionLevels["edit"][1]
    if currentProt == nil then currentProt = 0 else currentProt = protLevels[currentProt] end
    end
    for i, module in ipairs(modules) do
    if currentProt == nil then currentProt = 0 else currentProt = protLevels[currentProt] end
    local moduleProt = mw.title.new(module).protectionLevels["edit"][1]
    for i, module in ipairs(modules) do
    if moduleProt == nil then moduleProt = 0 else moduleProt = protLevels[moduleProt] end
    local moduleProt = mw.title.new(module).protectionLevels["edit"][1]
    if moduleProt < currentProt then
    if moduleProt == nil then moduleProt = 0 else moduleProt = protLevels[moduleProt] end
    cats[#cats + 1] = "Templates using under-protected Lua modules"
    if moduleProt < currentProt then
    break
    cats[#cats + 1] = "Templates using under-protected Lua modules"
    break
    end
    end
    end
    end
    end
    end
    end
    for i, cat in ipairs(cats) do
    for i, cat in ipairs(cats) do
    cats[i] = string.format('[[Category:%s]]', cat)
    cats[i] = string.format('[[Category:%s]]', cat)