Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Editing Module:Protection banner

From WikiOasis Meta
Warning: You are not logged in. Once you make an edit, a temporary account will be created for you. Learn more. Log in or create an account to continue receiving notifications after this account expires, and to access other features.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision Your text
Line 43: Line 43:
end
end
error(string.format(
error(string.format(
'%s「%s」並非有效的格式!',
'invalid %s: %s',
dateType,
dateType,
tostring(dateString)
tostring(dateString)
Line 50: Line 50:


local function makeFullUrl(page, query, display)
local function makeFullUrl(page, query, display)
return require('Module:Fullurl')._fullurl2(page, query, display)
return string.format(
'[%s %s]',
tostring(mw.uri.fullUrl(page, query)),
display
)
end
end


Line 109: Line 113:
else
else
error(string.format(
error(string.format(
'未知動作「%s」',
'invalid action: %s',
tostring(args.action)
tostring(args.action)
), 3)
), 3)
Line 127: Line 131:
obj.expiry = 'indef'
obj.expiry = 'indef'
elseif effectiveExpiry ~= 'unknown' then
elseif effectiveExpiry ~= 'unknown' then
obj.expiry = validateDate(effectiveExpiry, '截止時間')
obj.expiry = validateDate(effectiveExpiry, 'expiry date')
end
end


Line 134: Line 138:
obj.reason = mw.ustring.lower(args[1])
obj.reason = mw.ustring.lower(args[1])
if obj.reason:find('|') then
if obj.reason:find('|') then
error('理由中不得存在「|」!', 3)
error('reasons cannot contain the pipe character ("|")', 3)
end
end
end
end
Line 140: Line 144:
-- Set protection date
-- Set protection date
if args.date then
if args.date then
obj.protectionDate = validateDate(args.date, '保護日期')
obj.protectionDate = validateDate(args.date, 'protection date')
end
end
Line 165: Line 169:
end
end
return setmetatable(obj, Protection)
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
end


Line 170: Line 182:
return self.level ~= '*'
return self.level ~= '*'
end
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()
function Protection:isTemporary()
Line 176: Line 196:


function Protection:makeProtectionCategory()
function Protection:makeProtectionCategory()
if not self:shouldHaveProtectionCategory() then
return ''
end
local cfg = self._cfg
local cfg = self._cfg
local title = self.title
local title = self.title
-- Exit if the page is not protected.
if not self:isProtected() then
return ''
end
-- Get the expiry key fragment.
-- Get the expiry key fragment.
Line 197: Line 216:
namespaceFragment = 'talk'
namespaceFragment = 'talk'
end
end
 
-- Define the order that key fragments are tested in. This is done with an
-- 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
-- array of tables containing the value to be tested, along with its
Line 305: Line 324:
function Protection:isIncorrect()
function Protection:isIncorrect()
local expiry = self.expiry
local expiry = self.expiry
return not self:isProtected()
return not self:shouldHaveProtectionCategory()
or type(expiry) == 'number' and expiry < os.time()
or type(expiry) == 'number' and expiry < os.time()
end
end
Line 320: Line 339:
function Protection:makeCategoryLinks()
function Protection:makeCategoryLinks()
local msg = self._cfg.msg
local msg = self._cfg.msg
local ret = { self:makeProtectionCategory() }
local ret = {self:makeProtectionCategory()}
if self:isIncorrect() then
if self:isIncorrect() then
ret[#ret + 1] = makeCategoryLink(
ret[#ret + 1] = makeCategoryLink(
Line 496: Line 515:
msg = explanations[action].default.default
msg = explanations[action].default.default
else
else
istalk = talkKey == 'talk' and true or false
error(string.format(
error(string.format(
'找不到 action=%s protectionlevel=%s istalkpage=%s 時的解釋說明',
'could not find explanation blurb for action "%s", level "%s" and talk key "%s"',
action,
action,
level,
level,
istalk
talkKey
), 8)
), 8)
end
end
Line 542: Line 560:
return pagetypes[self._protectionObj.title.namespace]
return pagetypes[self._protectionObj.title.namespace]
or pagetypes.default
or pagetypes.default
or error('「pagetypes.default」丟失!', 8)
or error('no default pagetype defined', 8)
end
end


Line 557: Line 575:
msg = protectionBlurbs.edit.default
msg = protectionBlurbs.edit.default
else
else
error('沒有為「protectionBlurbs.edit.default」定義保護說明!', 8)
error('no protection blurb defined for protectionBlurbs.edit.default', 8)
end
end
return self:_substituteParameters(msg)
return self:_substituteParameters(msg)
Line 583: Line 601:
msg = protectionLevels.edit.default
msg = protectionLevels.edit.default
else
else
error('沒有為「protectionLevels.edit.default」定義保護級別!', 8)
error('no protection level defined for protectionLevels.edit.default', 8)
end
end
return self:_substituteParameters(msg)
return self:_substituteParameters(msg)
Line 634: Line 652:


function Blurb:_makeVandalTemplateParameter()
function Blurb:_makeVandalTemplateParameter()
return require('Module:Vandal-m')._main{
return mw.getCurrentFrame():expandTemplate{
self._args.user or self._protectionObj.title.baseText
title="vandal-m",
args={self._args.user or self._protectionObj.title.baseText}
}
}
end
end
Line 645: Line 664:
if not key or not Blurb.bannerTextFields[key] then
if not key or not Blurb.bannerTextFields[key] then
error(string.format(
error(string.format(
'%s」不是有效的橫幅配置金鑰。',
'"%s" is not a valid banner config field',
tostring(key)
tostring(key)
), 2)
), 2)
Line 658: Line 677:
if type(msg) ~= 'string' then
if type(msg) ~= 'string' then
error(string.format(
error(string.format(
'解析橫幅配置時生成錯誤「%s」',
'bad output from banner config function with key "%s"'
.. ' (expected string, got %s)',
tostring(key),
tostring(key),
type(msg)
type(msg)
Line 751: Line 771:
-- Renders the banner.
-- Renders the banner.
makeMessageBox = makeMessageBox or require('Module:Message box').main
makeMessageBox = makeMessageBox or require('Module:Message box').main
local reasonText = self._reasonText or error('沒有理由!', 2)
local reasonText = self._reasonText or error('no reason text set', 2)
local explanationText = self._explanationText
local explanationText = self._explanationText
local mbargs = {
local mbargs = {
Line 823: Line 843:
-- protection from some other action, then don't bother displaying anything
-- protection from some other action, then don't bother displaying anything
-- for the other action (except categories).
-- for the other action (except categories).
if 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,
cfg.hierarchy,
protectionObj.level
protectionObj.level
)[effectiveProtectionLevel('edit', protectionObj.title)]
)[effectiveProtectionLevel('edit', protectionObj.title)])
then
then
-- Initialise the blurb object
-- Initialise the blurb object
Line 834: Line 854:
-- Render the banner
-- Render the banner
if protectionObj:isProtected() and protectionObj.action ~= 'edit' then
if protectionObj:shouldShowLock() then
ret[#ret + 1] = tostring(
ret[#ret + 1] = tostring(
(yesno(args.small) and Padlock or Banner)
(yesno(args.small) and Padlock or Banner)
Line 845: Line 865:
if yesno(args.category) ~= false then
if yesno(args.category) ~= false then
ret[#ret + 1] = protectionObj:makeCategoryLinks()
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;'>This page is subject to the extended confirmed restriction related to the Arab-Israeli conflict.</p>"
end
end
end
Please note that all contributions to WikiOasis Meta are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) (see Meta:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)

 

Page included on this page:

Cookies help us deliver our services. By using our services, you agree to our use of cookies.