Module:User:Wonderfool/alternative accounts
Appearance
(Redirected from Module:User:Erutuon/Wonderfool)
- This module sandbox lacks a documentation subpage. Please create it.
- Useful links: root page • root page’s subpages • links • transclusions • testcases • sandbox
local export = {}
local concat = table.concat
local insert = table.insert
local is_positive_integer = require("Module:math").is_positive_integer
local make_user_linkbar = require("Module:linkbar").make_user_linkbar
local os_date = os.date
local os_time = os.time
local tonumber = tonumber
local tostring = tostring
local trim = require("Module:string utilities").trim
local function is_empty(str)
return str == nil or str:find "^%s*$" ~= nil
end
-- From [[Module:number list]].
local function add_separator(number, separator, group, start)
number = tostring(number)
start = start or group
if start >= #number then
return number
end
local parts = {number:sub(-start)}
for i = start + 1, #number, group do
insert(parts, 1, number:sub(-(i + group - 1), -i))
end
return concat(parts, separator)
end
local function add_thousands_separator(number)
return add_separator(tostring(number), ",", 3)
end
function export.show(frame)
local output = require("Module:array")()
output:insert [[
{| class="wikitable sortable"
! Name
! First edit
! Blocked
! style="text-align:right" | # of edits
]]
local args = require("Module:table").shallowCopy(frame.args)
if not require("Module:table").isArray(args) then
error("Sequential numbered parameters required.")
elseif #args % 6 ~= 0 then
error("Total number of arguments must be a multiple of 6.")
end
local total_edits = 0
for i = 1, #args, 6 do
local start_date_arg, block_date_arg, edits_arg = i + 2, i + 3, i + 5
local username, username_comment, start_date, block_date, date_comment, edits = unpack(args, i)
local start_date_sortkey = ""
local start_date_spelled_out = "—"
local block_date_sortkey = "9999-12-31"
local block_date_spelled_out = "no"
if not is_empty(start_date) then
local year, month, day = start_date:match("(%d%d%d%d)[/-](%d%d)[/-](%d%d)")
local time = os_time{year = year, month = month, day = day}
start_date_sortkey = os_date("%F", time)
start_date_spelled_out = os_date("%B %e, %Y", time)
end
if not is_empty(block_date) then
local year, month, day = block_date:match("(%d%d%d%d)[/-](%d%d)[/-](%d%d)")
local time = os_time{year = year, month = month, day = day}
block_date_sortkey = os_date("%F", time)
block_date_spelled_out = os_date("%B %e, %Y", time)
end
if not is_empty(edits) then
edits = tonumber(edits)
if not is_positive_integer(edits, "include 0") then
error("Argument " .. edits_arg .. " (" .. edits .. ") should be a positive integer or zero")
end
total_edits = total_edits + edits
edits = tostring(edits)
end
output:insert(([[
|-
| %s%s
| data-sort-value="%s" | %s
| data-sort-value="%s" | %s%s
| %s
]]):format(
make_user_linkbar{args = {
user = username,
"talk", "contribs"
}},
not is_empty(username_comment) and " (" .. trim(username_comment) .. ")" or "",
start_date_sortkey,
start_date_spelled_out,
block_date_sortkey,
block_date_spelled_out,
not is_empty(date_comment) and " (" .. trim(date_comment) .. ")" or "",
add_thousands_separator(edits)))
end
output:insert(([[
|- class="sortbottom"
| Total
| —
| —
| %s
]]):format(add_thousands_separator(total_edits)))
output:insert "|}"
return output:concat()
end
return export