「モジュール:Message box」の版間の差分

2版 をインポートしました
temp>Frozen-mikan
(Wikipedia:井戸端/subj/RemexHTML移行に関する合意形成 を受けて、特別:LintErrors を減らすため https://en.wikipedia.org/w/index.php?title=Module:Message_box&diff=803399820&oldid=742383679 の変更を取り込む)
(2版 をインポートしました)
 
(4人の利用者による、間の9版が非表示)
1行目: 1行目:
-- This is a meta-module for producing message box templates, including
require('strict')
-- {{mbox}}, {{ambox}}, {{imbox}}, {{tmbox}}, {{ombox}}, {{cmbox}} and {{fmbox}}.
 
-- Load necessary modules.
require('Module:No globals')
local getArgs
local getArgs
local categoryHandler = require('Module:Category handler')._main
local yesno = require('Module:Yesno')
local yesno = require('Module:Yesno')
local lang = mw.language.getContentLanguage()


-- Get a language object for formatDate and ucfirst.
local CONFIG_MODULE = 'Module:Message box/configuration'
local lang = mw.language.getContentLanguage()
local DEMOSPACES = {talk = 'tmbox', image = 'imbox', file = 'imbox', category = 'cmbox', article = 'ambox', main = 'ambox'}


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
72行目: 68行目:
local ns = obj.title.namespace
local ns = obj.title.namespace
-- boxType is "mbox" or invalid input
-- boxType is "mbox" or invalid input
if ns == 0 then
if args.demospace and args.demospace ~= '' then
-- implement demospace parameter of mbox
local demospace = string.lower(args.demospace)
if DEMOSPACES[demospace] then
-- use template from DEMOSPACES
obj.cfg = cfg[DEMOSPACES[demospace]]
elseif string.find( demospace, 'talk' ) then
-- demo as a talk page
obj.cfg = cfg.tmbox
else
-- default to ombox
obj.cfg = cfg.ombox
end
elseif ns == 0 then
obj.cfg = cfg.ambox -- main namespace
obj.cfg = cfg.ambox -- main namespace
elseif ns == 6 then
elseif ns == 6 then
106行目: 115行目:
obj.categories = {}
obj.categories = {}
obj.classes = {}
obj.classes = {}
-- For lazy loading of [[Module:Category handler]].
obj.hasCategories = false


return setmetatable(obj, MessageBox)
return setmetatable(obj, MessageBox)
119行目: 130行目:
cat = string.format('[[Category:%s]]', cat)
cat = string.format('[[Category:%s]]', cat)
end
end
self.hasCategories = true
self.categories[ns] = self.categories[ns] or {}
self.categories[ns] = self.categories[ns] or {}
table.insert(self.categories[ns], cat)
table.insert(self.categories[ns], cat)
155行目: 167行目:
-- Add attributes, classes and styles.
-- Add attributes, classes and styles.
self.id = args.id
self.id = args.id
self:addClass(
self.name = args.name
cfg.usePlainlinksParam and yesno(args.plainlinks or true) and 'plainlinks'
if self.name then
)
self:addClass('box-' .. string.gsub(self.name,' ','_'))
end
if yesno(args.plainlinks) ~= false then
self:addClass('plainlinks')
end
for _, class in ipairs(cfg.classes or {}) do
for _, class in ipairs(cfg.classes or {}) do
self:addClass(class)
self:addClass(class)
180行目: 196行目:
and cfg.templateCategoryRequireName
and cfg.templateCategoryRequireName
then
then
self.name = args.name
if self.name then
if self.name then
local templateName = mw.ustring.match(
local templateName = mw.ustring.match(
192行目: 207行目:
and mw.title.equals(self.title, self.templateTitle)
and mw.title.equals(self.title, self.templateTitle)
end
end
 
-- Process data for collapsible text fields. At the moment these are only
-- Process data for collapsible text fields. At the moment these are only
-- used in {{ambox}}.
-- used in {{ambox}}.
246行目: 261行目:
end
end
if talkTitle and talkTitle.exists then
if talkTitle and talkTitle.exists then
local talkText = '関連議論は'
local talkText
if talkArgIsTalkPage then
                if self.isSmall then
talkText = string.format(
                    local talkLink = talkArgIsTalkPage and talk or (talkTitle.prefixedText .. '#' .. talk)
'%s[[%s|%s]]に存在するかもしれません。',
                    talkText = string.format('([[%s|ノート]])', talkLink)
talkText,
                else
talk,
                    talkText = '関連議論は'
talkTitle.prefixedText
                    if talkArgIsTalkPage then
)
                        talkText = string.format(
else
                            '%s[[%s|%s]]に存在するかもしれません。',
talkText = string.format(
                            talkText,
'%s[[%s#%s|ノートページ]]に存在するかもしれません。',
                            talk,
talkText,
                            talkTitle.prefixedText
talkTitle.prefixedText,
                        )
talk
                    else
)
                        talkText = string.format(
end
                            '%s[[%s#%s|ノートページ]]に存在するかもしれません。',
                            talkText,
                            talkTitle.prefixedText,
                            talk
                        )
                    end
                end
self.talk = talkText
self.talk = talkText
end
end
275行目: 296行目:
end
end
if date then
if date then
self.date = string.format(" <small>(%s)</small>", date)
self.date = string.format("<span class='date-container'>(<span class='date'>%s</span>)</span>", date)
end
end
self.info = args.info
self.info = args.info
if yesno(args.removalnotice) then
self.removalNotice = cfg.removalNotice
end
end
end


294行目: 318行目:
self.imageCellDiv = not self.isSmall and cfg.imageCellDiv
self.imageCellDiv = not self.isSmall and cfg.imageCellDiv
self.imageEmptyCell = cfg.imageEmptyCell
self.imageEmptyCell = cfg.imageEmptyCell
if cfg.imageEmptyCellStyle then
self.imageEmptyCellStyle = 'border:none;padding:0px;width:1px'
end


-- Left image settings.
-- Left image settings.
318行目: 339行目:
self.imageRight = imageRight
self.imageRight = imageRight
end
end
-- set templatestyles
self.base_templatestyles = cfg.templatestyles
self.templatestyles = args.templatestyles
end
end


423行目: 448行目:


function MessageBox:renderCategories()
function MessageBox:renderCategories()
if not self.hasCategories then
-- No categories added, no need to pass them to Category handler so,
-- if it was invoked, it would return the empty string.
-- So we shortcut and return the empty string.
return ""
end
-- Convert category tables to strings and pass them through
-- Convert category tables to strings and pass them through
-- [[Module:Category handler]].
-- [[Module:Category handler]].
return categoryHandler{
return require('Module:Category handler')._main{
main = table.concat(self.categories[0] or {}),
main = table.concat(self.categories[0] or {}),
template = table.concat(self.categories[10] or {}),
template = table.concat(self.categories[10] or {}),
445行目: 476行目:
mw.text.nowiki('{{'), self.name, self.name, mw.text.nowiki('}}')
mw.text.nowiki('{{'), self.name, self.name, mw.text.nowiki('}}')
))
))
end
local frame = mw.getCurrentFrame()
root:wikitext(frame:extensionTag{
name = 'templatestyles',
args = { src = self.base_templatestyles },
})
-- Add support for a single custom templatestyles sheet. Undocumented as
-- need should be limited and many templates using mbox are substed; we
-- don't want to spread templatestyles sheets around to arbitrary places
if self.templatestyles then
root:wikitext(frame:extensionTag{
name = 'templatestyles',
args = { src = self.templatestyles },
})
end
end


470行目: 516行目:
-- image width to 52px. If any images in a div are wider than that,
-- image width to 52px. If any images in a div are wider than that,
-- they may overlap with the text or cause other display problems.
-- they may overlap with the text or cause other display problems.
imageLeftCell = imageLeftCell:tag('div'):css('width', '52px')
imageLeftCell = imageLeftCell:tag('div'):addClass('mbox-image-div')
end
end
imageLeftCell:wikitext(self.imageLeft or nil)
imageLeftCell:wikitext(self.imageLeft or nil)
480行目: 526行目:
row:tag('td')
row:tag('td')
:addClass('mbox-empty-cell')
:addClass('mbox-empty-cell')
:cssText(self.imageEmptyCellStyle or nil)
end
end


493行目: 538行目:
:addClass('mbox-text-span')
:addClass('mbox-text-span')
:wikitext(self.issue or nil)
:wikitext(self.issue or nil)
if not self.isSmall then
if (self.talk or self.fix) then
textCellDiv:tag('span')
textCellDiv:tag('span')
:addClass('hide-when-compact')
:addClass('hide-when-compact')
:wikitext(self.talk and (' ' .. self.talk) or nil)
:wikitext(self.talk and (self.talk) or nil)
:wikitext(self.fix and (' ' .. self.fix) or nil)
:wikitext(self.fix and (self.fix) or nil)
end
end
textCellDiv:wikitext(self.date and (' ' .. self.date) or nil)
textCellDiv:wikitext(self.date or nil)
if not self.isSmall then
if self.info and not self.isSmall then
textCellDiv
textCellDiv
:tag('span')
:tag('span')
:addClass('hide-when-compact')
:addClass('hide-when-compact')
:wikitext(self.info and (' ' .. self.info) or nil)
:wikitext(self.info and (' ' .. self.info) or nil)
end
if self.removalNotice then
textCellDiv:tag('span')
:addClass('hide-when-compact')
:tag('i')
:wikitext(string.format(" (%s)", self.removalNotice))
end
end
else
else
519行目: 570行目:
-- If we are using a div, redefine imageRightCell so that the image
-- If we are using a div, redefine imageRightCell so that the image
-- is inside it.
-- is inside it.
imageRightCell = imageRightCell:tag('div'):css('width', '52px')
imageRightCell = imageRightCell:tag('div'):addClass('mbox-image-div')
end
end
imageRightCell
imageRightCell
538行目: 589行目:
if self.invalidTypeError then
if self.invalidTypeError then
root:tag('div')
root:tag('div')
:css('text-align', 'center')
:addClass('mbox-invalid-type')
:wikitext(string.format(
:wikitext(string.format(
'このメッセージボックスには無効な"type=%s"というパラメータが指定されているため修正が必要です。',
'このメッセージボックスには無効な"type=%s"というパラメータが指定されているため修正が必要です。',
565行目: 616行目:


function p.main(boxType, args, cfgTables)
function p.main(boxType, args, cfgTables)
local box = MessageBox.new(boxType, args, cfgTables or mw.loadData('Module:Message box/configuration'))
local box = MessageBox.new(boxType, args, cfgTables or mw.loadData(CONFIG_MODULE))
box:setParameters()
box:setParameters()
box:setCategories()
box:setCategories()