Module:Article history: Difference between revisions

Content deleted Content added
more bug fixes for the config formatting function - we can't add values to the same table at the same time we are iterating over it, so build a new config table instead
some minor rearrangements
Line 20:
and num > 0
and num < math.huge
end
 
local function substituteParams(msg, ...)
return mw.message.newRawMessage(msg, ...):plain()
end
 
Line 40 ⟶ 44:
-- code, result, link, paramNum, actionCfg
local obj = setmetatable({}, Action)
 
obj.id = data.id
obj.name = data.name
obj.oldid = data.oldid
obj.paramNum = data.paramNum
 
return obj
end
Line 138 ⟶ 148:
obj.cfg = substituteAliases(cfg or require(CONFIG_PAGE))
-- Create theInitialize action objects.
 
do
return obj
-- Filter the arguments for actions.
end
local actionParams = {}
 
local pattern = '^' .. selfobj.cfg.actionParamPrefix .. '([1-9][0-9]*)(.-)$'
function ArticleHistory:initializeActionObjects()
local suffixes = selfobj.cfg.actionParamSuffixes
-- Filter the arguments for actions.
for k, v in pairs(obj.args) do
local actionParams = {}
if type(k) == 'string' then
local pattern = '^' .. self.cfg.actionParamPrefix .. '([1-9][0-9]*)(.-)$'
local num, suffix = key:match(pattern)
local suffixes = self.cfg.actionParamSuffixes
t[if num and suffix and suffixes[suffix]] = vthen
for k, v in pairs(args) do
t. num = tonumber(num)
if type(k) == 'string' then
local num, suffixt = key:match(pattern)actionParams[num] or {}
if num and suffix and t[suffixes[suffix]] = thenv
t.num = tonumber(num)
local t = actionParams[num] or= {}t
end
t[suffixes[suffix]] = v
t.num = num
actionParams[num] = t
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
table.insert(selfobj.actions, Action.new(t))
end
end
 
return obj
-- 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
table.insert(self.actions, Action.new(t))
end
end