“モジュール:Protection banner” のwerson間の差分

strict
(回退到由Pseudo Classes討論)做出的修訂版本61213875:BREAKING CHANGE)
 
(strict)
3行目: 3行目:


-- Initialise necessary modules.
-- Initialise necessary modules.
require('Module:No globals')
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
13行目: 13行目:


-- Set constants.
-- Set constants.
local CONFIG_MODULE = 'Module:Protection banner/config'
local CONFIG_MODULE = 'モジュール:Protection banner/config'


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
43行目: 43行目:
end
end
error(string.format(
error(string.format(
'%s「%s」並非有效的格式!',
'invalid %s: %s',
dateType,
dateType,
tostring(dateString)
tostring(dateString)
50行目: 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


109行目: 113行目:
else
else
error(string.format(
error(string.format(
'未知動作「%s」',
'invalid action: %s',
tostring(args.action)
tostring(args.action)
), 3)
), 3)
127行目: 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


134行目: 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
140行目: 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
307行目: 311行目:
return not self:isProtected()
return not self:isProtected()
or type(expiry) == 'number' and expiry < os.time()
or type(expiry) == 'number' and expiry < os.time()
end
-- 日本語版独自
function Protection:isMismatched()
return self.reason == 'dispute' and self.level ~= 'sysop'
end
end


324行目: 333行目:
ret[#ret + 1] = makeCategoryLink(
ret[#ret + 1] = makeCategoryLink(
msg['tracking-category-incorrect'],
msg['tracking-category-incorrect'],
self.title.text
)
elseif self:isMismatched() then
ret[#ret + 1] = makeCategoryLink(
msg['tracking-category-mismatch'],
self.title.text
self.title.text
)
)
496行目: 510行目:
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
542行目: 555行目:
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


557行目: 570行目:
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)
583行目: 596行目:
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)
645行目: 658行目:
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)
658行目: 671行目:
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)
681行目: 695行目:
local imageFilename = protectionObj.bannerConfig.image
local imageFilename = protectionObj.bannerConfig.image
if imageFilename then
if imageFilename then
obj._imageFilename = imageFilename
-- 日本語版独自の条件分岐
if type(imageFilename) == 'string' then
obj._imageFilename = imageFilename
elseif type(imageFilename) == 'function' then
obj._imageFilename = imageFilename(protectionObj)
end
else
else
-- If an image filename isn't specified explicitly in the banner config,
-- If an image filename isn't specified explicitly in the banner config,
724行目: 744行目:
return makeFileLink{
return makeFileLink{
file = filename,
file = filename,
size = (self.imageWidth or 20) .. 'px',
size = (self.imageSize or 'x20') .. 'px', -- 日本語版独自の変更
alt = self._imageAlt,
alt = self._imageAlt,
link = self._imageLink,
link = self._imageLink,
740行目: 760行目:
function Banner.new(protectionObj, blurbObj, cfg)
function Banner.new(protectionObj, blurbObj, cfg)
local obj = BannerTemplate.new(protectionObj, cfg) -- This doesn't need the blurb.
local obj = BannerTemplate.new(protectionObj, cfg) -- This doesn't need the blurb.
obj.imageWidth = 40
obj.imageSize = 40 -- 日本語版独自の変更: フィールド名
obj.imageCaption = blurbObj:makeBannerText('alt') -- Large banners use the alt text for the tooltip.
obj.imageCaption = blurbObj:makeBannerText('alt') -- Large banners use the alt text for the tooltip.
obj._reasonText = blurbObj:makeBannerText('text')
obj._reasonText = blurbObj:makeBannerText('text')
751行目: 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 = {
775行目: 795行目:
function Padlock.new(protectionObj, blurbObj, cfg)
function Padlock.new(protectionObj, blurbObj, cfg)
local obj = BannerTemplate.new(protectionObj, cfg) -- This doesn't need the blurb.
local obj = BannerTemplate.new(protectionObj, cfg) -- This doesn't need the blurb.
obj.imageWidth = 20
obj.imageSize = 'x20' -- 日本語版独自の変更: フィールド名、高さのみ指定
obj.imageCaption = blurbObj:makeBannerText('tooltip')
obj.imageCaption = blurbObj:makeBannerText('tooltip')
obj._imageAlt = blurbObj:makeBannerText('alt')
obj._imageAlt = blurbObj:makeBannerText('alt')
匿名利用者