Module:Protection banner: Difference between revisions
From WikiOasis Meta
More actions
m 1 revision imported Tags: Mobile edit Mobile web edit Advanced mobile edit |
m 11 revisions imported |
||
| (8 intermediate revisions by 7 users not shown) | |||
| Line 3: | Line 3: | ||
-- Initialise necessary modules. | -- Initialise necessary modules. | ||
require(' | require('strict') | ||
local makeFileLink = require('Module:File link')._main | local makeFileLink = require('Module:File link')._main | ||
local effectiveProtectionLevel = require('Module:Effective protection level')._main | local effectiveProtectionLevel = require('Module:Effective protection level')._main | ||
| Line 43: | Line 43: | ||
end | end | ||
error(string.format( | error(string.format( | ||
' | '%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 | return require('Module:Fullurl')._fullurl2(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) | ||
end | end | ||
| Line 182: | Line 170: | ||
return self.level ~= '*' | return self.level ~= '*' | ||
end | end | ||
function Protection:isTemporary() | function Protection:isTemporary() | ||
| Line 196: | Line 176: | ||
function Protection:makeProtectionCategory() | function Protection:makeProtectionCategory() | ||
if not self: | local cfg = self._cfg | ||
local title = self.title | |||
-- Exit if the page is not protected. | |||
if not self:isProtected() then | |||
return '' | return '' | ||
end | end | ||
-- 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 時的解釋說明', | ||
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{ | ||
self._args.user or self._protectionObj.title.baseText | |||
} | } | ||
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」不是有效的橫幅配置金鑰。', | ||
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」', | ||
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) | ||