Content deleted Content added
Make ArticleHistory.errors private |
per edit request on talk page - remove line as unnecessary |
||
(39 intermediate revisions by 6 users not shown) | |||
Line 10:
local CONFIG_PAGE = 'Module:Article history/config'
local WRAPPER_TEMPLATE = 'Template:Article history'
local DEBUG_MODE =
-- 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
end
function Row:
-- This method is for use in Row object methods that are called more than
-- once. The results of such methods should be cached to avoid unnecessary
-- processing. We also cache any errors found and abort if an error was
-- raised previously, otherwise error messages could be displayed multiple
-- times.
--
-- We use false as a key to cache nil results, so func cannot return false.
--
-- @param cacheKey The key to cache successful results with
-- @param errorCacheKey The key to cache errors with
-- @param func an anonymous function that returns the method result
if self[errorCacheKey] then
return nil
end
local ret = self[cacheKey]
if ret then
return ret
elseif ret == false then
return nil
end
local success
if DEBUG_MODE then
success = true
ret = func()
else
success, ret = pcall(func)
end
if success then
if ret then
self[cacheKey] = ret
return ret
else
self[cacheKey] = false
return nil
end
else
self[errorCacheKey] = true
-- We have already formatted the error message, so no need to format it
-- again.
error(ret, 0)
end
end
function Row:getData(articleHistoryObj)
return self:_cachedTry('_dataCache', '_isDataError', function ()
return self.makeData(articleHistoryObj)
end)
end
function Row:setIconValues(icon, caption, size
self.icon = icon
self.iconCaption = caption
self.iconSize = size
end
Line 163 ⟶ 196:
function Row:getIconSize()
return self.iconSize or self.cfg.defaultIconSize or '30px'
end
Line 239 ⟶ 268:
function Row:exportHtml(articleHistoryObj)
if self._html then
return self._html
end
local text = self:getText(articleHistoryObj)
if not text then
Line 252 ⟶ 284:
:addClass('mbox-text')
:wikitext(text)
self._html = html
return html
end
Line 308 ⟶ 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 342 ⟶ 371:
setmetatable(obj, MultiStatus)
obj.id = data.id
obj.statusCfg = obj.cfg.statuses[data.id]
obj.name = obj.statusCfg.name
Line 356 ⟶ 386:
end
obj.statuses = {}
local defaultIconSize = obj.cfg.
for
table.insert(obj.statuses, Status.new(getChildStatusData(
data,
Line 370 ⟶ 400:
function MultiStatus:exportHtml(articleHistoryObj)
local ret = mw.html.create()
for
ret:node(obj:exportHtml(articleHistoryObj))
end
Line 378 ⟶ 408:
function MultiStatus:getCategories(articleHistoryObj)
local ret = {}
for
for
ret[#ret + 1] = categoryObj
end
Line 388 ⟶ 418:
function MultiStatus:exportNoticeBarIcon()
local ret = {}
for
ret[#ret + 1] = obj:exportNoticeBarIcon()
end
Line 396 ⟶ 426:
function MultiStatus:getWarnings()
local ret = {}
for
for
ret[#ret + 1] = msg
end
Line 420 ⟶ 450:
data.icon,
data.iconCaption,
data.iconSize
)
obj:setNoticeBarIconValues(
Line 523 ⟶ 552:
obj:addWarning(
obj:message(
'action-
data.date,
obj:getParameter('date')
),
obj:message('action-
)
end
Line 533 ⟶ 562:
obj:addWarning(
obj:message(
'action-
obj.paramNum,
obj:getParameter('date'),
obj:getParameter('code')
),
obj:message('action-
)
end
Line 545 ⟶ 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 598 ⟶ 629:
function Action:exportHtml(articleHistoryObj)
if self._html then
return self._html
end
local row = mw.html.create('tr')
Line 622 ⟶ 657:
self:getName(articleHistoryObj)
))
-- Result cell
row
Line 628 ⟶ 663:
:wikitext(self:getResult(articleHistoryObj))
self._html = row
return row
end
Line 647 ⟶ 683:
data.icon,
data.iconCaption,
data.iconSize
)
obj:setNoticeBarIconValues(
Line 671 ⟶ 706:
function CollapsibleNotice:getIconSize()
or self.cfg.defaultCollapsibleNoticeIconSize
or '20px'
end
function CollapsibleNotice:exportHtml(articleHistoryObj, isInCollapsibleTable)
local
and '_htmlCacheCollapsible'
or '_htmlCacheDefault'
return self:_cachedTry(cacheKey, '_isHtmlError', function ()
local text = self:getText(articleHistoryObj)
if not text then
return nil
end
-- If collapsible text is specified, makes a collapsible table
-- inside the cell with two rows, a header row with one cell and a
-- collapsed row with one cell. These are filled with text and
-- collapsedText, respectively. If no collapsible text is
-- specified, the text is added to the cell as-is. if collapsibleText then
cell
:tag('div')
:addClass('mw-collapsible mw-collapsed')
:
:wikitext(text)
:done()
:
:
:css('border', '1px silver solid')
:wikitext(collapsibleText)
else
cell:wikitext(text)
end
end
local textCell = html:tag('td')
:attr('colspan', 3)
:css('width', '100%')
local rowText
if icon then
rowText = icon .. ' ' .. text
else
rowText = text
end
maybeMakeCollapsibleTable(textCell, rowText, collapsibleText)
else
:tag('td')
:addClass('mbox-image')
:wikitext(icon)
:done()
:tag('td')
:addClass('mbox-text')
maybeMakeCollapsibleTable(textCell, text, collapsibleText)
end
end)
end
Line 763 ⟶ 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 887 ⟶ 908:
local actions = {}
local suffixes = self.cfg.actionParamSuffixes
for
local objArgs = {}
for k, v in pairs(t) do
Line 912 ⟶ 933:
end
local statuses = self.cfg.statuses
if statuses[
return statuses[
else
self:addWarning(
self:message('articlehistory-warning-invalid-status', code),
self:message('articlehistory-warning-invalid-status-help')
)
return nil
end
end
Line 929 ⟶ 954:
local statusId
if self.cfg.getStatusIdFunction then
statusId = self:try(self.cfg.getStatusIdFunction
else
statusId = self:try(
Line 939 ⟶ 964:
self.statusObj = false
return nil
end
-- Check that some actions were specified, and if not add a warning.
local actions = self:getActionObjects()
if #actions < 1 then
self:addWarning(
self:message('articlehistory-warning-status-no-actions'),
self:message('articlehistory-warning-status-no-actions-help')
)
end
Line 945 ⟶ 979:
id = statusId,
currentTitle = self.currentTitle,
cfg = self.cfg
}
local isMulti = self.cfg.statuses[statusId].isMulti
Line 967 ⟶ 1,000:
end
local ret = {}
for
if t.isActive(self) then
local data = {}
Line 977 ⟶ 1,010:
data.cfg = self.cfg
data.currentTitle = self.currentTitle
ret[#ret + 1] = class.new(data)
end
Line 1,011 ⟶ 1,043:
self:getCollapsibleNoticeObjects()
}
for
for
ret[#ret + 1] = obj
end
Line 1,051 ⟶ 1,083:
ret[#ret + 1] = msg
end
for
for
ret[#ret + 1] = msg
end
Line 1,059 ⟶ 1,091:
end
function ArticleHistory:
-- 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
function ArticleHistory:renderCategories()
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
-- Extra categories
for _, func in ipairs(self.cfg.extraCategories or {}) do
local cats = func(self) or {}
for _, categoryObj in ipairs(cats) do
ret[#ret + 1] = tostring(categoryObj)
end
end
end
return table.concat(ret)
end
function ArticleHistory:__tostring()
local root = mw.html.create()
-- Table root
local
-- Status
local statusObj = self:getStatusObj()
if statusObj then
end
Line 1,082 ⟶ 1,140:
local notices = self:getNoticeObjects()
for _, noticeObj in ipairs(notices) do
end
Line 1,104 ⟶ 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,131 ⟶ 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,139 ⟶ 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,195 ⟶ 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
-- category errors display.
local categories = self:renderCategories()
-- Error row and error category
local errors = self:getErrorMessages()
local errorCategory
if #errors > 0 then
local errorList =
:tag('tr')
:tag('td')
Line 1,242 ⟶ 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
--
root:wikitext(categories)
root:wikitext(errorCategory)
local frame = mw.getCurrentFrame()
return
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,299 ⟶ 1,345:
wrappers = WRAPPER_TEMPLATE
})
if frame:getTitle():find('sandbox', 1, true) then
CONFIG_PAGE = CONFIG_PAGE .. '/sandbox'
end
return p._main(args)
end
|