Module:Article history: Difference between revisions

Content deleted Content added
use ArticleHistory:getStatusId to get the current status ID, and rename the old method ArticleHistory:getStatusIdForCode
add a Category class to standardise category processing
Line 10:
local CONFIG_PAGE = 'Module:Article history/config'
local WRAPPER_TEMPLATE = 'Template:Article history'
local CATEGORY_NS_TEXT = mw.site.namespaces[14].name
 
-- Load required modules.
local checkType = require('libraryUtil').checkType
 
-------------------------------------------------------------------------------
Line 24 ⟶ 28:
local function substituteParams(msg, ...)
return mw.message.newRawMessage(msg, ...):plain()
end
 
-------------------------------------------------------------------------------
-- Category
-- Category objects make category wikilinks.
-------------------------------------------------------------------------------
 
local Category = {}
Category.__index = Category
 
function Category.new(category, sortKey)
local obj = setmetatable({}, Category)
obj.category = category
obj.sortKey = sortKey
return obj
end
 
function Category:__tostring()
if self.sortKey then
return string.format(
'[[%s:%s|%s]]',
CATEGORY_NS_TEXT,
self.category,
self.sortKey
)
else
return string.format(
'[[%s:%s]]',
CATEGORY_NS_TEXT,
self.category
)
end
end
 
-------------------------------------------------------------------------------
-- Header
-- Header objects are displayed at the top of the template, above the
-- collapsed section. They usually have an image and a blurb.
-------------------------------------------------------------------------------
 
local Header = {}
Header.__index = Header
 
function Header.new(data)
local obj = setmetatable({}, Header)
return obj
end
 
function Header:exportHtml()
end
 
function Header:exportCategories()
end
 
-------------------------------------------------------------------------------
-- Status class
-- Status objects deal with possible current statuses of the article.
-------------------------------------------------------------------------------
 
local Status = setmetatable({}, Header)
Status.__index = Status
 
function Status.new(data)
local obj = Header.new(data)
setmetatable(obj, Status)
return obj
end
 
-------------------------------------------------------------------------------
-- DoubleStatus class
-- For when an article can have two distinct statuses, e.g. former featured
-- article status and good article status.
-------------------------------------------------------------------------------
 
local DoubleStatus = setmetatable({}, Header)
DoubleStatus.__index = DoubleStatus
 
function DoubleStatus.new(data)
local obj = Header.new(data)
setmetatable(obj, DoubleStatus)
return obj
end
 
-------------------------------------------------------------------------------
-- Notice class
-- Notice objects contain notices about an article that aren't part of its
-- current status, e.g. the date an article was featured on the main page.
-------------------------------------------------------------------------------
 
local Notice = setmetatable({}, Header)
Notice.__index = Notice
 
function Notice.new(data)
local obj = Header.new(data)
setmetatable(obj, Notice)
return obj
end
 
Line 86 ⟶ 186:
end
 
function Action:getCategoryexportHtml()
end
 
function Action:exportCategories()
-------------------------------------------------------------------------------
end
-- Header
-- Header objects are displayed at the top of the template, above the
-- collapsed section. They usually have an image and a blurb.
-------------------------------------------------------------------------------
 
local Header = {}
Header.__index = Header
 
-------------------------------------------------------------------------------
-- StatusCollapsibleNotice class
-- This class makes notices that go in the collapsible part of the template,
-- Status objects deal with possible current statuses of the article.
-- underneath the list of actions.
-------------------------------------------------------------------------------
 
local StatusCollapsibleNotice = {}
StatusCollapsibleNotice.__index = StatusCollapsibleNotice
 
-------------------------------------------------------------------------------
-- DoubleStatus class
-- For when an article can have two distinct statuses, e.g. former featured
-- article status and good article status.
-------------------------------------------------------------------------------
 
local DoubleStatus = {}
DoubleStatus.__index = DoubleStatus
 
-------------------------------------------------------------------------------
-- Notice class
-- Notice objects contain notices about an article that aren't time-dependent
-- and aren't part of its current status, e.g. the topic area of a good
-- article, or the date the article was featured on DYK.
-------------------------------------------------------------------------------
 
local Notice = {}
Notice.__index = Notice
 
-------------------------------------------------------------------------------
Line 142 ⟶ 218:
-- Define object structure
obj.actions = {}
obj.notices = {}
obj.collapsibleNotices = {}
-- Format the config
Line 246 ⟶ 324:
local statusObj = self:getStatusObj()
return statusObj and statusObj.id
end
 
function ArticleHistory:initializeNoticeObjects()
end
 
function ArticleHistory:initializeCollapsibleNoticeObjects()
end
 
Line 253 ⟶ 337:
function ArticleHistory:renderCategories()
local ret = {}
for i, actionObj in ipairs(self.actions) do
local categoryNsText = mw.site.namespaces[14].name
for j, categoryObj in ipairs(actionObj:exportCategories()) do
 
ret[#ret + 1] = tostring(categoryObj)
local function makeCategory(cat, sortKey)
if sortKey then
return string.format('[[%s:%s|%s]]', categoryNsText, cat, sortKey)
else
return string.format('[[%s:%s]]', categoryNsText, cat)
end
end
 
for _, actionObj in ipairs(self.actions) do
ret[#ret + 1] = makeCategory(actionObj:getCategory())
end
 
return table.concat(ret)
end