Module:Lua banner: Difference between revisions

protect against "mw.title.new()" returns "nil"
No edit summary
en>Uzume
(protect against "mw.title.new()" returns "nil")
Line 35: Line 35:
moduleLinks[i] = string.format('[[:%s]]', module)
moduleLinks[i] = string.format('[[:%s]]', module)
local maybeSandbox = mw.title.new(module .. '/sandbox')
local maybeSandbox = mw.title.new(module .. '/sandbox')
if maybeSandbox.exists then
if maybeSandbox and maybeSandbox.exists then
moduleLinks[i] = moduleLinks[i] .. string.format(' ([[:%s|sandbox]])', maybeSandbox.fullText)
moduleLinks[i] = moduleLinks[i] .. string.format(' ([[:%s|sandbox]])', maybeSandbox.fullText)
end
end
Line 105: Line 105:
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"] and titleObj.protectionLevels["edit"][1] or nil
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
Line 111: Line 111:
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.protectionLevels["edit"] and moduleTitle.protectionLevels["edit"][1] or nil
local moduleProt = moduleTitle and moduleTitle.protectionLevels["edit"][1]
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
Anonymous user