「モジュール:Protection banner」の版間の差分

1版 をインポートしました
mediawiki>Marine-Blue
(サンドボックスを反映、WP:AN/PEによる)
(1版 をインポートしました)
13行目: 13行目:


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


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
169行目: 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


174行目: 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()
180行目: 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.
201行目: 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
309行目: 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
-- 日本語版独自
function Protection:isMismatched()
return self.reason == 'dispute' and self.level ~= 'sysop'
end
end


329行目: 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(
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
)
)
647行目: 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
695行目: 701行目:
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,
744行目: 744行目:
return makeFileLink{
return makeFileLink{
file = filename,
file = filename,
size = (self.imageSize or 'x20') .. 'px', -- 日本語版独自の変更
size = (self.imageWidth or 20) .. 'px',
alt = self._imageAlt,
alt = self._imageAlt,
link = self._imageLink,
link = self._imageLink,
760行目: 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.imageSize = 40 -- 日本語版独自の変更: フィールド名
obj.imageWidth = 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')
795行目: 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.imageSize = 'x20' -- 日本語版独自の変更: フィールド名、高さのみ指定
obj.imageWidth = 20
obj.imageCaption = blurbObj:makeBannerText('tooltip')
obj.imageCaption = blurbObj:makeBannerText('tooltip')
obj._imageAlt = blurbObj:makeBannerText('alt')
obj._imageAlt = blurbObj:makeBannerText('alt')
843行目: 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
854行目: 854行目:
-- Render the banner
-- Render the banner
if protectionObj:isProtected() 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)