Module:NUMBEROF
Appearance
| This Lua module is used in MediaWiki:Statistics-files-desc. Changes to it can cause immediate changes to the Wikipedia user interface. To avoid major disruption, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on the talk page before implementing them. |
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| This module is currently protected from editing. See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected. |
| This module depends on the following other modules: |
- Module:NUMBEROF implements templates {{NUMBEROF}} and {{Wikipedia rank by size}}.
- It includes sub-modules Module:NUMBEROF/data, Module:NUMBEROF/rank, Module:NUMBEROF/other and Module:NUMBEROF/meta which are used once per page [not per template invocation]. These sub-modules pull data from Wikimedia Commons:
- c:Data:Wikipedia statistics/meta.tab for classification of wikis,
- c:Data:Wikipedia statistics/data.tab for statistics of all wikis,
- c:Data:Wikipedia statistics/rank/*.tab for rankings of languages in each project.
- data.tab, meta.tag and rank/*.tab are updated by a bot multiple times each day.
- The module was originally developed on Enwiki.
local p = {}
local function trimArg(arg, i)
arg = mw.text.trim(arg or '')
if arg == '' then
if i then
error('Parameter ' .. i .. ' is missing. See [[Template:NUMBEROF]] documentation')
end
return nil
end
return mw.ustring.lower(arg)
end
local function getIfLocal(site, action)
-- 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) -- activeusers, admins, articles, edits, files, pages, users
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 wantComma = trimArg(args[3]) -- nil for no commas in output; "N" or anything nonblank inserts commas
local result = getIfLocal(site, action)
if not result then
local data = mw.loadData('Module:NUMBEROF/data')
local map = data.map
data = data.data
result = data[site]
if result then
result = result[map[action]]
end
end
if result then
if wantComma then
result = mw.getContentLanguage():formatNum(result)
end
return result -- number or formatted string
end
return '-1'
end
return p