Changes
Jump to navigation
Jump to search
local theProtectionStatus = ProtectionStatus:new(args, title)
validate expiry and protection dates
local yesno = require('Module:Yesno')
-- Lazily initialise modules and objects we don't always need.local mArguments, mMessageBox ---------------------------------------------------------------------------------- ProtectionStatus class-------------------------------------------------------------------------------- local ProtectionStatus = class('ProtectionStatus') function ProtectionStatus:initialize(args, titleObj) -- Set action do local actions = { create = true, edit = true, move = true, autoreview = true } if args.action and actions[args.action] then self._action = args.action else self._action = 'edit' end end -- Set level do local level = mProtectionLevel._main(self._action, titleObj) if level == 'accountcreator' then -- Lump titleblacklisted pages in with template-protected pages, -- since templateeditors can do both. level = 'templateeditor' end self._level = level or '*' end -- Set other params self._reason = args.reason self._expiry = args.expiry or 'indef' self._protectionDate = args.dateend function ProtectionStatus:getAction() return self._actionend function ProtectionStatus:getLevel() return self._levelend function ProtectionStatus:getReason() return self._reasonend function ProtectionStatus:getExpiry() return self._expiryend function ProtectionStatus:getProtectionDate() return self._protectionDateendlang
--------------------------------------------------------------------------------
function Config:getMessage(key)
return self._msg[key]
end
--------------------------------------------------------------------------------
-- ProtectionStatus class
--------------------------------------------------------------------------------
local ProtectionStatus = class('ProtectionStatus')
function ProtectionStatus:initialize(args, configObj, titleObj)
-- Set action
do
local actions = {
create = true,
edit = true,
move = true,
autoreview = true
}
if args.action and actions[args.action] then
self._action = args.action
else
self._action = 'edit'
end
end
-- Set level
do
local level = mProtectionLevel._main(self._action, titleObj)
if level == 'accountcreator' then
-- Lump titleblacklisted pages in with template-protected pages,
-- since templateeditors can do both.
level = 'templateeditor'
end
self._level = level or '*'
end
-- Validation function for the expiry and the protection date
local function validateDate(date, dateType)
lang = lang or mw.language.getContentLanguage()
local success, expiry = pcall(lang.formatDate, lang, 'U', args.expiry)
expiry = tonumber(expiry)
if success and expiry then
return expiry
else
return string.format(
'<strong class="error">Error: invalid %s ("%s")</strong>',
dateType,
tostring(args.expiry)
)
end
end
-- Set expiry
if args.expiry then
local indefStrings = configObj:getConfigTable('indefStrings')
if indefStrings[args.expiry] then
self._expiry = 'indef'
elseif type(args.expiry) == 'number' then
self._expiry = args.expiry
else
self._expiry = validateDate(args.expiry, 'expiry date')
end
end
-- Set other params
self._reason = args.reason
self._protectionDate = validateDate(args.date, 'protection date')
end
function ProtectionStatus:getAction()
return self._action
end
function ProtectionStatus:getLevel()
return self._level
end
function ProtectionStatus:getReason()
return self._reason
end
function ProtectionStatus:getExpiry()
return self._expiry
end
function ProtectionStatus:getProtectionDate()
return self._protectionDate
end
-- parameter $5
local protectionDate = self._protectionStatusObj:getProtectionDate()
if type(protectionDate ) == 'number' then local lang date = mwos.language.getContentLanguagedate('%e %B %Y', protectionDate) local success, date = pcalldate:gsub( lang.formatDate'^ ', lang, 'j F Y') -- The %e option replaces leading zeroes with spaces, protectionDatebut we don't want spaces. ) if success and return date then return date else endreturn protectionDate
end
end
-- Get data objects
local theConfig = Config:new()
local theProtectionStatus = ProtectionStatus:new(args, theConfig, title)
local ret = {}