Content deleted Content added
Jackmcbarn (talk | contribs) fix stack levels of most errors |
sync to live module |
||
(73 intermediate revisions by 16 users not shown) | |||
Line 3:
-- Initialise necessary modules.
require('
local
local effectiveProtectionLevel = require('Module:Effective protection level')._main
local effectiveProtectionExpiry = require('Module:Effective protection expiry')._main
local yesno = require('Module:Yesno')
Line 12 ⟶ 13:
-- Set constants.
local CONFIG_MODULE = 'Module:Protection banner/config/sandbox' --
--------------------------------------------------------------------------------
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)
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)
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(
if not retval[v] then
toWalk[v] = true
Line 83 ⟶ 76:
end
end
end
Line 96 ⟶ 88:
edit = true,
move = true,
autoreview = true,
upload = true
}
Line 120 ⟶ 113:
else
error(string.format(
'invalid action:
tostring(args.action)
), 3)
Line 126 ⟶ 119:
-- 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 138 ⟶ 127:
-- Set expiry
local effectiveExpiry = effectiveProtectionExpiry(obj.action, obj.title)
end
Line 183 ⟶ 169:
end
return setmetatable(obj, Protection)
end
function Protection:isUserScript()
-- Whether the page is a user JavaScript or CSS page.
local title = self.title
return title.namespace == 2 and (
title.contentModel == 'javascript' or title.contentModel == 'css'
)
end
Line 188 ⟶ 182:
return self.level ~= '*'
end
function Protection:shouldShowLock()
-- Whether we should output a banner/padlock
return self:isProtected() and not self:isUserScript()
end
-- Whether this page needs a protection category.
Protection.shouldHaveProtectionCategory = Protection.shouldShowLock
function Protection:isTemporary()
Line 194 ⟶ 196:
function Protection:makeProtectionCategory()
if not self:shouldHaveProtectionCategory() then
return ''
end
local cfg = self._cfg
local title = self.title
-- Get the expiry key fragment.
Line 211 ⟶ 212:
-- Get the namespace key fragment.
local namespaceFragment = cfg.categoryNamespaceKeys[title.namespace]
if not namespaceFragment and title.namespace % 2 == 1 then
namespaceFragment =
end
-- Define the order that key fragments are tested in. This is done with an
-- array of tables containing the value to be tested, along with its
Line 241 ⟶ 239:
-- instead.
--]]
--[[
Line 327 ⟶ 320:
end
return ''
end
function Protection:isIncorrect()
local expiry = self.expiry
return not self:
or type(expiry) == 'number' and expiry < os.time()
end
Line 358 ⟶ 339:
function Protection:makeCategoryLinks()
local msg = self._cfg.msg
local ret = {
if self:isIncorrect() then
ret[#ret + 1] = makeCategoryLink(
Line 492 ⟶ 467:
if level == 'autoconfirmed' then
requestType = 'semi'
elseif level == 'extendedconfirmed' then
requestType = 'extended'
elseif level == 'templateeditor' then
requestType = 'template'
Line 543 ⟶ 520:
level,
talkKey
), 8)
end
return self:_substituteParameters(msg)
Line 583 ⟶ 560:
return pagetypes[self._protectionObj.title.namespace]
or pagetypes.default
or error('no default pagetype defined', 8)
end
Line 598 ⟶ 575:
msg = protectionBlurbs.edit.default
else
error('no protection blurb defined for protectionBlurbs.edit.default', 8)
end
return self:_substituteParameters(msg)
Line 624 ⟶ 601:
msg = protectionLevels.edit.default
else
error('no protection level defined for protectionLevels.edit.default', 8)
end
return self:_substituteParameters(msg)
Line 675 ⟶ 652:
function Blurb:_makeVandalTemplateParameter()
return mw.getCurrentFrame():expandTemplate{
title="vandal-m",
args={self._args.user or self._protectionObj.title.baseText} }
end
Line 703 ⟶ 681:
tostring(key),
type(msg)
),
end
return self:_substituteParameters(msg)
Line 758 ⟶ 736:
end
return setmetatable(obj, BannerTemplate)
end
Line 772 ⟶ 742:
or self._cfg.msg['image-filename-default']
or 'Transparent.gif'
return
file = filename,
caption = self.imageCaption
}
end
Line 789 ⟶ 760:
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 824 ⟶ 795:
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 869 ⟶ 840:
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 --
if not yesno(args.catonly) and (protectionObj.action == 'edit' or
args.demolevel or not 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:
ret[#ret + 1] = tostring(
(yesno(args.small) and Padlock or Banner)
Line 887 ⟶ 865:
if yesno(args.category) ~= false then
ret[#ret + 1] = protectionObj:makeCategoryLinks()
end
-- For arbitration enforcement, flagging [[WP:PIA]] pages to enable [[Special:AbuseFilter/1339]] to flag edits to them
if protectionObj.level == "extendedconfirmed" then
if require("Module:TableTools").inArray(protectionObj.title.talkPageTitle.categories, "Wikipedia pages subject to the extended confirmed restriction related to the Arab-Israeli conflict") then
ret[#ret + 1] = "<p class='PIA-flag' style='display:none; visibility:hidden;' title='This page is subject to the extended confirmed restriction related to the Arab-Israeli conflict.'></p>"
end
end
|