Module:Protection banner: Difference between revisions
From Test Wiki
Content deleted Content added
MacFan4000 (talk | contribs) m 1 revision imported |
m 1 revision imported |
||
| (One intermediate revision by one other user not shown) | |||
| 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 113: | Line 109: | ||
else |
else |
||
error(string.format( |
error(string.format( |
||
' |
'未知動作「%s」', |
||
tostring(args.action) |
tostring(args.action) |
||
), 3) |
), 3) |
||
| Line 131: | Line 127: | ||
obj.expiry = 'indef' |
obj.expiry = 'indef' |
||
elseif effectiveExpiry ~= 'unknown' then |
elseif effectiveExpiry ~= 'unknown' then |
||
obj.expiry = validateDate(effectiveExpiry, ' |
obj.expiry = validateDate(effectiveExpiry, '截止時間') |
||
end |
end |
||
| Line 138: | Line 134: | ||
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(' |
error('理由中不得存在「|」!', 3) |
||
end |
end |
||
end |
end |
||
| Line 144: | Line 140: | ||
-- Set protection date |
-- Set protection date |
||
if args.date then |
if args.date then |
||
obj.protectionDate = validateDate(args.date, ' |
obj.protectionDate = validateDate(args.date, '保護日期') |
||
end |
end |
||
| Line 169: | Line 165: | ||
end |
end |
||
return setmetatable(obj, Protection) |
return setmetatable(obj, Protection) |
||
| ⚫ | |||
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 182: | Line 170: | ||
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 196: | Line 176: | ||
function Protection:makeProtectionCategory() |
function Protection:makeProtectionCategory() |
||
| ⚫ | |||
| ⚫ | |||
end |
|||
local cfg = self._cfg |
local cfg = self._cfg |
||
local title = self.title |
local title = self.title |
||
| ⚫ | |||
-- Exit if the page is not protected. |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
-- Get the expiry key fragment. |
-- Get the expiry key fragment. |
||
| Line 216: | Line 197: | ||
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 324: | Line 305: | ||
function Protection:isIncorrect() |
function Protection:isIncorrect() |
||
local expiry = self.expiry |
local expiry = self.expiry |
||
return not self: |
return not self:isProtected() |
||
or type(expiry) == 'number' and expiry < os.time() |
or type(expiry) == 'number' and expiry < os.time() |
||
end |
end |
||
| Line 339: | Line 320: | ||
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 515: | Line 496: | ||
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 |
|||
), 8) |
), 8) |
||
end |
end |
||
| Line 560: | Line 542: | ||
return pagetypes[self._protectionObj.title.namespace] |
return pagetypes[self._protectionObj.title.namespace] |
||
or pagetypes.default |
or pagetypes.default |
||
or error(' |
or error('「pagetypes.default」丟失!', 8) |
||
end |
end |
||
| Line 575: | Line 557: | ||
msg = protectionBlurbs.edit.default |
msg = protectionBlurbs.edit.default |
||
else |
else |
||
error(' |
error('沒有為「protectionBlurbs.edit.default」定義保護說明!', 8) |
||
end |
end |
||
return self:_substituteParameters(msg) |
return self:_substituteParameters(msg) |
||
| Line 601: | Line 583: | ||
msg = protectionLevels.edit.default |
msg = protectionLevels.edit.default |
||
else |
else |
||
error(' |
error('沒有為「protectionLevels.edit.default」定義保護級別!', 8) |
||
end |
end |
||
return self:_substituteParameters(msg) |
return self:_substituteParameters(msg) |
||
| Line 652: | Line 634: | ||
function Blurb:_makeVandalTemplateParameter() |
function Blurb:_makeVandalTemplateParameter() |
||
return |
return require('Module:Vandal-m')._main{ |
||
| ⚫ | |||
title="vandal-m", |
|||
| ⚫ | |||
} |
} |
||
end |
end |
||
| Line 664: | Line 645: | ||
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 677: | Line 658: | ||
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 771: | Line 751: | ||
-- 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(' |
local reasonText = self._reasonText or error('沒有理由!', 2) |
||
local explanationText = self._explanationText |
local explanationText = self._explanationText |
||
local mbargs = { |
local mbargs = { |
||
| Line 843: | Line 823: | ||
-- 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 |
if 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 854: | Line 834: | ||
-- Render the banner |
-- Render the banner |
||
if protectionObj: |
if protectionObj:isProtected() and protectionObj.action ~= 'edit' then |
||
ret[#ret + 1] = tostring( |
ret[#ret + 1] = tostring( |
||
(yesno(args.small) and Padlock or Banner) |
(yesno(args.small) and Padlock or Banner) |
||
| Line 865: | Line 845: | ||
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 |
||