匿名利用者
“モジュール:Protection banner” のwerson間の差分
モジュール:Protection banner (Ipemoto a=nukar)
2023 ppm 2 2023-02-12T15:32:26+00:00up 12 282023 (Sir.) 15:32時点におけるwerson
、 2023 ppm 2 2023-02-12T15:32:26+00:00up 12 282023 (Sir.)strict
(回退到由Pseudo Classes(討論)做出的修訂版本61213875:BREAKING CHANGE) |
(strict) |
||
3行目: | 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 | ||
13行目: | 13行目: | ||
-- Set constants. | -- Set constants. | ||
local CONFIG_MODULE = ' | local CONFIG_MODULE = 'モジュール:Protection banner/config' | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
43行目: | 43行目: | ||
end | end | ||
error(string.format( | error(string.format( | ||
'% | 'invalid %s: %s', | ||
dateType, | dateType, | ||
tostring(dateString) | tostring(dateString) | ||
50行目: | 50行目: | ||
local function makeFullUrl(page, query, display) | local function makeFullUrl(page, query, display) | ||
return | return string.format( | ||
'[%s %s]', | |||
tostring(mw.uri.fullUrl(page, query)), | |||
display | |||
) | |||
end | end | ||
109行目: | 113行目: | ||
else | else | ||
error(string.format( | error(string.format( | ||
' | '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(' | 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 | ||
error(string.format( | error(string.format( | ||
' | 'could not find explanation blurb for action "%s", level "%s" and talk key "%s"', | ||
action, | action, | ||
level, | level, | ||
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(' | or error('no default pagetype defined', 8) | ||
end | end | ||
557行目: | 570行目: | ||
msg = protectionBlurbs.edit.default | msg = protectionBlurbs.edit.default | ||
else | else | ||
error(' | 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(' | 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" 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( | ||
' | '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. | 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. | 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(' | 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. | obj.imageSize = 'x20' -- 日本語版独自の変更: フィールド名、高さのみ指定 | ||
obj.imageCaption = blurbObj:makeBannerText('tooltip') | obj.imageCaption = blurbObj:makeBannerText('tooltip') | ||
obj._imageAlt = blurbObj:makeBannerText('alt') | obj._imageAlt = blurbObj:makeBannerText('alt') |