More actions
Content deleted Content added
simplify further |
config isn't an object anymore |
||
Line 67: | Line 67: | ||
} |
} |
||
function Protection:initialize(args, |
function Protection:initialize(args, cfg, titleObj) |
||
self. |
self._cfg = cfg |
||
self._titleObj = titleObj |
self._titleObj = titleObj |
||
Line 98: | Line 98: | ||
-- Set expiry |
-- Set expiry |
||
if args.expiry then |
if args.expiry then |
||
if |
if cfg.indefStrings[args.expiry] then |
||
self.expiry = 'indef' |
self.expiry = 'indef' |
||
elseif type(args.expiry) == 'number' then |
elseif type(args.expiry) == 'number' then |
||
Line 122: | Line 122: | ||
self.bannerConfig = {} |
self.bannerConfig = {} |
||
local configTables = {} |
local configTables = {} |
||
if |
if cfg.banners[self.action] then |
||
configTables[#configTables + 1] = |
configTables[#configTables + 1] = cfg.banners[self.action][self.reason] |
||
end |
end |
||
if |
if cfg.defaultBanners[self.action] then |
||
configTables[#configTables + 1] = |
configTables[#configTables + 1] = cfg.defaultBanners[self.action][self.level] |
||
configTables[#configTables + 1] = |
configTables[#configTables + 1] = cfg.defaultBanners[self.action].default |
||
end |
end |
||
configTables[#configTables + 1] = |
configTables[#configTables + 1] = cfg.masterBanner |
||
for i, field in ipairs(self.bannerConfigFields) do |
for i, field in ipairs(self.bannerConfigFields) do |
||
for j, t in ipairs(configTables) do |
for j, t in ipairs(configTables) do |
||
Line 146: | Line 146: | ||
function Protection:makeProtectionCategory() |
function Protection:makeProtectionCategory() |
||
local |
local cfg = self._cfg |
||
local titleObj = self._titleObj |
local titleObj = self._titleObj |
||
Line 166: | Line 166: | ||
do |
do |
||
local namespace = titleObj.namespace |
local namespace = titleObj.namespace |
||
local categoryNamespaces = |
local categoryNamespaces = cfg.categoryNamespaceKeys |
||
nskey = categoryNamespaces[namespace] |
nskey = categoryNamespaces[namespace] |
||
if not nskey and namespace % 2 == 1 then |
if not nskey and namespace % 2 == 1 then |
||
Line 201: | Line 201: | ||
local configOrder = {} |
local configOrder = {} |
||
do |
do |
||
local reasonsWithNamespacePriority = |
local reasonsWithNamespacePriority = cfg.reasonsWithNamespacePriority |
||
local namespaceFirst = reason and reasonsWithNamespacePriority[reason] or false |
local namespaceFirst = reason and reasonsWithNamespacePriority[reason] or false |
||
for propertiesKey, t in pairs(properties) do |
for propertiesKey, t in pairs(properties) do |
||
Line 270: | Line 270: | ||
-- pos field in the property table. |
-- pos field in the property table. |
||
--]] |
--]] |
||
local cats = |
local cats = cfg.protectionCategories |
||
local cat |
local cat |
||
for i = 1, 2^noActive do |
for i = 1, 2^noActive do |
||
Line 299: | Line 299: | ||
function Protection:makeExpiryCategory() |
function Protection:makeExpiryCategory() |
||
local reasonsWithoutExpiryCheck = self. |
local reasonsWithoutExpiryCheck = self._cfg.reasonsWithoutExpiryCheck |
||
local expiryCheckActions = self. |
local expiryCheckActions = self._cfg.expiryCheckActions |
||
local cat |
local cat |
||
Line 308: | Line 308: | ||
and not reasonsWithoutExpiryCheck[self.reason] |
and not reasonsWithoutExpiryCheck[self.reason] |
||
then |
then |
||
cat = self. |
cat = self._cfg.msg['tracking-category-expiry'] |
||
end |
end |
||
return makeCategoryLink(cat) |
return makeCategoryLink(cat) |
||
Line 314: | Line 314: | ||
function Protection:makeErrorCategory() |
function Protection:makeErrorCategory() |
||
local |
local cfg = self._cfg |
||
local cat |
local cat |
||
if not self:isProtected() |
if not self:isProtected() |
||
or type(self.expiry) == 'number' and self.expiry < os.time() |
or type(self.expiry) == 'number' and self.expiry < os.time() |
||
then |
then |
||
cat = |
cat = cfg.msg['tracking-category-incorrect'] |
||
end |
end |
||
return makeCategoryLink(cat) |
return makeCategoryLink(cat) |
||
Line 325: | Line 325: | ||
function Protection:makeTemplateCategory() |
function Protection:makeTemplateCategory() |
||
local |
local cfg = self._cfg |
||
local titleObj = self._titleObj |
local titleObj = self._titleObj |
||
Line 335: | Line 335: | ||
) |
) |
||
then |
then |
||
cat = |
cat = cfg.msg['tracking-category-template'] |
||
end |
end |
||
return makeCategoryLink(cat) |
return makeCategoryLink(cat) |
||
Line 346: | Line 346: | ||
local Blurb = class('Blurb') |
local Blurb = class('Blurb') |
||
function Blurb:initialize( |
function Blurb:initialize(cfg, protectionObj, titleObj) |
||
self. |
self._cfg = cfg |
||
self._protectionObj = protectionObj |
self._protectionObj = protectionObj |
||
self._bannerConfig = protectionObj.bannerConfig |
self._bannerConfig = protectionObj.bannerConfig |
||
Line 378: | Line 378: | ||
function Blurb:_getExpandedMessage(msg) |
function Blurb:_getExpandedMessage(msg) |
||
local msg = self. |
local msg = self._cfg.msg[msg] |
||
return self:_substituteParameters(msg) |
return self:_substituteParameters(msg) |
||
end |
end |
||
Line 553: | Line 553: | ||
function Blurb:_makeImageLinkParameter() |
function Blurb:_makeImageLinkParameter() |
||
local imageLinks = self. |
local imageLinks = self._cfg.imageLinks |
||
local action = self._protectionObj.action |
local action = self._protectionObj.action |
||
local level = self._protectionObj.level |
local level = self._protectionObj.level |
||
Line 586: | Line 586: | ||
function Blurb:_makePagetypeParameter() |
function Blurb:_makePagetypeParameter() |
||
local pagetypes = self. |
local pagetypes = self._cfg.pagetypes |
||
local namespace = self._titleObj.namespace |
local namespace = self._titleObj.namespace |
||
return pagetypes[namespace] or pagetypes.default or error('no default pagetype defined') |
return pagetypes[namespace] or pagetypes.default or error('no default pagetype defined') |
||
Line 592: | Line 592: | ||
function Blurb:_makeProtectionBlurbParameter() |
function Blurb:_makeProtectionBlurbParameter() |
||
local protectionBlurbs = self. |
local protectionBlurbs = self._cfg.protectionBlurbs |
||
local action = self._protectionObj.action |
local action = self._protectionObj.action |
||
local level = self._protectionObj.level |
local level = self._protectionObj.level |
||
Line 618: | Line 618: | ||
function Blurb:_makeProtectionLevelParameter() |
function Blurb:_makeProtectionLevelParameter() |
||
local protectionLevels = self. |
local protectionLevels = self._cfg.protectionLevels |
||
local action = self._protectionObj.action |
local action = self._protectionObj.action |
||
local level = self._protectionObj.level |
local level = self._protectionObj.level |
||
Line 738: | Line 738: | ||
local BannerTemplate = class('BannerTemplate') |
local BannerTemplate = class('BannerTemplate') |
||
function BannerTemplate:initialize( |
function BannerTemplate:initialize(cfg) |
||
self. |
self._cfg = cfg |
||
end |
end |
||
Line 761: | Line 761: | ||
-- Fully protected modules and templates get the special red "indef" |
-- Fully protected modules and templates get the special red "indef" |
||
-- padlock. |
-- padlock. |
||
self._imageFilename = self. |
self._imageFilename = self._cfg.msg['image-filename-indef'] |
||
return nil |
return nil |
||
end |
end |
||
-- Deal with regular protection types. |
-- Deal with regular protection types. |
||
local images = self. |
local images = self._cfg.images |
||
if images[action] then |
if images[action] then |
||
if images[action][level] then |
if images[action][level] then |
||
Line 790: | Line 790: | ||
function BannerTemplate:renderImage() |
function BannerTemplate:renderImage() |
||
local filename = self._imageFilename |
local filename = self._imageFilename |
||
or self. |
or self._cfg.msg['image-filename-default'] |
||
or 'Transparent.gif' |
or 'Transparent.gif' |
||
return newFileLink(filename) |
return newFileLink(filename) |
||
Line 806: | Line 806: | ||
local Banner = BannerTemplate:subclass('Banner') |
local Banner = BannerTemplate:subclass('Banner') |
||
function Banner:initialize( |
function Banner:initialize(cfg) |
||
BannerTemplate.initialize(self, |
BannerTemplate.initialize(self, cfg) |
||
self:setImageWidth(40) |
self:setImageWidth(40) |
||
end |
end |
||
Line 849: | Line 849: | ||
local Padlock = BannerTemplate:subclass('Padlock') |
local Padlock = BannerTemplate:subclass('Padlock') |
||
function Padlock:initialize( |
function Padlock:initialize(cfg) |
||
BannerTemplate.initialize(self, |
BannerTemplate.initialize(self, cfg) |
||
self:setImageWidth(20) |
self:setImageWidth(20) |
||
end |
end |
||
Line 882: | Line 882: | ||
local ProtectionBanner = {} |
local ProtectionBanner = {} |
||
function ProtectionBanner.exportToWiki(frame, |
function ProtectionBanner.exportToWiki(frame, cfg, titleObj) |
||
mArguments = mArguments or require('Module:Arguments') |
mArguments = mArguments or require('Module:Arguments') |
||
local args = mArguments.getArgs(frame) |
local args = mArguments.getArgs(frame) |
||
return ProtectionBanner.exportToLua(args, |
return ProtectionBanner.exportToLua(args, cfg, titleObj) |
||
end |
end |
||
function ProtectionBanner.exportToLua(args, |
function ProtectionBanner.exportToLua(args, cfg, titleObj) |
||
cfg = cfg or mw.loadData('Module:Protection banner/config') |
|||
titleObj = titleObj or mw.title.getCurrentTitle() |
titleObj = titleObj or mw.title.getCurrentTitle() |
||
-- Initialise protection and blurb objects |
-- Initialise protection and blurb objects |
||
local protectionObj = Protection:new(args, |
local protectionObj = Protection:new(args, cfg, titleObj) |
||
local blurbObj = Blurb:new( |
local blurbObj = Blurb:new(cfg, protectionObj, titleObj) |
||
blurbObj:setDeletionDiscussionPage(args.xfd) |
blurbObj:setDeletionDiscussionPage(args.xfd) |
||
blurbObj:setUsername(args.user) |
blurbObj:setUsername(args.user) |
||
Line 907: | Line 907: | ||
local bannerObj |
local bannerObj |
||
if isPadlock then |
if isPadlock then |
||
bannerObj = Padlock:new( |
bannerObj = Padlock:new(cfg) |
||
else |
else |
||
bannerObj = Banner:new( |
bannerObj = Banner:new(cfg) |
||
end |
end |
||