Module:Article history: Difference between revisions

Content deleted Content added
rewrite the Row class internals to deal with function values from the config - other classes also need to be updated
use getter methods and override them for the Status class instead of overriding the exportHtml method
Line 133:
end
 
function Row:getIcon(...articleHistoryObj)
return maybeCallFunc(self.icon, ...articleHistoryObj, self)
end
 
function Row:getIconCaption(...articleHistoryObj)
return maybeCallFunc(self.iconCaption, ...articleHistoryObj, self)
end
 
Line 149:
end
 
function Row:renderIcon(...articleHistoryObj)
local icon = self:getIcon(...articleHistoryObj)
if not icon then
return nil
end
return renderImage(
icon,
self:getIconCaption(...articleHistoryObj),
self:getIconSize())
)
end
 
Line 163 ⟶ 167:
end
 
function Row:getNoticeBarIcon(...articleHistoryObj)
return maybeCallFunc(self.noticeBarIcon, ...articleHistoryObj, self)
end
 
function Row:getNoticeBarIconCaption(...articleHistoryObj)
return maybeCallFunc(self.noticeBarIconCaption, ...articleHistoryObj, self)
end
 
Line 175 ⟶ 179:
end
 
function Row:exportNoticeBarIcon(...articleHistoryObj)
local icon = self:getNoticeBarIcon(...articleHistoryObj)
if not icon then
return nil
Line 182 ⟶ 186:
return renderImage(
icon,
self.:getNoticeBarCaption(...articleHistoryObj),
self:getNoticeBarIconSize()
)
Line 191 ⟶ 195:
end
 
function Row:getText(...articleHistoryObj)
return maybeCallFunc(self.text, articleHistoryObj, self)
end
 
function Row:exportHtml(...articleHistoryObj)
local text = self:getText(...articleHistoryObj)
if not text then
return nil
Line 204 ⟶ 208:
:tag('td')
:addClass('mbox-image')
:wikitext(self:renderIcon(...articleHistoryObj))
:done()
:tag('td')
Line 218 ⟶ 222:
end
 
function Row:getCategories(...articleHistoryObj)
local ret = {}
if type(self.categories) == 'table' then
Line 225 ⟶ 229:
end
elseif type(self.categories) == 'function' then
forlocal _,t categoryObj= in ipairs(self.categories(...articleHistoryObj, self) or {}) do
for _, categoryObj in ipairs(t) do
ret[#ret + 1] = categoryObj
end
Line 244 ⟶ 249:
setmetatable(obj, Status)
 
-- Set the ID, status config and name
obj.id = data.id
local obj.statusCfg = obj.cfg.statuses[obj.id]
obj.statusCfgname = obj.statusCfg.name
obj:setIconValues(obj.name =statusCfg.icon, obj.statusCfg.iconCaption or obj.name)
obj:setText(obj.statusCfg.text)
obj:setCategories(obj.statusCfg.categories)
-- Set the icon
local iconSize
if data.iconSize then
iconSize = data.iconSize
elseif obj.isSmall then
iconSize = statusCfg.smallIconSize or obj.cfg.defaultSmallStatusIconSize or '30px'
else
iconSize = statusCfg.iconSize or obj.cfg.defaultStatusIconSize or '50px'
end
obj:setIconValues(statusCfg.icon, statusCfg.caption or obj.name, iconSize)
 
return obj
end
 
function Status:exportHtmlgetIconSize(articleHistoryObj)
if self.isSmall then
self:setText(substituteParams(
return self.statusCfg.smallIconSize or self.cfg.defaultSmallStatusIconSize or '30px'
maybeCallFunc(self.statusCfg.text, articleHistoryObj),
else
return self.statusCfg.iconSize or self.cfg.defaultStatusIconSize or '50px'
end
end
 
function Status:getText(articleHistoryObj)
local text = Row.getText(self, articleHistoryObj)
return substituteParams(
text,
self.currentTitle.subjectPageTitle.prefixedText,
self.currentTitle.text
))
return Row.exportHtml(self)
end
 
function Status:getCategories(articleHistoryObj)
self:setCategories(self.statusCfg.categories)
return Row.getCategories(self)
end
 
Line 498 ⟶ 496:
)
end
 
-- Set the categories
obj:setCategories(obj.actionCfg.categories)
 
return obj
Line 563 ⟶ 564:
 
return row
end
 
function Action:getCategories(articleHistoryObj)
local categories = self.actionCfg.categories
if type(categories) == 'table' then
local ret = {}
for _, cat in ipairs(categories) do
ret[#ret + 1] = Category.new(cat)
end
return ret
elseif type(categories) == 'function' then
return categories(self, articleHistoryObj)
end
end
 
Line 598 ⟶ 586:
)
obj:setText(data.text)
obj:setCollapsibleText(data.collapsibleText)
obj:setCategories(data.categories)
obj.collapsibleText = data.collapsibleText
 
return obj
end
 
function CollapsibleNotice:exportHtmlsetCollapsibleText(isInCollapsibleTables)
self.collapsibleText = s
if not self.text then
end
return nil
 
function CollapsibleNotice:getCollapsibleText(articleHistoryObj)
return maybeCallFun(self.collapsibleText, articleHistoryObj, self)
end
 
function CollapsibleNotice:getIconSize()
if self.isSmall then
return self.iconSmallSize
or self.cfg.defaultSmallCollapsibleNoticeIconSize
or '15px'
else
return self.iconSize
or self.cfg.defaultCollapsibleNoticeIconSize
or '20px'
end
end
 
function CollapsibleNotice:exportHtml(articleHistoryObj, isInCollapsibleTable)
-- Render the icon.
local text = self:getText(articleHistoryObj)
local icon
if self.iconnot text then
return nil
local iconSize
if self.isSmall then
iconSize = self.iconSmallSize
or self.cfg.defaultSmallCollapsibleNoticeIconSize
or '15px'
else
iconSize = self.iconSize
or self.cfg.defaultCollapsibleNoticeIconSize
or '20px'
end
icon = renderImage(self.icon, self.iconCaption, iconSize)
end
 
-- Render the HTML
local function maybeMakeCollapsibleTable(cell, text, collapsibleText)
-- If collapsible text is specified, makes a collapsible table inside
Line 659 ⟶ 651:
 
local html = mw.html.create('tr')
local icon = self:renderIcon(articleHistoryObj)
local collapsibleText = self:getCollapsibleText(articleHistoryObj)
if isInCollapsibleTable then
local textCell = html:tag('td')
:attr('colspan', 3)
:css('width', '100%')
local textrowText
if icon then
textrowText = icon .. ' ' .. self.text
else
textrowText = self.text
end
maybeMakeCollapsibleTable(textCell, textrowText, self.collapsibleText)
else
local textCell = html
Line 678 ⟶ 672:
:tag('td')
:addClass('mbox-text')
maybeMakeCollapsibleTable(textCell, self.text, self.collapsibleText)
end
 
Line 808 ⟶ 802:
-- user. We memoise this so that the parameters only have to be processed
-- once.
if self.actions ~= nil then
return self.actions
end
Line 857 ⟶ 851:
function ArticleHistory:getStatusObj()
-- Get the status object for the current status.
if self.statusObj ~== nilfalse then
return nil
elseif self.statusObj ~= nil then
return self.statusObj
end
Line 871 ⟶ 867:
if not statusId then
self.statusObj = false
return falsenil
end
 
Line 883 ⟶ 879:
local isMulti = self.cfg.statuses[statusId].isMulti
local initFunc = isMulti and MultiStatus.new or Status.new
local statusObj = self:try(initFunc, statusObjData) or false
self.statusObj = statusObj or false
return self.statusObj or nil
end
 
Line 893 ⟶ 889:
end
 
function ArticleHistory:getNoticeObjectsnoticeFactory(memoizeKey, configKey, class)
-- This holds the logic for fetching tables of Notice and CollapsibleNotice
-- Returns an array of notice objects to be output.
-- objects.
if self.notices ~= nil then
if self[memoizeKey] then
return self.notices
return self[memoizeKey]
end
local ret = {}
for i, funct in ipairs(self.cfg.notices[configKey] or {}) do
localif data = funct.isActive(self) then
if local data then= {}
for k, v in pairs(t) do
if k ~= 'isActive' then
data[k] = v
end
end
data.cfg = self.cfg
data.currentTitle = self.currentTitle
data.isSmall = self.isSmall
ret[#ret + 1] = Notice.new(data)
ret[#ret + 1] = class.new(data)
end
end
self.notices[memoizeKey] = ret
return ret
end
 
function ArticleHistory:getNoticeObjects()
return self:noticeFactory('notices', 'notices', Notice)
end
 
function ArticleHistory:getCollapsibleNoticeObjects()
return self:noticeFactory(
-- Returns an array of collapsible notice objects to be output.
if self. 'collapsibleNotices ~= nil then',
return self.'collapsibleNotices',
CollapsibleNotice
end
)
local ret = {}
for i, func in ipairs(self.cfg.collapsibleNotices or {}) do
local data = func(self)
if data then
data.cfg = self.cfg
data.currentTitle = self.currentTitle
ret[#ret + 1] = CollapsibleNotice.new(data)
end
end
self.collapsibleNotices = ret
return ret
end