Content deleted Content added
add a Category class to standardise category processing |
write ArticleHistory:renderBox and add ArticleHistory:message |
||
Line 14:
-- Load required modules.
local checkType = require('libraryUtil').checkType
local yesno = require('Module:Yesno')
-------------------------------------------------------------------------------
Line 24 ⟶ 25:
and num > 0
and num < math.huge
end
Line 218 ⟶ 215:
-- Define object structure
obj.actions = {}
-- Set isSmall
obj.isSmall = yesno(obj.args.small) or false
-- Format the config
Line 286 ⟶ 284:
return obj
end
function ArticleHistory:message(key, ...)
local msg = self.cfg.msg[key]
if select('#', ...) > 0 then
return mw.message.newRawMessage(msg, ...):plain()
else
return msg
end
end
Line 326 ⟶ 333:
end
function ArticleHistory:
-- Returns an array of notice objects to be output.
local ret = {}
return ret
end
function ArticleHistory:
-- Returns an array of collapsible notice objects to be output.
local ret = {}
return ret
end
function ArticleHistory:renderBox()
local root = mw.html.create('table')
root
:addClass('tmbox tmbox-notice')
:addClass(self.isSmall and 'mbox-small' or nil)
-- Status
local statusObj = self:getStatusObj()
if statusObj then
root:node(statusObj:exportHtml())
end
-- Notices
local notices = self:getNoticeObjects()
for _, noticeObj in ipairs(notices) do
root:node(noticeObj:exportHtml())
end
-- Get the count of collapsible rows
local collapsibleNotices = self:getCollapsibleNoticeObjects()
local noCollapsibleRows = #self.actions + #collapsibleNotices
-- Collapsible table for actions and collapsible notices
if noCollapsibleRows > 0 then
-- Find out if we are collapsed or not.
local isCollapsed
if self.cfg.uncollapsedRows == 'all' then
isCollapsed = false
else
isCollapsed = noCollapsibleRows > (tonumber(self.cfg.uncollapsedRows) or 3)
end
-- Collapsible table base
local collapsibleTable = root
:tag('tr')
:tag('td')
:attr('colspan', 2)
:css('width', '100%')
:tag('table')
:addClass('AH-milestones')
:addClass(isCollapsed and 'collapsible collapsed' or nil)
:css('width', '100%')
:css('background', 'transparent')
:css('font-size', '90%')
-- Header row
local ctHeader = collapsibleTable
:tag('tr')
:tag('th')
:attr('colspan', 3)
:css('font-size', '110%')
local noticeBarIcons = {}
for i, t in ipairs{notices, collapsiblenotices, self.actions} do
for j, obj in ipairs(t) do
table.insert(noticeBarIcons, obj:exportNoticeBarIcon())
end
end
if #noticeBarIcons > 0 then
local noticeBar = ctHeader:tag('span'):css('float', 'left')
for _, icon in ipairs(noticeBarIcons) do
noticeBar:wikitext(icon)
end
ctHeader:wikitext(' ')
end
if mw.site.namespaces[self.currentTitle.namespace].subject.id == 0 then
ctHeader:wikitext(self:message('milestones-header'))
else
ctHeader:wikitext(self:message(
'milestones-header-other-ns',
self.currentTitle.subjectNsText
))
end
-- Subheadings
collapsibleTable
:tag('tr')
:css('text-align', 'left')
:tag('th')
:wikitext(self:message('milestones-date-header'))
:done()
:tag('th')
:wikitext(self:message('milestones-process-header'))
:done()
:tag('th')
:wikitext(self:message('milestones-result-header'))
-- Actions and collapsible notices
for i, t in ipairs{self.actions, collapsibleNotices} do
for j, obj in ipairs(t) do
collapsibleTable:node(obj:exportHtml())
end
end
end
return tostring(root)
end
Line 346 ⟶ 453:
function ArticleHistory:__tostring()
return self:renderBox() .. self:renderCategories()
end
Line 355 ⟶ 463:
local p = {}
function p._main(args, cfg, currentTitle)
local articleHistoryObj = ArticleHistory.new(args, cfg, currentTitle)
return tostring(articleHistoryObj)
end
|