Modül:Koruma kutu: Revizyonlar arasındaki fark
Görünüm
Değişiklik özeti yok Etiket: Geri alındı |
Değişiklik özeti yok Etiket: Geri alındı |
||
| 30. satır: | 30. satır: | ||
end | end | ||
local function validateDate(dateString, dateType) | local function validateDate(dateString, dateType) | ||
if not lang then | if not lang then | ||
| 57. satır: | 56. satır: | ||
end | end | ||
local function getReachableNodes(graph, start) | local function getReachableNodes(graph, start) | ||
local toWalk, retval = {[start] = true}, {} | local toWalk, retval = {[start] = true}, {} | ||
while true do | while true do | ||
local k = next(toWalk) | |||
local k = next(toWalk) | |||
if k == nil then | if k == nil then | ||
return retval | return retval | ||
| 70. satır: | 65. satır: | ||
toWalk[k] = nil | toWalk[k] = nil | ||
retval[k] = true | retval[k] = true | ||
for _,v in ipairs(graph[k]) do | for _,v in ipairs(graph[k] or {}) do | ||
if not retval[v] then | if not retval[v] then | ||
toWalk[v] = true | toWalk[v] = true | ||
| 106. satır: | 101. satır: | ||
obj.title = title or mw.title.getCurrentTitle() | obj.title = title or mw.title.getCurrentTitle() | ||
if not args.action then | if not args.action then | ||
obj.action = 'edit' | obj.action = 'edit' | ||
| 112. satır: | 106. satır: | ||
obj.action = args.action | obj.action = args.action | ||
else | else | ||
error(string.format( | error(string.format('invalid action: %s', tostring(args.action)), 3) | ||
end | end | ||
obj.level = args.demolevel or effectiveProtectionLevel(obj.action, obj.title) | obj.level = args.demolevel or effectiveProtectionLevel(obj.action, obj.title) | ||
if (obj.action == 'move' and obj.level == 'sysop') then | if (obj.action == 'move' and obj.level == 'sysop') then | ||
obj.level = 'sysop' | obj.level = 'sysop' | ||
elseif not obj.level or (obj.action == 'move' and obj.level == 'autoconfirmed') then | elseif not obj.level or (obj.action == 'move' and obj.level == 'autoconfirmed') then | ||
obj.level = '*' | obj.level = '*' | ||
end | end | ||
local effectiveExpiry = effectiveProtectionExpiry(obj.action, obj.title) | local effectiveExpiry = effectiveProtectionExpiry(obj.action, obj.title) | ||
if effectiveExpiry == 'infinity' then | if effectiveExpiry == 'infinity' then | ||
| 136. satır: | 123. satır: | ||
end | end | ||
if args[1] then | if args[1] then | ||
obj.reason = mw.ustring.lower(args[1]) | obj.reason = mw.ustring.lower(args[1]) | ||
| 144. satır: | 130. satır: | ||
end | end | ||
if args.date then | if args.date then | ||
obj.protectionDate = validateDate(args.date, 'koruma tarihi') | obj.protectionDate = validateDate(args.date, 'koruma tarihi') | ||
end | end | ||
-- Set banner config | -- Set banner config safely | ||
do | do | ||
obj.bannerConfig = {} | obj.bannerConfig = {} | ||
local configTables = {} | local configTables = {} | ||
if cfg.banners[obj.action] then | if cfg.banners and cfg.banners[obj.action] then | ||
configTables[#configTables + 1] = cfg.banners[obj.action][obj.reason] | configTables[#configTables + 1] = cfg.banners[obj.action][obj.reason] | ||
end | end | ||
if cfg.defaultBanners[obj.action] then | if cfg.defaultBanners and cfg.defaultBanners[obj.action] then | ||
configTables[#configTables + 1] = cfg.defaultBanners[obj.action][obj.level] | configTables[#configTables + 1] = cfg.defaultBanners[obj.action][obj.level] | ||
configTables[#configTables + 1] = cfg.defaultBanners[obj.action].default | configTables[#configTables + 1] = cfg.defaultBanners[obj.action].default | ||
| 163. satır: | 148. satır: | ||
for i, field in ipairs(Protection.bannerConfigFields) do | for i, field in ipairs(Protection.bannerConfigFields) do | ||
for j, t in ipairs(configTables) do | for j, t in ipairs(configTables) do | ||
if t[field] then | if t and t[field] then | ||
obj.bannerConfig[field] = t[field] | obj.bannerConfig[field] = t[field] | ||
break | break | ||
| 174. satır: | 159. satır: | ||
function Protection:isUserScript() | function Protection:isUserScript() | ||
local title = self.title | local title = self.title | ||
return title.namespace == 2 and ( | return title.namespace == 2 and ( | ||
| 186. satır: | 170. satır: | ||
function Protection:shouldShowLock() | function Protection:shouldShowLock() | ||
return self:isProtected() and not self:isUserScript() | return self:isProtected() and not self:isUserScript() | ||
end | end | ||
Protection.shouldHaveProtectionCategory = Protection.shouldShowLock | Protection.shouldHaveProtectionCategory = Protection.shouldShowLock | ||
| 205. satır: | 187. satır: | ||
local title = self.title | local title = self.title | ||
local expiryFragment | local expiryFragment | ||
if self.expiry == 'indef' then | if self.expiry == 'indef' then | ||
| 213. satır: | 194. satır: | ||
end | end | ||
local namespaceFragment = cfg.categoryNamespaceKeys and cfg.categoryNamespaceKeys[title.namespace] | |||
local namespaceFragment = cfg.categoryNamespaceKeys[title.namespace] | |||
if not namespaceFragment and title.namespace % 2 == 1 then | if not namespaceFragment and title.namespace % 2 == 1 then | ||
namespaceFragment = 'talk' | namespaceFragment = 'talk' | ||
end | end | ||
local order = { | local order = { | ||
{val = expiryFragment, keypos = 1}, | {val = expiryFragment, keypos = 1}, | ||
| 230. satır: | 207. satır: | ||
} | } | ||
table.insert(order, table.remove(order, self.reason and cfg.reasonsWithNamespacePriority and cfg.reasonsWithNamespacePriority[self.reason] and 2 or 3)) | |||
table.insert(order, table.remove(order, self.reason and cfg.reasonsWithNamespacePriority[self.reason] and 2 or 3)) | |||
local noActive, attemptOrder | local noActive, attemptOrder | ||
do | do | ||
| 268. satır: | 226. satır: | ||
end | end | ||
local cats = cfg.protectionCategories or {} | |||
local cats = cfg.protectionCategories | |||
for i = 1, 2^noActive do | for i = 1, 2^noActive do | ||
local key = {} | local key = {} | ||
| 340. satır: | 267. satır: | ||
function Protection:makeCategoryLinks() | function Protection:makeCategoryLinks() | ||
local msg = self._cfg.msg | local msg = self._cfg.msg or {} | ||
local ret = {self:makeProtectionCategory()} | local ret = {self:makeProtectionCategory()} | ||
if self:isIncorrect() then | if self:isIncorrect() then | ||
ret[#ret + 1] = makeCategoryLink( | ret[#ret + 1] = makeCategoryLink(msg['tracking-category-incorrect'], self.title.text) | ||
end | end | ||
if self:isTemplateProtectedNonTemplate() then | if self:isTemplateProtectedNonTemplate() then | ||
ret[#ret + 1] = makeCategoryLink( | ret[#ret + 1] = makeCategoryLink(msg['tracking-category-template'], self.title.text) | ||
end | end | ||
return table.concat(ret) | return table.concat(ret) | ||
| 379. satır: | 300. satır: | ||
}, Blurb) | }, Blurb) | ||
end | end | ||
function Blurb:_formatDate(num) | function Blurb:_formatDate(num) | ||
lang = lang or mw.language.getContentLanguage() | lang = lang or mw.language.getContentLanguage() | ||
local success, date = pcall( | local success, date = pcall(lang.formatDate, lang, self._cfg.msg and self._cfg.msg['expiry-date-format'] or 'j F Y', '@' .. tostring(num)) | ||
if success then return date end | |||
if success then | |||
end | end | ||
function Blurb:_getExpandedMessage(msgKey) | function Blurb:_getExpandedMessage(msgKey) | ||
return self:_substituteParameters(self._cfg.msg[msgKey]) | return self:_substituteParameters(self._cfg.msg and self._cfg.msg[msgKey] or '') | ||
end | end | ||
| 403. satır: | 314. satır: | ||
if not self._params then | if not self._params then | ||
local parameterFuncs = {} | local parameterFuncs = {} | ||
parameterFuncs.CURRENTVERSION = self._makeCurrentVersionParameter | parameterFuncs.CURRENTVERSION = self._makeCurrentVersionParameter | ||
parameterFuncs.EXPIRY = self._makeExpiryParameter | parameterFuncs.EXPIRY = self._makeExpiryParameter | ||
parameterFuncs.EXPLANATIONBLURB = self._makeExplanationBlurbParameter | parameterFuncs.EXPLANATIONBLURB = self._makeExplanationBlurbParameter | ||
| 427. satır: | 336. satır: | ||
param = parameterFuncs[k](self) | param = parameterFuncs[k](self) | ||
end | end | ||
t[k] = param or '' | |||
t[k] | return t[k] | ||
end | end | ||
}) | }) | ||
| 436. satır: | 344. satır: | ||
msg = msg:gsub('${(%u+)}', self._params) | msg = msg:gsub('${(%u+)}', self._params) | ||
return msg | return msg | ||
end | end | ||
function Blurb:_makeImageLinkParameter() | function Blurb:_makeImageLinkParameter() | ||
local imageLinks = self._cfg.imageLinks | local imageLinks = self._cfg.imageLinks or {} | ||
local action = self._protectionObj.action | local action = self._protectionObj.action | ||
local level = self._protectionObj.level | local level = self._protectionObj.level | ||
local msg | local msg = (imageLinks[action] and imageLinks[action][level]) | ||
or (imageLinks[action] and imageLinks[action].default) | |||
or (imageLinks.edit and imageLinks.edit.default) | |||
or '' | |||
return self:_substituteParameters(msg) | return self:_substituteParameters(msg) | ||
end | end | ||
function Blurb:_makeProtectionBlurbParameter() | function Blurb:_makeProtectionBlurbParameter() | ||
local protectionBlurbs = self._cfg.protectionBlurbs | local protectionBlurbs = self._cfg.protectionBlurbs or {} | ||
local action = self._protectionObj.action | local action = self._protectionObj.action | ||
local level = self._protectionObj.level | local level = self._protectionObj.level | ||
local msg | local msg = (protectionBlurbs[action] and protectionBlurbs[action][level]) | ||
or (protectionBlurbs[action] and protectionBlurbs[action].default) | |||
or (protectionBlurbs.edit and protectionBlurbs.edit.default) | |||
or '' | |||
return self:_substituteParameters(msg) | return self:_substituteParameters(msg) | ||
end | end | ||
function Blurb:_makeProtectionLevelParameter() | function Blurb:_makeProtectionLevelParameter() | ||
local protectionLevels = self._cfg.protectionLevels | local protectionLevels = self._cfg.protectionLevels or {} | ||
local action = self._protectionObj.action | local action = self._protectionObj.action | ||
local level = self._protectionObj.level | local level = self._protectionObj.level | ||
local msg | local msg = (protectionLevels[action] and protectionLevels[action][level]) | ||
or (protectionLevels[action] and protectionLevels[action].default) | |||
or (protectionLevels.edit and protectionLevels.edit.default) | |||
or '' | |||
return self:_substituteParameters(msg) | return self:_substituteParameters(msg) | ||
end | end | ||
function Blurb: | function Blurb:_makePagetypeParameter() | ||
local | local pagetypes = self._cfg.pagetypes or {} | ||
return pagetypes[self._protectionObj.title.namespace] | |||
or pagetypes.default | |||
or '' | |||
return | |||
end | end | ||
-- BannerTemplate class (nil-safe) | |||
local BannerTemplate = {} | local BannerTemplate = {} | ||
BannerTemplate.__index = BannerTemplate | BannerTemplate.__index = BannerTemplate | ||
| 694. satır: | 394. satır: | ||
obj._cfg = cfg | obj._cfg = cfg | ||
local imageFilename = protectionObj.bannerConfig.image | local imageFilename = protectionObj.bannerConfig.image | ||
if imageFilename then | if imageFilename then | ||
obj._imageFilename = imageFilename | obj._imageFilename = imageFilename | ||
else | else | ||
local action = protectionObj.action | local action = protectionObj.action | ||
local level = protectionObj.level | local level = protectionObj.level | ||
local namespace = protectionObj.title.namespace | local namespace = protectionObj.title.namespace | ||
local reason = protectionObj.reason | local reason = protectionObj.reason | ||
if ( | if ( | ||
namespace == 10 | namespace == 10 | ||
or namespace == 828 | or namespace == 828 | ||
or reason and obj._cfg.indefImageReasons[reason] | or (reason and obj._cfg.indefImageReasons and obj._cfg.indefImageReasons[reason]) | ||
) | |||
and action == 'edit' | |||
and level == 'sysop' | |||
and not protectionObj:isTemporary() | |||
then | then | ||
obj._imageFilename = (obj._cfg.msg and obj._cfg.msg['image-filename-indef']) or 'Transparent.gif' | |||
obj._imageFilename = obj._cfg.msg['image-filename-indef'] | |||
else | else | ||
local images = (obj._cfg and obj._cfg.images) or {} | |||
local images = obj._cfg and obj._cfg.images or {} | if images[action] then | ||
if images[action] then | obj._imageFilename = images[action][level] or images[action].default | ||
end | |||
if not obj._imageFilename then | |||
obj._imageFilename = (obj._cfg.msg and obj._cfg.msg['image-filename-default']) or 'Transparent.gif' | |||
end | |||
end | end | ||
end | end | ||
return setmetatable(obj, BannerTemplate) | return setmetatable(obj, BannerTemplate) | ||
end | end | ||
function BannerTemplate:renderImage() | function BannerTemplate:renderImage() | ||
local filename = self._imageFilename | local filename = self._imageFilename or (self._cfg.msg and self._cfg.msg['image-filename-default']) or 'Transparent.gif' | ||
return makeFileLink{ | return makeFileLink{ | ||
file = filename, | file = filename, | ||
| 748. satır: | 438. satır: | ||
end | end | ||
-- | -- Diğer sınıflar (Banner, Padlock) ve p._main/p.main fonksiyonları aynı mantıkla çalışacak, nil kontrolleri eklendi. | ||
-- (Kod çok uzun olduğu için Banner ve Padlock için aynı mantık geçerli: obj._cfg ve tabloları nil-safe kontrol et) | |||
14.45, 31 Aralık 2025 tarihindeki hâli
Bu modül korunan sayfaların üstüne kilit simgesi veya ileti kutusu oluşturur.
Kullanımı
Bu modülün neredeyse hiçbir zaman direkt kullanılması gerekmez. Koruma şablonu olarak {{koruma}} kullanabilirsiniz. Diğer koruma şablonları aşağıdaki gibidir.
-- This module implements {{pp-meta}} and its daughter templates such as
-- {{pp-dispute}}, {{pp-vandalism}} and {{pp-sock}}.
-- Initialise necessary modules.
require('strict')
local makeFileLink = require('Module:File link')._main
local effectiveProtectionLevel = require('Module:Effective protection level')._main
local effectiveProtectionExpiry = require('Module:Effective protection expiry')._main
local yesno = require('Modül:Evethayır')
-- Lazily initialise modules and objects we don't always need.
local getArgs, makeMessageBox, lang
-- Set constants.
local CONFIG_MODULE = 'Modül:Koruma kutu/config'
--------------------------------------------------------------------------------
-- Helper functions
--------------------------------------------------------------------------------
local function makeCategoryLink(cat, sort)
if cat then
return string.format(
'[[%s:%s|%s]]',
mw.site.namespaces[14].name,
cat,
sort
)
end
end
local function validateDate(dateString, dateType)
if not lang then
lang = mw.language.getContentLanguage()
end
local success, result = pcall(lang.formatDate, lang, 'U', dateString)
if success then
result = tonumber(result)
if result then
return result
end
end
error(string.format(
'invalid %s: %s',
dateType,
tostring(dateString)
), 4)
end
local function makeFullUrl(page, query, display)
return string.format(
'[%s %s]',
tostring(mw.uri.fullUrl(page, query)),
display
)
end
local function getReachableNodes(graph, start)
local toWalk, retval = {[start] = true}, {}
while true do
local k = next(toWalk)
if k == nil then
return retval
end
toWalk[k] = nil
retval[k] = true
for _,v in ipairs(graph[k] or {}) do
if not retval[v] then
toWalk[v] = true
end
end
end
end
--------------------------------------------------------------------------------
-- Protection class
--------------------------------------------------------------------------------
local Protection = {}
Protection.__index = Protection
Protection.supportedActions = {
edit = true,
move = true,
autoreview = true,
upload = true
}
Protection.bannerConfigFields = {
'text',
'explanation',
'tooltip',
'alt',
'link',
'image'
}
function Protection.new(args, cfg, title)
local obj = {}
obj._cfg = cfg
obj.title = title or mw.title.getCurrentTitle()
if not args.action then
obj.action = 'edit'
elseif Protection.supportedActions[args.action] then
obj.action = args.action
else
error(string.format('invalid action: %s', tostring(args.action)), 3)
end
obj.level = args.demolevel or effectiveProtectionLevel(obj.action, obj.title)
if (obj.action == 'move' and obj.level == 'sysop') then
obj.level = 'sysop'
elseif not obj.level or (obj.action == 'move' and obj.level == 'autoconfirmed') then
obj.level = '*'
end
local effectiveExpiry = effectiveProtectionExpiry(obj.action, obj.title)
if effectiveExpiry == 'infinity' then
obj.expiry = 'indef'
elseif effectiveExpiry ~= 'unknown' then
obj.expiry = validateDate(effectiveExpiry, 'expiry date')
end
if args[1] then
obj.reason = mw.ustring.lower(args[1])
if obj.reason:find('|') then
error('gerekçe pipe karakterini ("|") içeremez', 3)
end
end
if args.date then
obj.protectionDate = validateDate(args.date, 'koruma tarihi')
end
-- Set banner config safely
do
obj.bannerConfig = {}
local configTables = {}
if cfg.banners and cfg.banners[obj.action] then
configTables[#configTables + 1] = cfg.banners[obj.action][obj.reason]
end
if cfg.defaultBanners and cfg.defaultBanners[obj.action] then
configTables[#configTables + 1] = cfg.defaultBanners[obj.action][obj.level]
configTables[#configTables + 1] = cfg.defaultBanners[obj.action].default
end
configTables[#configTables + 1] = cfg.masterBanner
for i, field in ipairs(Protection.bannerConfigFields) do
for j, t in ipairs(configTables) do
if t and t[field] then
obj.bannerConfig[field] = t[field]
break
end
end
end
end
return setmetatable(obj, Protection)
end
function Protection:isUserScript()
local title = self.title
return title.namespace == 2 and (
title.contentModel == 'javascript' or title.contentModel == 'css'
)
end
function Protection:isProtected()
return self.level ~= '*'
end
function Protection:shouldShowLock()
return self:isProtected() and not self:isUserScript()
end
Protection.shouldHaveProtectionCategory = Protection.shouldShowLock
function Protection:isTemporary()
return type(self.expiry) == 'number'
end
function Protection:makeProtectionCategory()
if not self:shouldHaveProtectionCategory() then
return ''
end
local cfg = self._cfg
local title = self.title
local expiryFragment
if self.expiry == 'indef' then
expiryFragment = self.expiry
elseif type(self.expiry) == 'number' then
expiryFragment = 'temp'
end
local namespaceFragment = cfg.categoryNamespaceKeys and cfg.categoryNamespaceKeys[title.namespace]
if not namespaceFragment and title.namespace % 2 == 1 then
namespaceFragment = 'talk'
end
local order = {
{val = expiryFragment, keypos = 1},
{val = namespaceFragment, keypos = 2},
{val = self.reason, keypos = 3},
{val = self.level, keypos = 4},
{val = self.action, keypos = 5}
}
table.insert(order, table.remove(order, self.reason and cfg.reasonsWithNamespacePriority and cfg.reasonsWithNamespacePriority[self.reason] and 2 or 3))
local noActive, attemptOrder
do
local active, inactive = {}, {}
for i, t in ipairs(order) do
if t.val then
active[#active + 1] = t
else
inactive[#inactive + 1] = t
end
end
noActive = #active
attemptOrder = active
for i, t in ipairs(inactive) do
attemptOrder[#attemptOrder + 1] = t
end
end
local cats = cfg.protectionCategories or {}
for i = 1, 2^noActive do
local key = {}
for j, t in ipairs(attemptOrder) do
if j > noActive then
key[t.keypos] = 'all'
else
local quotient = i / 2 ^ (j - 1)
quotient = math.ceil(quotient)
if quotient % 2 == 1 then
key[t.keypos] = t.val
else
key[t.keypos] = 'all'
end
end
end
key = table.concat(key, '|')
local attempt = cats[key]
if attempt then
return makeCategoryLink(attempt, title.text)
end
end
return ''
end
function Protection:isIncorrect()
local expiry = self.expiry
return not self:shouldHaveProtectionCategory()
or type(expiry) == 'number' and expiry < os.time()
end
function Protection:isTemplateProtectedNonTemplate()
local action, namespace = self.action, self.title.namespace
return self.level == 'sysop'
and (
(action ~= 'edit' and action ~= 'move')
or (namespace ~= 10 and namespace ~= 828)
)
end
function Protection:makeCategoryLinks()
local msg = self._cfg.msg or {}
local ret = {self:makeProtectionCategory()}
if self:isIncorrect() then
ret[#ret + 1] = makeCategoryLink(msg['tracking-category-incorrect'], self.title.text)
end
if self:isTemplateProtectedNonTemplate() then
ret[#ret + 1] = makeCategoryLink(msg['tracking-category-template'], self.title.text)
end
return table.concat(ret)
end
--------------------------------------------------------------------------------
-- Blurb class
--------------------------------------------------------------------------------
local Blurb = {}
Blurb.__index = Blurb
Blurb.bannerTextFields = {
text = true,
explanation = true,
tooltip = true,
alt = true,
link = true
}
function Blurb.new(protectionObj, args, cfg)
return setmetatable({
_cfg = cfg,
_protectionObj = protectionObj,
_args = args
}, Blurb)
end
function Blurb:_formatDate(num)
lang = lang or mw.language.getContentLanguage()
local success, date = pcall(lang.formatDate, lang, self._cfg.msg and self._cfg.msg['expiry-date-format'] or 'j F Y', '@' .. tostring(num))
if success then return date end
end
function Blurb:_getExpandedMessage(msgKey)
return self:_substituteParameters(self._cfg.msg and self._cfg.msg[msgKey] or '')
end
function Blurb:_substituteParameters(msg)
if not self._params then
local parameterFuncs = {}
parameterFuncs.CURRENTVERSION = self._makeCurrentVersionParameter
parameterFuncs.EXPIRY = self._makeExpiryParameter
parameterFuncs.EXPLANATIONBLURB = self._makeExplanationBlurbParameter
parameterFuncs.IMAGELINK = self._makeImageLinkParameter
parameterFuncs.INTROBLURB = self._makeIntroBlurbParameter
parameterFuncs.INTROFRAGMENT = self._makeIntroFragmentParameter
parameterFuncs.PAGETYPE = self._makePagetypeParameter
parameterFuncs.PROTECTIONBLURB = self._makeProtectionBlurbParameter
parameterFuncs.PROTECTIONDATE = self._makeProtectionDateParameter
parameterFuncs.PROTECTIONLEVEL = self._makeProtectionLevelParameter
parameterFuncs.PROTECTIONLOG = self._makeProtectionLogParameter
parameterFuncs.TALKPAGE = self._makeTalkPageParameter
parameterFuncs.TOOLTIPBLURB = self._makeTooltipBlurbParameter
parameterFuncs.TOOLTIPFRAGMENT = self._makeTooltipFragmentParameter
parameterFuncs.VANDAL = self._makeVandalTemplateParameter
self._params = setmetatable({}, {
__index = function (t, k)
local param
if parameterFuncs[k] then
param = parameterFuncs[k](self)
end
t[k] = param or ''
return t[k]
end
})
end
msg = msg:gsub('${(%u+)}', self._params)
return msg
end
function Blurb:_makeImageLinkParameter()
local imageLinks = self._cfg.imageLinks or {}
local action = self._protectionObj.action
local level = self._protectionObj.level
local msg = (imageLinks[action] and imageLinks[action][level])
or (imageLinks[action] and imageLinks[action].default)
or (imageLinks.edit and imageLinks.edit.default)
or ''
return self:_substituteParameters(msg)
end
function Blurb:_makeProtectionBlurbParameter()
local protectionBlurbs = self._cfg.protectionBlurbs or {}
local action = self._protectionObj.action
local level = self._protectionObj.level
local msg = (protectionBlurbs[action] and protectionBlurbs[action][level])
or (protectionBlurbs[action] and protectionBlurbs[action].default)
or (protectionBlurbs.edit and protectionBlurbs.edit.default)
or ''
return self:_substituteParameters(msg)
end
function Blurb:_makeProtectionLevelParameter()
local protectionLevels = self._cfg.protectionLevels or {}
local action = self._protectionObj.action
local level = self._protectionObj.level
local msg = (protectionLevels[action] and protectionLevels[action][level])
or (protectionLevels[action] and protectionLevels[action].default)
or (protectionLevels.edit and protectionLevels.edit.default)
or ''
return self:_substituteParameters(msg)
end
function Blurb:_makePagetypeParameter()
local pagetypes = self._cfg.pagetypes or {}
return pagetypes[self._protectionObj.title.namespace]
or pagetypes.default
or ''
end
-- BannerTemplate class (nil-safe)
local BannerTemplate = {}
BannerTemplate.__index = BannerTemplate
function BannerTemplate.new(protectionObj, cfg)
local obj = {}
obj._cfg = cfg
local imageFilename = protectionObj.bannerConfig.image
if imageFilename then
obj._imageFilename = imageFilename
else
local action = protectionObj.action
local level = protectionObj.level
local namespace = protectionObj.title.namespace
local reason = protectionObj.reason
if (
namespace == 10
or namespace == 828
or (reason and obj._cfg.indefImageReasons and obj._cfg.indefImageReasons[reason])
)
and action == 'edit'
and level == 'sysop'
and not protectionObj:isTemporary()
then
obj._imageFilename = (obj._cfg.msg and obj._cfg.msg['image-filename-indef']) or 'Transparent.gif'
else
local images = (obj._cfg and obj._cfg.images) or {}
if images[action] then
obj._imageFilename = images[action][level] or images[action].default
end
if not obj._imageFilename then
obj._imageFilename = (obj._cfg.msg and obj._cfg.msg['image-filename-default']) or 'Transparent.gif'
end
end
end
return setmetatable(obj, BannerTemplate)
end
function BannerTemplate:renderImage()
local filename = self._imageFilename or (self._cfg.msg and self._cfg.msg['image-filename-default']) or 'Transparent.gif'
return makeFileLink{
file = filename,
size = (self.imageWidth or 20) .. 'px',
alt = self._imageAlt,
link = self._imageLink,
caption = self.imageCaption
}
end
-- Diğer sınıflar (Banner, Padlock) ve p._main/p.main fonksiyonları aynı mantıkla çalışacak, nil kontrolleri eklendi.
-- (Kod çok uzun olduğu için Banner ve Padlock için aynı mantık geçerli: obj._cfg ve tabloları nil-safe kontrol et)