Content deleted Content added
more structure rearranging |
add code to initialise action objects |
||
Line 7:
-- other information such as the date it was featured on the main page.
-------------------------------------------------------------------------------
local CONFIG_PAGE = 'Module:Article history/config'
-------------------------------------------------------------------------------
Line 34 ⟶ 36:
-- * paramNum
function Action.new(data)
-- Valid data table keys:
-- code, result, link, paramNum, rowCfg, title
local obj = setmetatable({}, Action)
return obj
Line 91 ⟶ 95:
ArticleHistory.__index = ArticleHistory
function ArticleHistory.new(args, cfg, title)
local obj = setmetatable({}, ArticleHistory)
-- Set input
obj.args = args or {}
obj.cfg = cfg or require(CONFIG_PAGE)
obj.title = title or mw.title.getCurrentTitle()
-- Define object structure
obj.actions = {}
obj.categories = {}
-- Initialise the action objects
do
-- Filter the arguments for actions.
local actionParams = {}
local suffixes = {
[''] = 'id',
date = 'date',
link = 'link',
result = 'result',
oldid = 'oldid'
}
for k, v in pairs(args) do
if type(k) == 'string' then
local num, suffix = key:match('^action([1-9][0-9]*)(.-)$')
if num and suffix and suffixes[suffix] then
num = tonumber(num)
local t = actionParams[num] or {}
t[suffixes[suffix]] = v
t.num = num
actionParams[num] = t
end
end
end
-- Sort the action parameters.
local actionParamsSorted = {}
for num, t in pairs(actionParams) do
table.insert(actionParamsSorted, t)
end
table.sort(actionParamsSorted, function (t1, t2)
return t1.num < t2.num
end)
-- Create the action objects.
for _, t in ipairs(actionParamsSorted) do
t.title = obj.title
t.cfg = obj.cfg
table.insert(obj.actions, Action.new(t))
end
end
return obj
|