Module:NUMBEROFGROUP
Implements {{NUMBEROFGROUP}}
local p = {}
local contentLanguage = mw.language.new(mw.getCurrentFrame():preprocess('{{PAGELANGUAGE}}'))
local function trimArg(arg, i)
arg = mw.text.trim(arg or '')
if arg == '' then
if i then
error('Parameter ' .. i .. ' is missing. See template documentation')
end
return nil
end
return arg
end
function p.main(frame)
local args = frame:getParent().args
local action = mw.ustring.lower(trimArg(args[1], 1)) -- activeusers, admins, articles, edits, files, pages, users, depth, active, closed, languages
local site = trimArg(args[2], 2)
local dataData = mw.loadData('Module:NUMBEROFGROUP/data')
local result = dataData.data[site]
if result then
result = result[dataData.map[action]]
end
local wantComma = trimArg(args[3]) -- nil for no commas in output; "N" or anything nonblank inserts commas
result = result or 0
return wantComma and contentLanguage:formatNum(result) or result -- number or formatted string
end
return p