Module:Article history: Difference between revisions

Content deleted Content added
add status object initialisation code
move the category class to Module:Article history/Category
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.
Line 28 ⟶ 27:
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
 
Line 125 ⟶ 92:
end
 
function Row:addCategory(category, sortKeycategoryObj)
local categoryObj = Category.new(category, sortKey)
table.insert(self.categories, categoryObj)
end
Line 179 ⟶ 145:
-- Add categories
for i, categorycategoryObj in ipairs(statusCfg.categories or {}) do
self:addCategory(categorycategoryObj)
end