Module:Article history: Difference between revisions

Content deleted Content added
Undid revision 642591985 by Mr. Stradivarius (talk) let's keep things the same as the current template until we roll this out
per edit request on talk page - remove line as unnecessary
 
(16 intermediate revisions by 6 users not shown)
Line 13:
 
-- Load required modules.
require('Module:No globalsstrict')
local Category = require('Module:Article history/Category')
local yesno = require('Module:Yesno')
Line 127:
obj.cfg = data.cfg
obj.currentTitle = data.currentTitle
obj.isSmall = data.isSmall
obj.makeData = data.makeData -- used by Row:getData
return obj
Line 182 ⟶ 181:
end
 
function Row:setIconValues(icon, caption, size, smallSize)
self.icon = icon
self.iconCaption = caption
self.iconSize = size
self.iconSmallSize = smallSize
end
 
Line 198 ⟶ 196:
 
function Row:getIconSize()
return self.iconSize or self.cfg.defaultIconSize or '30px'
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
 
Line 347 ⟶ 341:
 
function Status:getIconSize()
ifreturn self.isSmall theniconSize
returnor self.statusCfg.smallIconSizeiconSize
or self.cfg.defaultSmallStatusIconSizedefaultStatusIconSize
or '30px50px'
else
return self.iconSize
or self.statusCfg.iconSize
or self.cfg.defaultStatusIconSize
or '50px'
end
end
 
function Status:getText(articleHistoryObj)
local text = Row.getText(self, articleHistoryObj)
if text then
return substituteParams(
return substituteParams(
text,
text,
self.currentTitle.subjectPageTitle.prefixedText,
self.currentTitle.textsubjectPageTitle.prefixedText,
self.currentTitle.text
)
)
end
end
 
Line 396 ⟶ 386:
end
obj.statuses = {}
local defaultIconSize = obj.cfg.defaultSmallStatusIconSizedefaultMultiStatusIconSize or '30px'
for i_, id in ipairs(obj.statusCfg.statuses) do
table.insert(obj.statuses, Status.new(getChildStatusData(
data,
Line 410 ⟶ 400:
function MultiStatus:exportHtml(articleHistoryObj)
local ret = mw.html.create()
for i_, obj in ipairs(self.statuses) do
ret:node(obj:exportHtml(articleHistoryObj))
end
Line 418 ⟶ 408:
function MultiStatus:getCategories(articleHistoryObj)
local ret = {}
for i_, obj in ipairs(self.statuses) do
for j_, categoryObj in ipairs(obj:getCategories(articleHistoryObj)) do
ret[#ret + 1] = categoryObj
end
Line 428 ⟶ 418:
function MultiStatus:exportNoticeBarIcon()
local ret = {}
for i_, obj in ipairs(self.statuses) do
ret[#ret + 1] = obj:exportNoticeBarIcon()
end
Line 436 ⟶ 426:
function MultiStatus:getWarnings()
local ret = {}
for i_, obj in ipairs(self.statuses) do
for j_, msg in ipairs(obj:getWarnings()) do
ret[#ret + 1] = msg
end
Line 460 ⟶ 450:
data.icon,
data.iconCaption,
data.iconSize,
data.iconSmallSize
)
obj:setNoticeBarIconValues(
Line 668 ⟶ 657:
self:getName(articleHistoryObj)
))
 
-- Result cell
row
Line 694 ⟶ 683:
data.icon,
data.iconCaption,
data.iconSize,
data.iconSmallSize
)
obj:setNoticeBarIconValues(
Line 718 ⟶ 706:
 
function CollapsibleNotice:getIconSize()
ifreturn self.isSmall theniconSize
or self.cfg.defaultCollapsibleNoticeIconSize
return self.iconSmallSize
or '20px'
or self.cfg.defaultSmallCollapsibleNoticeIconSize
or '15px'
else
return self.iconSize
or self.cfg.defaultCollapsibleNoticeIconSize
or '20px'
end
end
 
Line 747 ⟶ 729:
if collapsibleText then
cell
:tag('tablediv')
:addClass('mw-collapsible mw-collapsed')
:csstag('margindiv', 0)
:csswikitext('padding', 0text)
:css('border-collapse', 'collapse')
:css('width', '100%')
:css('background', 'transparent')
:tag('tr')
:tag('th')
:css('font-weight', 'normal')
:css('text-align', 'left')
:css('width', '100%')
:wikitext(text)
:done()
:done()
:tag('trdiv')
:tagaddClass('tdmw-collapsible-content')
:css('border', '1px silver solid')
:wikitext(collapsibleText)
else
cell:wikitext(text)
Line 815 ⟶ 787:
obj.args = args or {}
obj.currentTitle = currentTitle or mw.title.getCurrentTitle()
 
-- Set isSmall
obj.isSmall = yesno(obj.args.small) or false
 
-- Define object structure.
obj._errors = {}
obj._allObjectsCache = {}
 
-- Format the config
local function substituteAliases(t, ret)
Line 939 ⟶ 908:
local actions = {}
local suffixes = self.cfg.actionParamSuffixes
for i_, t in ipairs(actionArgs) do
local objArgs = {}
for k, v in pairs(t) do
Line 1,010 ⟶ 979:
id = statusId,
currentTitle = self.currentTitle,
cfg = self.cfg,
isSmall = self.isSmall
}
local isMulti = self.cfg.statuses[statusId].isMulti
Line 1,032 ⟶ 1,000:
end
local ret = {}
for i_, t in ipairs(self.cfg[configKey] or {}) do
if t.isActive(self) then
local data = {}
Line 1,042 ⟶ 1,010:
data.cfg = self.cfg
data.currentTitle = self.currentTitle
data.isSmall = self.isSmall
ret[#ret + 1] = class.new(data)
end
Line 1,076 ⟶ 1,043:
self:getCollapsibleNoticeObjects()
}
for i_, t in ipairs(objTables) do
for j_, obj in ipairs(t) do
ret[#ret + 1] = obj
end
Line 1,116 ⟶ 1,083:
ret[#ret + 1] = msg
end
for i_, obj in ipairs(self:getAllObjects(true)) do
for j_, msg in ipairs(obj:getWarnings()) do
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,127 ⟶ 1,103:
local ret = {}
 
if self:categoriesAreActive() then
-- Child object categories
-- Child object categories
for i, obj in ipairs(self:getAllObjects()) do
for _, obj in ipairs(self:getAllObjects()) do
local categories = self:try(obj.getCategories, obj, self)
local categories = self:try(obj.getCategories, obj, self)
for j, categoryObj in ipairs(categories or {}) do
for _, categoryObj in ipairs(categories or {}) do
ret[#ret + 1] = tostring(categoryObj)
ret[#ret + 1] = tostring(categoryObj)
end
end
end
 
-- Extra categories
for i_, func in ipairs(self.cfg.extraCategories or {}) do
local cats = func(self) or {}
for i_, categoryObj in ipairs(cats) do
ret[#ret + 1] = tostring(categoryObj)
end
end
end
Line 1,151 ⟶ 1,129:
-- Table root
local tableRoot = root:tag('table')
tableRoot:addClass('article-history tmbox tmbox-notice')
 
if self.isSmall then
tableRoot:addClass('mbox-small')
else
tableRoot:css('width', '80%')
end
-- Status
local statusObj = self:getStatusObj()
Line 1,189 ⟶ 1,162:
)
end
local noCollapsibleRowsnActionRows = #actionHtmlObjects + #collapsibleNoticeHtmlObjects
local nCollapsibleRows = nActionRows + #collapsibleNoticeHtmlObjects
 
-- Find out if we are collapsed or not.
local isCollapsed = yesno(self.args.collapse)
if self.cfg.uncollapsedRowsisCollapsed == 'all'nil then
if self.cfg.uncollapsedRows == 'all' then
isCollapsed = false
isCollapsed = false
elseif noCollapsibleRows == 1 then
elseif nCollapsibleRows == 1 then
isCollapsed = false
isCollapsed = false
else
else
isCollapsed = noCollapsibleRows > (tonumber(self.cfg.uncollapsedRows) or 3)
isCollapsed = nCollapsibleRows > (tonumber(self.cfg.uncollapsedRows) or 3)
end
end
 
Line 1,216 ⟶ 1,192:
-- notices are only included in the table if it is collapsed. Action rows
-- are always included.
local collapsibleTable
if isCollapsed or #actionHtmlObjects > 0 then
if isCollapsed or nActionRows > 0 then
-- Collapsible table base
local collapsibleTable = tableRoot
:tag('tr')
:tag('td')
Line 1,224 ⟶ 1,201:
:css('width', '100%')
:tag('table')
:addClass('AHarticle-history-milestones')
:addClass(isCollapsed and 'mw-collapsible mw-collapsed' or nil)
:css('width', '100%')
:css('background', 'transparent')
:css('font-size', '90%')
 
-- Header row
if noCollapsibleRows > 1 then
local ctHeader = collapsibleTable
-- Header row
:tag('tr')
local ctHeader = collapsibleTable
:tag('trth')
:tagattr('thcolspan', 3)
:attrcss('colspanfont-size', 3'110%')
:css('font-size', '110%')
 
-- Notice bar
if isCollapsed then
local noticeBarIcons = self:getNoticeBarIcons()
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
ctHeader:wikitext(' ')
end
end
 
-- Header text
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
if #actionHtmlObjectsnActionRows > 0 then
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'))
end
end
 
Line 1,280 ⟶ 1,254:
collapsibleTable:node(htmlObj)
end
end
 
-- Collapsible notices
-- Collapsible notices and current status
-- These are only included in the table if it is collapsed. Otherwise,
-- theyThese are addedonly afterwards,included soin thatthe theycollapsible cantable alignif withit theis statuscollapsed.
-- Otherwise, they are added afterwards, so that they align with the
-- and notices.
-- notices.
do
local tableNode, statusColspan
if isCollapsed then
tableNode = collapsibleTable
for _, obj in ipairs(collapsibleNotices) do
statusColspan = 3
collapsibleTable:node(self:try(obj.exportHtml, obj, self, true))
endelse
tableNode = tableRoot
statusColspan = 2
end
 
-- CurrentCollapsible status.notices
for _, obj in ipairs(collapsibleNotices) do
if isCollapsed and noCollapsibleRows > 1 then
tableNode:node(self:try(obj.exportHtml, obj, self, isCollapsed))
local statusText
end
if statusObj then
 
statusText = statusObj.name
-- Current status
end
if statusObj and nActionRows > 1 then
statusText = statusText or self:message('status-unknown')
tableNode
collapsibleTable
:tag('tr')
:tag('td')
:attr('colspan', 3statusColspan)
:wikitext(self:message('status-blurb', statusTextstatusObj.name))
end
end
 
-- Add the collapsible notices if we are not collapsed.
if not isCollapsed then
for _, obj in ipairs(collapsibleNotices) do
tableRoot:node(self:try(obj.exportHtml, obj, self, false))
end
end
 
-- Get the categories. We have to do this before the error row, so that
Line 1,332 ⟶ 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
Line 1,344 ⟶ 1,320:
root:wikitext(categories)
root:wikitext(errorCategory)
 
local frame = mw.getCurrentFrame()
return tostring(root)
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,364 ⟶ 1,345:
wrappers = WRAPPER_TEMPLATE
})
if frame:getTitle():find('sandbox', 1, true) then
CONFIG_PAGE = CONFIG_PAGE .. '/sandbox'
end
return p._main(args)
end