Content deleted Content added
replace p.numberof for Template:NUMBEROF with new code that loads data once per page from Module:NUMBEROF/data, see Template talk:NUMBEROF#Overhead |
use magic variables if want local site; if want commas, use local digits and formatting |
||
Line 1:
local p = {}
local function commaValue(amount)▼
if k == 0 then▼
end▼
end▼
end▼
local function trimArg(arg, i)
Line 23 ⟶ 10:
end
return mw.ustring.lower(arg)
▲end
-- If wanted site is the local site where module is running,
-- return numberof result for given action, or nil.
-- This is faster than reading the cached table, and gives the current value.
local localSite = string.match(mw.site.server, '.*//(.*)%.org$') -- examples: 'en.wikipedia', 'commons.wikimedia'
if site == localSite then
if action == 'activeusers' then
action = 'activeUsers'
▲ end
return mw.site.stats[action]
▲ end
end
function p.numberof(frame)
local args = frame:getParent().args
local action = trimArg(args[1], 1) --
local site = trimArg(args[2], 2) -- "en" or "en.wikipedia" or "en.wikiquote" etc.
if not site:find('.', 1, true) then
site = site .. '.wikipedia'
end
local data = mw.loadData('Module:NUMBEROF/data')▼
local map = data.map▼
data = data.data▼
local wantComma = trimArg(args[3]) -- nil for no commas in output; "N" or anything nonblank inserts commas
local result =
if not result then
result = result[map[action]]▼
result = data[site]
▲ result = result[map[action]]
end
end
if result then
▲ result = tostring(result)
if wantComma then
result =
end
return result -- number or formatted string
end
return '-1'
|