Module:Lua banner: Difference between revisions

Content added Content deleted
(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
if not args.noprotcat then
local protLevels = {
autoconfirmed = 1,
local protLevels = {
extendedconfirmed = 2,
autoconfirmed = 1,
templateeditor = 3,
extendedconfirmed = 2,
sysop = 4
templateeditor = 3,
sysop = 4
}
}
local currentProt
local currentProt
if titleObj.id ~= 0 then
if titleObj.id ~= 0 then
-- id is 0 (page does not exist) if am previewing before creating a template.
-- id is 0 (page does not exist) if am previewing before creating a template.
currentProt = titleObj.protectionLevels["edit"][1]
currentProt = titleObj.protectionLevels["edit"][1]
end
end
if currentProt == nil then currentProt = 0 else currentProt = protLevels[currentProt] end
if currentProt == nil then currentProt = 0 else currentProt = protLevels[currentProt] end
for i, module in ipairs(modules) do
for i, module in ipairs(modules) do
local moduleProt = mw.title.new(module).protectionLevels["edit"][1]
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
if moduleProt < currentProt then
cats[#cats + 1] = "Templates using under-protected Lua modules"
cats[#cats + 1] = "Templates using under-protected Lua modules"
break
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)