Zum Inhalt springen

Modul:Protection banner: Unterschied zwischen den Versionen

add a function to get the protection data, and start work on a main function
(merge the reasons and banners tables)
(add a function to get the protection data, and start work on a main function)
Zeile 166: Zeile 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


Zeile 182: Zeile 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)
Anonymer Benutzer