self.imageEmptyCell = cfg.imageEmptyCell  
-- Left image settings.
local imageLeft = self.isSmall and args.smallimage or args.image
if cfg.imageCheckBlank and imageLeft ~= 'blank' and imageLeft ~= ''
or not cfg.imageCheckBlank and imageLeft ~= ''
then
self.imageLeft = imageLeft
if not imageLeft then
local imageSize = self.isSmall
and (cfg.imageSmallSize or '30x30px')
or '40x40px'
self.imageLeft = string.format('', self.typeImage
or 'Imbox notice.png', imageSize)
end
end  
-- Right image settings.
local imageRight = self.isSmall and args.smallimageright or args.imageright
if not (cfg.imageRightNone and imageRight == '') then
self.imageRight = imageRight
end  
-- set templatestyles
-- DIV MIGRATION CONDITIONAL
if cfg.div_templatestyles then
self.base_templatestyles = cfg.div_templatestyles
else
self.base_templatestyles = cfg.templatestyles
end
-- END DIV MIGRATION CONDITIONAL
self.templatestyles = args.templatestyles
end  
function MessageBox:setMainspaceCategories
local args = self.args
local cfg = self.cfg  
if not cfg.allowMainspaceCategories then
return nil
end  
local nums = {}
for _, prefix in ipairs{'cat', 'category', 'all'} do
args[prefix .. '1'] = args[prefix]
nums = union(nums, getArgNums(args, prefix))
end  
-- The following is roughly equivalent to the old .
local date = args.date
date = type(date) == 'string' and date
local preposition = 'from'
for _, num in ipairs(nums) do
local mainCat = args['cat' .. tostring(num)]
or args['category' .. tostring(num)]
local allCat = args['all' .. tostring(num)]
mainCat = type(mainCat) == 'string' and mainCat
allCat = type(allCat) == 'string' and allCat
if mainCat and date and date ~= '' then
local catTitle = string.format('%s %s %s', mainCat, preposition, date)
self:addCat(0, catTitle)
catTitle = getTitleObject('Category:' .. catTitle)
if not catTitle or not catTitle.exists then
self:addCat(0, 'Articles with invalid date parameter in template')
end
elseif mainCat and (not date or date == '') then
self:addCat(0, mainCat)
end
if allCat then
self:addCat(0, allCat)
end
end
end  
function MessageBox:setTemplateCategories
local args = self.args
local cfg = self.cfg  
-- Add template categories.
if cfg.templateCategory then
if cfg.templateCategoryRequireName then
if self.isTemplatePage then
self:addCat(10, cfg.templateCategory)
end
elseif not self.title.isSubpage then
self:addCat(10, cfg.templateCategory)
end
end  
-- Add template error categories.
if cfg.templateErrorCategory then
local templateErrorCategory = cfg.templateErrorCategory
local templateCat, templateSort
if not self.name and not self.title.isSubpage then
templateCat = templateErrorCategory
elseif self.isTemplatePage then
local paramsToCheck = cfg.templateErrorParamsToCheck or {}
local count = 0
for i, param in ipairs(paramsToCheck) do
if not args[param] then
count = count + 1
end
end
if count > 0 then
templateCat = templateErrorCategory
templateSort = tostring(count)
end
if self.categoryNums and #self.categoryNums > 0 then
templateCat = templateErrorCategory
templateSort = 'C'
end
end
self:addCat(10, templateCat, templateSort)
end
end  
function MessageBox:setAllNamespaceCategories
-- Set categories for all namespaces.
if self.invalidTypeError then
local allSort = (self.title.namespace == 0 and 'Main:' or '') .. self.title.prefixedText
self:addCat('all', 'Wikipedia message box parameter needs fixing', allSort)
end
if self.isSubstituted then
self:addCat('all', 'Pages with incorrectly substituted templates')
end
end  
function MessageBox:setCategories
if self.title.namespace == 0 then
self:setMainspaceCategories
elseif self.title.namespace == 10 then
self:setTemplateCategories
end
self:setAllNamespaceCategories
end  
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
-- Module:Category handler.
return require('Module:Category handler')._main{
main = table.concat(self.categories[0] or {}),
template = table.concat(self.categories[10] or {}),
all = table.concat(self.categories.all or {}),
nocat = self.args.nocat,
page = self.args.page
}
end  
function MessageBox:exportDiv
local root = mw.html.create  
-- Add the subst check error.
if self.isSubstituted and self.name then
root:tag('b')
:addClass('error')
:wikitext(string.format(
'Template <code>%s%s%s</code> has been incorrectly substituted.',
mw.text.nowiki('')
))
end  
local = mw.getCurrentFrame
root:wikitext(: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(:extensionTag{
name = 'templatestyles',
args = { src = self.templatestyles },
})
end  
-- Create the box table.
local mbox = root:tag('div')
mbox:attr('id', self.id or nil)
for i, class in ipairs(self.classes or {}) do
mbox:addClass(class or nil)
end
mbox
:cssText(self.style or nil)  
if self.attrs then
mbox:attr(self.attrs)
end  
-- Add the -hand image.
if self.imageLeft then
local imageLeftCell = mbox:tag('div'):addClass('mbox-image')
imageLeftCell:wikitext(self.imageLeft or nil)
end  
-- Add the text.
local textCell = mbox:tag('div'):addClass('mbox-text')
if self.useCollapsibleTextFields then
-- The message box uses advanced text parameters that allow things to be
-- collapsible. At the moment, only ambox uses this.
textCell:cssText(self.textstyle or nil)
local textCellDiv = textCell:tag('div')
textCellDiv
:addClass('mbox-text-span')
:wikitext(self.issue or nil)
if (self.talk or self.fix) then
textCellDiv:tag('span')
:addClass('hide-when-compact')
:wikitext(self.talk and (' ' .. self.talk) or nil)
:wikitext(self.fix and (' ' .. self.fix) or nil)
end
textCellDiv:wikitext(self.date and (' ' .. self.date) or nil)
if self.info and not self.isSmall then
textCellDiv
:tag('span')
:addClass('hide-when-compact')
: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
else
-- Default text formatting - anything goes.
textCell
:cssText(self.textstyle or nil)
:wikitext(self.text or nil)
end  
-- Add the -hand image.
if self.imageRight then
local imageRightCell = mbox:tag('div'):addClass('mbox-imageright')
imageRightCell
:wikitext(self.imageRight or nil)
end  
-- Add the below row.
if self.below then
mbox:tag('div')
:addClass('mbox-text')
:cssText(self.textstyle or nil)
:wikitext(self.below or nil)
end  
-- Add error message for invalid type parameters.
if self.invalidTypeError then
root:tag('div')
:addClass('mbox-invalid-type')
:wikitext(string.format(
'This message box is using an invalid "type=%s" parameter and needs fixing.',
self.type or ''
))
end  
-- Add categories.
root:wikitext(self:renderCategories or nil)  
return tostring(root)
end  
function MessageBox:export  
local root = mw.html.create  
-- Add the subst check error.
if self.isSubstituted and self.name then
root:tag('b')
:addClass('error')
:wikitext(string.format(
'Template <code>%s%s%s</code> has been incorrectly substituted.',
mw.text.nowiki('')
))
end  
local = mw.getCurrentFrame
root:wikitext(: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(:extensionTag{
name = 'templatestyles',
args = { src = self.templatestyles },
})
end  
-- Create the box table.
local boxTable = root:tag('table')