-- This module powers {{old AfD multi}}.
local p = {}
-- Constants
local lang = mw.language.getContentLanguage()
local yesno = require('Module:Yesno')
local getArgs = require('Module:Arguments').getArgs
local function ipairsBackwards(t)
-- Exactly what it sounds like
local function ripairs_it(t, i)
i = i - 1
local v = t[i]
if v == nil then return v end
return i, v
end
return ripairs_it, t, #t + 1
end
local function getDataSets(args)
-- Given a table of arguments with names like ("date1", "xyz1",
-- "something2", "more2"), returns a table of subtables, in the format
-- { [1] = {date = 'text', xyz = 'text' ...}, [2] = {something = 'text', ...} }
local nums = {}
for k, v in pairs(args) do
local key, num = tostring(k):match('^([^0-9]+)([0-9]*)$')
if key then -- Key must be provided, positional parameters are stupid
num = tonumber(num)
if not num then num = 1 end -- Assume 1 for params without number, e.g. "date" == "date1"
if not nums[num] then nums[num] = {} end
nums[num][key] = v
end
end
return nums
end
local function generateRow(number, data, numbered, collapse)
-- Returns the text for one row
local result = data.result or "'''Keep'''"
local page = data.page or data.votepage
-- Use some defaults for the first debate
if number == 1 then
if not data.date then data.date = 'in the past' end
if not page and not data.link then page = tostring(mw.title.getCurrentTitle()) end
end
-- Assemble the link to the discussion
local pagelink = ''
if page then
pagelink = ', see [[Wikipedia:Articles for deletion/' .. page .. '|' .. (data.caption or 'discussion') .. ']]'
elseif data.link then
pagelink = ', see [' .. data.link .. ' ' .. (data.caption or 'discussion') .. ']'
end
local output = '\n*' ..
(numbered and (number .. '. ') or ' ') .. -- Prepend the number of the nomination
(data.result or "'''Keep''', ") .. -- Result of the debat
', ' .. data.date .. -- Date debate was closed
pagelink .. '.' -- Link to the debate
-- If collapse is true, all debates from before this one will be collapsed
if collapse then output = output .. '</td></tr></table><table class="collapsible collapsed" style="width:100%; background-color: #f8eaba;"><th>Older deletion discussions:</th><tr><td>' end
return output
end
function p.main(frame)
local args = getArgs(frame)
-- Get a table, with subtables for each entry
local nomData = getDataSets(args)
-- Set to the date iif there has only been one nomination
local nomDateSingle = (#nomData == 1 and nomData[1]) and nomData[1].date or nil
-- Parse some variables
local numbered = yesno(args.numbered)
local collapse = tonumber(args.collapse) or yesno(args.collapse)
-- Create the intro text
text = 'This ' ..
(args.type or 'page') ..
' was ' .. (nomDateSingle and '' or 'previously ') .. 'nominated for [[Wikipedia:Deletion policy|deletion]]' ..
(nomDateSingle and (' on ' .. nomDateSingle) or '') .. '. '
-- If more than one nomination
if #nomData > 1 then
if args.small then
-- Condense for small version
text = text .. 'Review prior discussions if considering re-nomination:' -- ' .. (#nomData > 2 and 's' or '') .. '
else
text = text .. 'Please review the prior discussions if you are considering re-nomination:'
end
end
-- If there are 1 or 0 sets of data provided, nothing crazy.
if #nomData < 2 then
local data = nomData[1] or {} -- In case nothing is provided at all
local page = data.page or data.votepage or tostring(mw.title.getCurrentTitle())
-- Attempt to set the link to the discusssion
local pagelink
if page then
local discusspage = mw.title.new('Wikipedia:Articles for deletion/' .. page)
if discusspage.exists then
pagelink = '[[Wikipedia:Articles for deletion/' .. page .. '|' .. (data.caption or 'the discussion') .. ']]'
end
elseif data.link then
pagelink = '[' + data.link .. (data.caption or 'the discussion') .. ']'
end
-- If no pagelink use placeholder
if not pagelink then
pagelink = (data.caption or 'the discussion')
end
text = text .. 'The result of ' .. pagelink .. ' was ' .. (data.result or "'''keep'''") .. '.</td></tr></table>'
else
-- Collapse everything if necessary
if collapse == true then
text = text .. '<table class="collapsible collapsed" style="width:100%; background-color: #f8eaba;"><th>Deletion discussions:</th><tr><td>'
else
text = text .. '<table style="width:100%; background-color: #f8eaba;"><tr><td>'
end
for i, v in ipairsBackwards(nomData) do
text = text .. generateRow(i, v, numbered, collapse == i - 1)
end
text = text .. '</td></tr></table>'
end
local finalArgs = {
small = args.small,
type = 'notice',
image = '[[Image:Clipboard.svg|35px|Articles for deletion]]',
smallimage = 'none',
text = text
}
return frame:expandTemplate{title = 'tmbox', args = finalArgs}
end
return p