Modül:Koruma kutu: Revizyonlar arasındaki fark
Görünüm
k Joe Goldberg, Modül:Protection banner sayfasını Modül:Koruma kutu sayfasına taşıdı |
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 | ||
obj.bannerConfig = {} | |||
local configTables = {} | |||
if cfg.banners[obj.action] then | |||
configTables[#configTables + 1] = cfg.banners[obj.action][obj.reason] | |||
end | |||
if 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 | ||
end | end | ||
return setmetatable(obj, Protection) | return setmetatable(obj, Protection) | ||
end | end | ||
function Protection:isUserScript() | function Protection:isUserScript() | ||
local title = self.title | local title = self.title | ||
return title.namespace == 2 and ( | return title.namespace == 2 and (title.contentModel == 'javascript' or title.contentModel == 'css') | ||
end | end | ||
| 186. satır: | 166. 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 | ||
| 197. satır: | 175. satır: | ||
end | end | ||
-- (Burada makeProtectionCategory, isIncorrect, isTemplateProtectedNonTemplate, makeCategoryLinks metotları aynı kalabilir) | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| 380. satır: | 200. satır: | ||
end | end | ||
-- | -- (Blurb:_formatDate, _getExpandedMessage, _substituteParameters ve tüm _make* parametre metodları aynı kalabilir) | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- BannerTemplate | -- BannerTemplate, Banner ve Padlock sınıfları | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| 694. satır: | 213. 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[reason]) | ||
) and action == 'edit' and level == 'sysop' and not protectionObj:isTemporary() | |||
then | then | ||
obj._imageFilename = obj._cfg.msg['image-filename-indef'] | obj._imageFilename = obj._cfg.msg['image-filename-indef'] | ||
else | else | ||
local images = obj._cfg.images | local images = obj._cfg.images | ||
if images[action] then | if images[action] then | ||
| 734. satır: | 242. satır: | ||
end | end | ||
-- (Banner ve Padlock sınıfları aynı kalabilir) | |||
Padlock | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| 818. satır: | 251. satır: | ||
function p._exportClasses() | function p._exportClasses() | ||
return { | return { | ||
Protection = Protection, | Protection = Protection, | ||
| 836. satır: | 268. satır: | ||
local ret = {} | local ret = {} | ||
if not yesno(args.catonly) and (protectionObj.action == 'edit' or | if not yesno(args.catonly) and (protectionObj.action == 'edit' or | ||
args.demolevel or | args.demolevel or | ||
not getReachableNodes( | not getReachableNodes(cfg.hierarchy, protectionObj.level)[effectiveProtectionLevel('edit', protectionObj.title)]) | ||
then | then | ||
local blurbObj = Blurb.new(protectionObj, args, cfg) | local blurbObj = Blurb.new(protectionObj, args, cfg) | ||
local parameter = args["küçük"] or args["small"] | local parameter = args["küçük"] or args["small"] | ||
if protectionObj:shouldShowLock() then | if protectionObj:shouldShowLock() then | ||
| 859. satır: | 282. satır: | ||
end | end | ||
if yesno(args.category) or yesno(args.kategori) ~= false then | if yesno(args.category) or yesno(args.kategori) ~= false then | ||
ret[#ret + 1] = protectionObj:makeCategoryLinks() | ret[#ret + 1] = protectionObj:makeCategoryLinks() | ||
| 869. satır: | 291. satır: | ||
function p.main(frame, cfg) | function p.main(frame, cfg) | ||
cfg = cfg or require(CONFIG_MODULE) | cfg = cfg or require(CONFIG_MODULE) | ||
cfg.wrappers = cfg.wrappers or {} -- burada nil kontrolü | |||
local parent = frame.getParent and frame:getParent() | local parent = frame.getParent and frame:getParent() | ||
local defaultArgs = | local defaultArgs | ||
if parent then | |||
defaultArgs = cfg.wrappers[parent:getTitle():gsub('/sandbox$', '')] or {} | |||
end | |||
getArgs = getArgs or require('Modül:Bağımsız değişkenler').getArgs | getArgs = getArgs or require('Modül:Bağımsız değişkenler').getArgs | ||
local userArgs = getArgs(frame, { | local userArgs = getArgs(frame, { | ||
| 882. satır: | 305. satır: | ||
}) | }) | ||
local args = {} | local args = {} | ||
for k, v in pairs(defaultArgs or {}) do | for k, v in pairs(defaultArgs or {}) do | ||
| 890. satır: | 312. satır: | ||
args[k] = v | args[k] = v | ||
end | end | ||
return p._main(args, cfg) | return p._main(args, cfg) | ||
end | end | ||
return p | return p | ||
14.36, 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
obj.bannerConfig = {}
local configTables = {}
if cfg.banners[obj.action] then
configTables[#configTables + 1] = cfg.banners[obj.action][obj.reason]
end
if 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
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
-- (Burada makeProtectionCategory, isIncorrect, isTemplateProtectedNonTemplate, makeCategoryLinks metotları aynı kalabilir)
--------------------------------------------------------------------------------
-- 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
-- (Blurb:_formatDate, _getExpandedMessage, _substituteParameters ve tüm _make* parametre metodları aynı kalabilir)
--------------------------------------------------------------------------------
-- BannerTemplate, Banner ve Padlock sınıfları
--------------------------------------------------------------------------------
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[reason])
) and action == 'edit' and level == 'sysop' and not protectionObj:isTemporary()
then
obj._imageFilename = obj._cfg.msg['image-filename-indef']
else
local images = obj._cfg.images
if images[action] then
if images[action][level] then
obj._imageFilename = images[action][level]
elseif images[action].default then
obj._imageFilename = images[action].default
end
end
end
end
return setmetatable(obj, BannerTemplate)
end
-- (Banner ve Padlock sınıfları aynı kalabilir)
--------------------------------------------------------------------------------
-- Exports
--------------------------------------------------------------------------------
local p = {}
function p._exportClasses()
return {
Protection = Protection,
Blurb = Blurb,
BannerTemplate = BannerTemplate,
Banner = Banner,
Padlock = Padlock,
}
end
function p._main(args, cfg, title)
args = args or {}
cfg = cfg or require(CONFIG_MODULE)
local protectionObj = Protection.new(args, cfg, title)
local ret = {}
if not yesno(args.catonly) and (protectionObj.action == 'edit' or
args.demolevel or
not getReachableNodes(cfg.hierarchy, protectionObj.level)[effectiveProtectionLevel('edit', protectionObj.title)])
then
local blurbObj = Blurb.new(protectionObj, args, cfg)
local parameter = args["küçük"] or args["small"]
if protectionObj:shouldShowLock() then
ret[#ret + 1] = tostring(
(yesno(parameter) and Padlock or Banner)
.new(protectionObj, blurbObj, cfg)
)
end
end
if yesno(args.category) or yesno(args.kategori) ~= false then
ret[#ret + 1] = protectionObj:makeCategoryLinks()
end
return table.concat(ret)
end
function p.main(frame, cfg)
cfg = cfg or require(CONFIG_MODULE)
cfg.wrappers = cfg.wrappers or {} -- burada nil kontrolü
local parent = frame.getParent and frame:getParent()
local defaultArgs
if parent then
defaultArgs = cfg.wrappers[parent:getTitle():gsub('/sandbox$', '')] or {}
end
getArgs = getArgs or require('Modül:Bağımsız değişkenler').getArgs
local userArgs = getArgs(frame, {
parentOnly = defaultArgs,
frameOnly = not defaultArgs
})
local args = {}
for k, v in pairs(defaultArgs or {}) do
args[k] = v
end
for k, v in pairs(userArgs) do
args[k] = v
end
return p._main(args, cfg)
end
return p