Module:Protection banner: Difference between revisions
m
11 revisions imported: import clickable buttons 2
(add a "TOOLTIPFRAGMENT" parameter, as we were having the same issues with commas in tooltips as we did with INTROBLURB and INTROFRAGMENT; also move the config module name to a global variable so that it's more obvious when updating) |
m (11 revisions imported: import clickable buttons 2) |
||
(31 intermediate revisions by 12 users not shown) | |||
Line 4:
-- Initialise necessary modules.
require('Module:No globals')
local
local effectiveProtectionLevel = require('Module:Effective protection level')._main
local effectiveProtectionExpiry = require('Module:Effective protection expiry')._main
local yesno = require('Module:Yesno')
Line 19 ⟶ 20:
local function makeCategoryLink(cat, sort)
if cat then
return string.format(
'[[%s:%s|%s]]',
mw.site.namespaces[14].name,
cat,
sort
)
end
end
Line 40 ⟶ 32:
-- Validation function for the expiry and the protection date
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
Line 49 ⟶ 43:
end
error(string.format(
'invalid %s:
dateType,
tostring(dateString)
),
end
Line 63 ⟶ 57:
end
-- Given a directed graph formatted as node -> table of direct successors,
-- get a table of all nodes reachable from a given node (though always
-- including the given node).
local function getReachableNodes(graph, start)
local toWalk, retval = {[start] = true}, {}
while true do
-- Can't use pairs() since we're adding and removing things as we're iterating
local k = next(toWalk) -- This always gets the "first" key
if k == nil then
return retval
end
toWalk[k] = nil
retval[k] = true
for _,v in ipairs(graph[k]) do
if not retval[v] then
toWalk[v] = true
end
end
end
end
Line 79 ⟶ 88:
edit = true,
move = true,
autoreview = true,
upload = true
}
Line 103 ⟶ 113:
else
error(string.format(
'invalid action:
tostring(args.action)
),
end
-- Set level
obj.level = args.demolevel or effectiveProtectionLevel(obj.action, obj.title)
if not obj.level or (obj.action == 'move' and obj.level == '
-- Users need to be autoconfirmed to move pages anyway, so treat
-- semi-move-protected pages as unprotected.
Line 121 ⟶ 127:
-- Set expiry
local effectiveExpiry = effectiveProtectionExpiry(obj.action, obj.title)
end
Line 135 ⟶ 138:
obj.reason = mw.ustring.lower(args[1])
if obj.reason:find('|') then
error('reasons cannot contain the pipe character ("|")',
end
end
Line 194 ⟶ 197:
-- Get the namespace key fragment.
local namespaceFragment = cfg.categoryNamespaceKeys[title.namespace]
if not namespaceFragment and title.namespace % 2 == 1 then
namespaceFragment =
end
Line 224:
-- instead.
--]]
--[[
Line 310 ⟶ 305:
end
return ''
end
Line 342 ⟶ 325:
local msg = self._cfg.msg
local ret = { self:makeProtectionCategory() }
if self:isIncorrect() then
ret[#ret + 1] = makeCategoryLink(
Line 475 ⟶ 452:
if level == 'autoconfirmed' then
requestType = 'semi'
elseif level == 'extendedconfirmed' then
requestType = 'extended'
elseif level == 'templateeditor' then
requestType = 'template'
Line 526 ⟶ 505:
level,
talkKey
), 8)
end
return self:_substituteParameters(msg)
Line 566 ⟶ 545:
return pagetypes[self._protectionObj.title.namespace]
or pagetypes.default
or error('no default pagetype defined', 8)
end
Line 581 ⟶ 560:
msg = protectionBlurbs.edit.default
else
error('no protection blurb defined for protectionBlurbs.edit.default', 8)
end
return self:_substituteParameters(msg)
Line 607 ⟶ 586:
msg = protectionLevels.edit.default
else
error('no protection level defined for protectionLevels.edit.default', 8)
end
return self:_substituteParameters(msg)
Line 686 ⟶ 665:
tostring(key),
type(msg)
), 4)
end
return self:_substituteParameters(msg)
Line 741 ⟶ 720:
end
return setmetatable(obj, BannerTemplate)
end
Line 755 ⟶ 726:
or self._cfg.msg['image-filename-default']
or 'Transparent.gif'
return
file = filename,
caption = self.imageCaption
}
end
Line 772 ⟶ 744:
function Banner.new(protectionObj, blurbObj, cfg)
local obj = BannerTemplate.new(protectionObj, cfg) -- This doesn't need the blurb.
obj
obj
obj._reasonText = blurbObj:makeBannerText('text')
obj._explanationText = blurbObj:makeBannerText('explanation')
Line 783 ⟶ 755:
-- Renders the banner.
makeMessageBox = makeMessageBox or require('Module:Message box').main
local reasonText = self._reasonText or error('no reason text set', 2)
local explanationText = self._explanationText
local mbargs = {
Line 807 ⟶ 779:
function Padlock.new(protectionObj, blurbObj, cfg)
local obj = BannerTemplate.new(protectionObj, cfg) -- This doesn't need the blurb.
obj
obj
obj._imageAlt = blurbObj:makeBannerText('alt')
obj._imageLink = blurbObj:makeBannerText('link')
obj.
or cfg.
or '
return setmetatable(obj, Padlock)
end
function Padlock:__tostring()
local
-- The nowiki tag helps prevent whitespace at the top of articles.
return frame:extensionTag{name = 'nowiki'} .. frame:extensionTag{
name = 'indicator',
}
end
Line 846 ⟶ 818:
function p._main(args, cfg, title)
args = args or {}
cfg = cfg or require(
local protectionObj = Protection.new(args, cfg, title)
local ret = {}
-- If a page's edit protection is equally or more restrictive than its
-- protection from some other action, then don't bother displaying anything
-- for the other action (except categories).
if protectionObj.action == 'edit' or
args.demolevel or
not getReachableNodes(
cfg.hierarchy,
protectionObj.level
)[effectiveProtectionLevel('edit', protectionObj.title)]
then
-- Initialise the blurb object
local blurbObj = Blurb.new(protectionObj, args, cfg)
-- Render the banner
if protectionObj:isProtected() then
ret[#ret + 1] = tostring(
(yesno(args.small) and Padlock or Banner)
.new(protectionObj, blurbObj, cfg)
)
end
end
-- Render the categories
if yesno(args.category) ~= false then
Line 892 ⟶ 855:
function p.main(frame, cfg)
cfg = cfg or require(CONFIG_MODULE)
-- Find default args, if any.
local parent = frame.getParent and frame:getParent()
local defaultArgs = parent and cfg.wrappers[parent:getTitle():gsub('/sandbox$', '')]
-- Find user args, and use the parent frame if we are being called from a
-- wrapper template.
getArgs = getArgs or require('Module:Arguments').getArgs
local userArgs = getArgs(frame, {
parentOnly = defaultArgs,
frameOnly = not defaultArgs
})
-- Build the args table. User-specified args overwrite default args.
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
|