Module:NUMBEROF: Difference between revisions

Content deleted Content added
per convention, use function "main" since only one entry point; error return changed to the number -1 rather than string "-1" so in principle a module could get the data more easily
style tweaks
Line 1:
-- Implement {{NUMBEROF}} by extracting statistics from
local p = {}
-- https://commons.wikimedia.org/wiki/Data:Wikipedia_statistics/data.tab
 
local function trimArg(arg, i)
Line 50 ⟶ 51:
end
 
local function p.main(frame)
local args = frame:getParent().args
local action = trimArg(args[1], 1) -- activeusers, admins, articles, edits, files, pages, users, depth
if action:sub(1, 8) == 'numberof' then -- numberofX is an alias for X
action = trimArg(action:sub(9), 1)
end
local site = trimArg(args[2], 2) -- "en" or "en.wikipedia" or "en.wikiquote" etc., including "total"
if not site:find('.', 1, true) then
site = site .. '.wikipedia'
Line 85 ⟶ 86:
end
 
return p{ main = main }