Content deleted Content added
add Row:cachedTry, to standardise caching for methods called multiple times |
per edit request on talk page - remove line as unnecessary |
||
(24 intermediate revisions by 6 users not shown) | |||
Line 13:
-- Load required modules.
require('
local Category = require('Module:Article history/Category')
local yesno = require('Module:Yesno')
Line 127:
obj.cfg = data.cfg
obj.currentTitle = data.currentTitle
obj.makeData = data.makeData -- used by Row:getData
return obj
Line 154 ⟶ 153:
end
local success
if DEBUG_MODE then
success = true
ret = func()
else
success, ret = pcall(func)
end
if success then
if ret then
Line 177 ⟶ 181:
end
function Row:setIconValues(icon, caption, size
self.icon = icon
self.iconCaption = caption
self.iconSize = size
end
Line 193 ⟶ 196:
function Row:getIconSize()
return self.iconSize or self.cfg.defaultIconSize or '30px'
end
Line 342 ⟶ 341:
function Status:getIconSize()
end
function Status:getText(articleHistoryObj)
local text = Row.getText(self, articleHistoryObj)
if text then
return substituteParams(
text,
self.currentTitle.
self.currentTitle.text
)
end
end
Line 376 ⟶ 371:
setmetatable(obj, MultiStatus)
obj.id = data.id
obj.statusCfg = obj.cfg.statuses[data.id]
obj.name = obj.statusCfg.name
Line 390 ⟶ 386:
end
obj.statuses = {}
local defaultIconSize = obj.cfg.
for
table.insert(obj.statuses, Status.new(getChildStatusData(
data,
Line 404 ⟶ 400:
function MultiStatus:exportHtml(articleHistoryObj)
local ret = mw.html.create()
for
ret:node(obj:exportHtml(articleHistoryObj))
end
Line 412 ⟶ 408:
function MultiStatus:getCategories(articleHistoryObj)
local ret = {}
for
for
ret[#ret + 1] = categoryObj
end
Line 422 ⟶ 418:
function MultiStatus:exportNoticeBarIcon()
local ret = {}
for
ret[#ret + 1] = obj:exportNoticeBarIcon()
end
Line 430 ⟶ 426:
function MultiStatus:getWarnings()
local ret = {}
for
for
ret[#ret + 1] = msg
end
Line 454 ⟶ 450:
data.icon,
data.iconCaption,
data.iconSize
)
obj:setNoticeBarIconValues(
Line 557 ⟶ 552:
obj:addWarning(
obj:message(
'action-
data.date,
obj:getParameter('date')
),
obj:message('action-
)
end
Line 567 ⟶ 562:
obj:addWarning(
obj:message(
'action-
obj.paramNum,
obj:getParameter('date'),
obj:getParameter('code')
),
obj:message('action-
)
end
Line 580 ⟶ 575:
obj.oldid = tonumber(data.oldid)
if data.oldid and (not obj.oldid or not isPositiveInteger(obj.oldid)) then
obj
obj:addWarning(
obj:message(
'action-
data.oldid,
obj:getParameter('oldid')
),
obj:message('action-
)
end
Line 661 ⟶ 657:
self:getName(articleHistoryObj)
))
-- Result cell
row
Line 687 ⟶ 683:
data.icon,
data.iconCaption,
data.iconSize
)
obj:setNoticeBarIconValues(
Line 711 ⟶ 706:
function CollapsibleNotice:getIconSize()
or self.cfg.defaultCollapsibleNoticeIconSize
or '20px'
end
Line 740 ⟶ 729:
if collapsibleText then
cell
:tag('
:addClass('mw-collapsible mw-collapsed')
:
:
:done()
:tag('
:
else
cell:wikitext(text)
Line 808 ⟶ 787:
obj.args = args or {}
obj.currentTitle = currentTitle or mw.title.getCurrentTitle()
-- Define object structure.
obj._errors = {}
obj._allObjectsCache = {}
-- Format the config
local function substituteAliases(t, ret)
Line 932 ⟶ 908:
local actions = {}
local suffixes = self.cfg.actionParamSuffixes
for
local objArgs = {}
for k, v in pairs(t) do
Line 962 ⟶ 938:
else
self:addWarning(
self:message('articlehistory-
self:message('articlehistory-
)
return nil
Line 1,003 ⟶ 979:
id = statusId,
currentTitle = self.currentTitle,
cfg = self.cfg
}
local isMulti = self.cfg.statuses[statusId].isMulti
Line 1,025 ⟶ 1,000:
end
local ret = {}
for
if t.isActive(self) then
local data = {}
Line 1,035 ⟶ 1,010:
data.cfg = self.cfg
data.currentTitle = self.currentTitle
ret[#ret + 1] = class.new(data)
end
Line 1,069 ⟶ 1,043:
self:getCollapsibleNoticeObjects()
}
for
for
ret[#ret + 1] = obj
end
Line 1,109 ⟶ 1,083:
ret[#ret + 1] = msg
end
for
for
ret[#ret + 1] = msg
end
end
return ret
end
function ArticleHistory:categoriesAreActive()
-- Returns a boolean indicating whether categories should be output or not.
local title = self.currentTitle
local ns = title.namespace
return title.isTalkPage
and ns ~= 3 -- not user talk
and ns ~= 119 -- not draft talk
end
Line 1,120 ⟶ 1,103:
local ret = {}
if self:categoriesAreActive() then
-- Child object categories
for _, obj in ipairs(self:getAllObjects()) do
local categories = self:try(obj.getCategories, obj, self)
for _, categoryObj in ipairs(categories or {}) do
ret[#ret + 1] = tostring(categoryObj)
end
end
local cats = func(self) or {}
for
ret[#ret + 1] = tostring(categoryObj)
end
end
end
Line 1,140 ⟶ 1,125:
function ArticleHistory:__tostring()
local root = mw.html.create()
-- Table root
local tableRoot = root:tag('table')
tableRoot:addClass('article-history tmbox tmbox-notice')
-- Status
local statusObj = self:getStatusObj()
Line 1,186 ⟶ 1,162:
)
end
local
local nCollapsibleRows = nActionRows + #collapsibleNoticeHtmlObjects
-- Find out if we are collapsed or not.
local isCollapsed = yesno(self.args.collapse)
if
if self.cfg.uncollapsedRows == 'all' then
isCollapsed = false
elseif nCollapsibleRows == 1 then
isCollapsed = false
else
isCollapsed = nCollapsibleRows > (tonumber(self.cfg.uncollapsedRows) or 3)
end
end
Line 1,213 ⟶ 1,192:
-- notices are only included in the table if it is collapsed. Action rows
-- are always included.
local collapsibleTable
if isCollapsed or nActionRows > 0 then
-- Collapsible table base
:tag('tr')
:tag('td')
Line 1,221 ⟶ 1,201:
:css('width', '100%')
:tag('table')
:addClass('
:addClass(isCollapsed and 'mw-collapsible mw-collapsed' or nil)
:css('width', '100%')
:css('font-size', '90%')
-- Header row
local ctHeader = collapsibleTable
:tag('tr')
:tag('
:
end
ctHeader:wikitext(' ')
end
end
end
Line 1,277 ⟶ 1,254:
collapsibleTable:node(htmlObj)
end
end
-- Collapsible notices and current status
-- Otherwise, they are added afterwards, so that they align with the
-- notices.
do
local tableNode, statusColspan
if isCollapsed then
tableNode = collapsibleTable
statusColspan = 3
tableNode = tableRoot
statusColspan = 2
end
--
for _, obj in ipairs(collapsibleNotices) do
tableNode:node(self:try(obj.exportHtml, obj, self, isCollapsed))
end
-- Current status
if statusObj and nActionRows > 1 then
tableNode
:tag('tr')
:tag('td')
:attr('colspan',
:wikitext(self:message('status-blurb',
end
end
-- Get the categories. We have to do this before the error row, so that
Line 1,329 ⟶ 1,304:
errorList:tag('li'):wikitext(msg)
end
if self:categoriesAreActive() then
errorCategory = tostring(Category.new(self:message( 'error-category' ))) end
-- If there are no errors and no active objects, then exit. We can't make
-- this check earlier as we don't know where the errors may be until we
-- have finished rendering the banner.
elseif #self:getAllObjects() < 1 then
return ''
end
Line 1,335 ⟶ 1,320:
root:wikitext(categories)
root:wikitext(errorCategory)
local frame = mw.getCurrentFrame()
return frame:extensionTag{
name = 'templatestyles', args = { src = 'Module:Message box/tmbox.css' }
} .. frame:extensionTag{
name = 'templatestyles', args = { src = 'Module:Article history/styles.css' }
} .. tostring(root)
end
Line 1,355 ⟶ 1,345:
wrappers = WRAPPER_TEMPLATE
})
if frame:getTitle():find('sandbox', 1, true) then
CONFIG_PAGE = CONFIG_PAGE .. '/sandbox'
end
return p._main(args)
end
|