Jump to content

Module:Lua banner: Difference between revisions

pc>Uzume
protect against "mw.title.new()" returns "nil"
Peoplesconcord (talk | contribs)
m 1 revision imported
Tags: Mobile edit Mobile web edit
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
-- This module implements the {{lua}} template.
-- This module implements the {{lua}} template.
local yesno = require('Module:Yesno')
local yesno = require('Module:Yesno')
local mList = require('Module:List')
local mList = require('Module:List')
Line 76: Line 77:
testcases = true
testcases = true
}
}
if not subpageBlacklist[titleObj.subpageText] then
if not subpageBlacklist[titleObj.subpageText] then
local protCatName
local protCatName
Line 95: Line 97:
protCatName = "Modules depending on under-protected modules"
protCatName = "Modules depending on under-protected modules"
end
end
if not args.noprotcat and protCatName then
if not args.noprotcat and protCatName then
local protLevels = {
local protLevels = {
Line 104: Line 107:
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.
-- check protection level only if page exists
currentProt = titleObj.protectionLevels["edit"][1]
if titleObj.protectionLevels and titleObj.protectionLevels["edit"] then
currentProt = titleObj.protectionLevels["edit"][1]
end
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
if module ~= "WP:libraryUtil" then
if module ~= "WP:libraryUtil" then
local moduleTitle = mw.title.new(module)
local moduleTitle = mw.title.new(module)
local moduleProt = moduleTitle and moduleTitle.protectionLevels["edit"][1]
local moduleProt
if moduleTitle and moduleTitle.protectionLevels and moduleTitle.protectionLevels["edit"] then
moduleProt = moduleTitle.protectionLevels["edit"][1]
end
if moduleProt == nil then moduleProt = 0 else moduleProt = protLevels[moduleProt] end
if moduleProt == nil then moduleProt = 0 else moduleProt = protLevels[moduleProt] end
if moduleProt < currentProt then
if moduleProt < currentProt then
Line 121: Line 130:
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)
Cookies help us deliver our services. By using our services, you agree to our use of cookies.