Module:Article history: Difference between revisions

Content deleted Content added
move the action parameter values to the config
split action object creation into its own method
Line 9:
 
local CONFIG_PAGE = 'Module:Article history/config'
local WRAPPER_TEMPLATE = 'Template:Article history'
 
-------------------------------------------------------------------------------
Line 53 ⟶ 54:
 
-------------------------------------------------------------------------------
-- ImageRowHeader
-- ImageRowHeader objects representare adisplayed rowat withthe itstop ownof imagethe andtemplate, blurb.above the
-- collapsed section. They usually have an image and a blurb.
-------------------------------------------------------------------------------
 
local ImageRowHeader = {}
ImageRowHeader.__index = ImageRowHeader
 
-------------------------------------------------------------------------------
Line 107 ⟶ 109:
obj.categories = {}
 
return obj
-- Initialise the action objects
end
do
 
-- Filter the arguments for actions.
function ArticleHistory:initializeActionObjects()
local actionParams = {}
-- Filter the arguments for actions.
local pattern = '^' .. obj.cfg.actionParamPrefix .. '([1-9][0-9]*)(.-)$'
local actionParams = {}
local suffixes = obj.cfg.actionParamSuffixes
local pattern = '^' .. objself.cfg.actionParamPrefix .. '([1-9][0-9]*)(.-)$'
for k, v in pairs(args) do
local suffixes = objself.cfg.actionParamSuffixes
if type(k) == 'string' then
for k, v in pairs(args) do
local num, suffix = key:match(pattern)
if numtype(k) and== suffix and suffixes[suffix]'string' then
local num, suffix = tonumberkey:match(numpattern)
t[if num and suffix and suffixes[suffix]] = vthen
local t = actionParams[num] or {}
num = tonumber(num)
t[suffixes[suffix]] = v
local t.num = actionParams[num] or {}
actionParamst[numsuffixes[suffix]] = tv
endt.num = num
local t = actionParams[num] or= {}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
t.title = obj.title
t.cfg = obj.cfg
table.insert(obj.actions, Action.new(t))
end
end
 
-- Sort the action parameters.
return obj
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)
-- InitialiseCreate the action objects.
for _, t in ipairs(actionParamsSorted) do
t.articleHistoryObj = self
table.insert(objself.actions, Action.new(t))
end
end
 
Line 191:
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:Article history'WRAPPER_TEMPLATE
})
return p._main(args)