Module:Article history: Difference between revisions

Content deleted Content added
make collapsible notices display outside the action table if the action table is not collapsed
rewrite the Row class internals to deal with function values from the config - other classes also need to be updated
Line 123:
obj.currentTitle = data.currentTitle
obj.isSmall = data.isSmall
obj.categories = {}
return obj
end
 
function Row:setIconsetIconValues(icon, caption, size, smallSize)
self.icon = icon
self.captioniconCaption = caption
self.iconSize = size
self.iconSmallSize = smallSize
end
 
function Row:setTextgetIcon(text...)
return maybeCallFunc(self.icon, ...)
self.text = text
end
 
function Row:exportHtmlgetIconCaption(...)
return maybeCallFunc(self.iconCaption, ...)
if not self.text then
end
 
function Row:getIconSize()
if self.isSmall then
return self.iconSmallSize or self.cfg.defaultSmallIconSize or '15px'
else
return self.iconSize or self.cfg.defaultIconSize or '30px'
end
end
 
function Row:renderIcon(...)
local icon = self:getIcon(...)
if not icon then
return nil
end
return renderImage(icon, self:getIconCaption(...), self:getIconSize())
end
 
function Row:setNoticeBarIconValues(icon, caption, size)
local html = mw.html.create('tr')
self.noticeBarIcon = icon
self.noticeBarIconCaption = caption
self.noticeBarIconSize = size
end
 
function Row:getNoticeBarIcon(...)
-- Render the icon link.
return maybeCallFunc(self.noticeBarIcon, ...)
local icon
end
if self.icon then
 
local iconSize
function Row:getNoticeBarIconCaption(...)
if self.isSmall then
return maybeCallFunc(self.noticeBarIconCaption, ...)
iconSize = self.iconSmallSize or self.cfg.defaultSmallIconSize or '15px'
end
else
 
iconSize = self.iconSize or self.cfg.defaultIconSize or '30px'
function Row:getNoticeBarIconSize()
end
return self.noticeBarIconSize or self.cfg.defaultNoticeBarIconSize or '15px'
icon = renderImage(self.icon, self.caption, iconSize)
end
 
function Row:exportNoticeBarIcon(...)
local icon = self:getNoticeBarIcon(...)
if not icon then
return nil
end
return renderImage(
icon,
self.getNoticeBarCaption(...),
self:getNoticeBarIconSize()
)
end
 
function Row:setText(text)
-- Render the HTML
self.text = text
end
 
function Row:getText(...)
return maybeCallFunc(self.text)
end
 
function Row:exportHtml(...)
local text = self:getText(...)
if not text then
return nil
end
local html = mw.html.create('tr')
html
:tag('td')
:addClass('mbox-image')
:wikitext(iconself:renderIcon(...))
:done()
:tag('td')
:addClass('mbox-text')
:wikitext(self.text)
 
return html
end
 
function Row:addCategoriessetCategories(val, ...)
-- AddSet the categories tofrom the object's categories tableconfig. val can be either an array
-- array of strings, or a function returning an array of category objects, or a function returning.
self.categories = val
-- an array of category objects.
end
if type(val) == 'table' then
 
for _, cat in ipairs(val) do
function Row:getCategories(...)
if type(cat) == 'string' then
local ret = {}
table.insert(self.categories, Category.new(cat))
if type(self.categories) == 'table' then
else
table.insertfor _, cat in ipairs(self.categories, cat) do
ret[#ret + 1] = Category.new(cat)
end
end
elseif type(valself.categories) == 'function' then
for _, categoryObj in ipairs(valself.categories(...) or {}) do
table.insert(self.categories,ret[#ret + 1] = categoryObj)
end
end
return ret
end
 
function Row:exportCategories()
return self.categories
end
 
function Row:setNoticeBarIcon(icon, caption, size)
self.noticeBarIcon = icon
self.noticeBarCaption = caption
self.noticeBarIconSize = size
end
 
function Row:exportNoticeBarIcon()
if not self.noticeBarIcon then
return nil
end
local size = self.noticeBarIconSize or self.cfg.defaultNoticeBarIconSize or '15px'
return renderImage(self.noticeBarIcon, size, self.noticeBarCaption)
end
 
Line 234 ⟶ 259:
iconSize = statusCfg.iconSize or obj.cfg.defaultStatusIconSize or '50px'
end
obj:setIconsetIconValues(statusCfg.icon, statusCfg.caption or obj.name, iconSize)
 
return obj
Line 248 ⟶ 273:
end
 
function Status:exportCategoriesgetCategories(articleHistoryObj)
self:addCategoriessetCategories(self.statusCfg.categories, articleHistoryObj)
return Row.exportCategoriesgetCategories(self)
end
 
Line 300 ⟶ 325:
end
 
function MultiStatus:exportCategoriesgetCategories(articleHistoryObj)
local ret = {}
for i, obj in ipairs(self.statuses) do
for j, categoryObj in ipairs(obj:exportCategoriesgetCategories(articleHistoryObj)) do
ret[#ret + 1] = categoryObj
end
Line 341 ⟶ 366:
setmetatable(obj, Notice)
 
obj:setIconsetIconValues(
data.icon,
data.iconCaption,
Line 348 ⟶ 373:
)
obj:setText(data.text)
obj:addCategoriessetCategories(data.categories)
 
return obj
Line 540 ⟶ 565:
end
 
function Action:exportCategoriesgetCategories(articleHistoryObj)
local categories = self.actionCfg.categories
if type(categories) == 'table' then
Line 566 ⟶ 591:
setmetatable(obj, CollapsibleNotice)
 
obj:setIconsetIconValues(
data.icon,
data.iconCaption,
Line 573 ⟶ 598:
)
obj:setText(data.text)
obj:addCategoriessetCategories(data.categories)
obj.collapsibleText = data.collapsibleText
 
Line 597 ⟶ 622:
or '20px'
end
icon = renderImage(self.icon, self.captioniconCaption, iconSize)
end
 
Line 1,114 ⟶ 1,139:
-- Child object categories
for i, obj in ipairs(self:getAllObjects()) do
local categories = self:try(obj.exportCategoriesgetCategories, obj, self)
for j, categoryObj in ipairs(categories or {}) do
ret[#ret + 1] = tostring(categoryObj)