Module:Protection banner/sandbox: Difference between revisions

Content deleted Content added
No edit summary
sync to live module
 
(22 intermediate revisions by 13 users not shown)
Line 3:
 
-- Initialise necessary modules.
require('Module:No globalsstrict')
local makeFileLink = require('Module:File link')._main
local effectiveProtectionLevel = require('Module:Effective protection level')._main
Line 171:
end
 
function Protection:isProtectedisUserScript()
-- Whether the page is a user JavaScript or CSS page.
-- Ignore .css/.js files in userspace
local title = self.title
ifreturn title.namespace == 2 and (
title.contentModel == 'javascript' or title.contentModel == 'css'
string.find(title.subpageText, ".js", -3, true) or
)
string.find(title.subpageText, ".css", -4, true)
end
) then
return false
end
 
function Protection:isProtected()
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 189 ⟶ 196:
 
function Protection:makeProtectionCategory()
if not self:isProtectedshouldHaveProtectionCategory() then
return false''
end
 
local cfg = self._cfg
local title = self.title
-- Exit if the page is not protected.
if not self:isProtected() then
return ''
end
-- Get the expiry key fragment.
Line 210 ⟶ 216:
namespaceFragment = 'talk'
end
 
-- Remap redirects
local reason = self.reason
local is_redirect = nil
if title.isRedirect then
is_redirect = 'redirect'
local newReason = cfg.reasonRedirectMap[reason]
if newReason then
reason = newReason
end
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 228 ⟶ 223:
{val = expiryFragment, keypos = 1},
{val = namespaceFragment, keypos = 2},
{val = self.reason, keypos = 3},
{val = self.level, keypos = 4},
{val = self.action, keypos = 5},
{val = is_redirect, keypos = 6}
}
 
Line 330 ⟶ 324:
function Protection:isIncorrect()
local expiry = self.expiry
return not self:isProtectedshouldHaveProtectionCategory()
or type(expiry) == 'number' and expiry < os.time()
end
Line 345 ⟶ 339:
function Protection:makeCategoryLinks()
local msg = self._cfg.msg
local ret = { self:makeProtectionCategory() }
if self:isIncorrect() then
ret[#ret + 1] = makeCategoryLink(
Line 658 ⟶ 652:
 
function Blurb:_makeVandalTemplateParameter()
return mw.getCurrentFrame():expandTemplate{
return require('Module:Vandal-m')._main{
title="vandal-m",
args={self._args.user or self._protectionObj.title.baseText}
}
end
Line 848 ⟶ 843:
-- protection from some other action, then don't bother displaying anything
-- for the other action (except categories).
if not yesno(args.catonly) and (protectionObj.action == 'edit' or
args.demolevel or
not getReachableNodes(
cfg.hierarchy,
protectionObj.level
)[effectiveProtectionLevel('edit', protectionObj.title)])
then
-- Initialise the blurb object
Line 859 ⟶ 854:
-- Render the banner
if protectionObj:isProtectedshouldShowLock() then
ret[#ret + 1] = tostring(
(yesno(args.small) and Padlock or Banner)
Line 870 ⟶ 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