Module:Protection banner: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(merge the reasons and banners tables) |
(add a function to get the protection data, and start work on a main function) |
||
Line 166: | Line 166: | ||
-- Initialise necessary modules. |
-- Initialise necessary modules. |
||
local mArguments = require('Module:Arguments') |
local mArguments = require('Module:Arguments') |
||
local mProtectionLevel = require('Module:Effective protection level') |
|||
local mMessageBox -- only needs to be loaded if we are outputting a banner, so lazily initialise |
local mMessageBox -- only needs to be loaded if we are outputting a banner, so lazily initialise |
||
Line 182: | Line 183: | ||
local p = {} |
local p = {} |
||
function p.main(frame) |
|||
local args = mArguments.getArgs(frame) |
|||
return p._main(args) |
|||
end |
|||
function p._main(args) |
|||
local title |
|||
if args.page then |
|||
title = mw.title.new(args.page) |
|||
else |
|||
title = mw.title.getCurrentTitle() |
|||
end |
|||
local protectionData = p.getProtectionData(title) |
|||
end |
|||
function p.getProtectionData(title) |
|||
-- Gets a table containing protection data for the given title. The data |
|||
-- is cached using a metatable, and so can be indexed as needed without |
|||
-- a performance loss. |
|||
local protectionData = {} |
|||
local actions = { |
|||
create = true, |
|||
edit = true, |
|||
move = true |
|||
} |
|||
setmetatable(protectionData, { |
|||
__index = function (t, key) |
|||
local level |
|||
if actions[key] then |
|||
level = mProtectionLevel.main(key, title) |
|||
if level == 'accountcreator' then |
|||
-- Lump titleblacklisted pages in with template-protected pages, |
|||
-- since templateeditors can do both. |
|||
level = 'templateeditor' |
|||
end |
|||
elseif key == 'pc' then |
|||
level = mProtectionLevel.pending(title) |
|||
end |
|||
protectionData[key] = level |
|||
return level |
|||
end |
|||
}) |
|||
return protectionData |
|||
end |
|||
function p.getPagetype(ns) |
function p.getPagetype(ns) |