Модул:NUMBEROF
![]() | 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 aliases = {wikidata = 'www.wikidata',meta = 'meta.wikimedia',commons = 'commons.wikimedia',foundation = 'foundation.wikimedia',wikimania = 'wikimania.wikimedia',wikitech = 'wikitech.wikimedia',}local function trimArg(arg, i)arg = mw.text.trim(arg or '')if arg == '' thenif i thenerror('Parameter ' .. i .. ' is missing. See template documentation')endreturn nilendreturn mw.ustring.lower(arg)endlocal function getValue(stats, action, map)if action == 'depth' then-- https://meta.wikimedia.org/wiki/Wikipedia_article_depth-- This gives silly results if, for example, the number of articles is small.local n = { 'articles', 'edits', 'pages' }if map thenfor i, v in ipairs(n) don[i] = map[v]endendfor i, v in ipairs(n) don[i] = stats[v] or 0endlocal articles, edits, pages = n[1], n[2], n[3]if pages == 0 or articles == 0 thenreturn 0endreturn math.floor((edits/pages) * ((pages - articles)/articles)^2)endif map thenaction = map[action]endreturn stats[action]endlocal 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: 'af.wikipedia', 'commons.wikimedia'if site == localSite thenif action == 'activeusers' thenaction = 'activeUsers'endreturn getValue(mw.site.stats, action)endendlocal function main(frame)local metaWords = { active = true, closed = true, languages = true, }local args = frame:getParent().argslocal action = trimArg(args[1], 1) -- activeusers, admins, articles, edits, files, pages, users, depth, active, closed, languagesif action:sub(1, 8) == 'numberof' then -- numberofX is an alias for Xaction = trimArg(action:sub(9), 1)endlocal wantMeta = metaWords[action]local site = trimArg(args[2], 2)site = aliases[site] or siteif not wantMeta and not site:find('.', 1, true) then-- site is like "af" or "af.wikipedia" or "af.wikiquote" etc., including "total"site = site .. '.wikipedia'endlocal wantComma = trimArg(args[3]) -- nil for no commas in output; "N" or anything nonblank inserts commaslocal resultif wantMeta thenlocal data = mw.loadData('Module:NUMBEROF/meta')local nrActive = data.nrActive[site]local nrClosed = data.nrClosed[site]if nrActive or nrClosed then-- If either is set, site is valid but there may not be an entry for both active and closed.nrActive = nrActive or 0nrClosed = nrClosed or 0if action == 'active' thenresult = nrActiveelseif action == 'closed' thenresult = nrClosedelseif action == 'languages' thenresult = nrActive + nrClosedendendelseresult = getIfLocal(site, action)if not result thenlocal data = mw.loadData('Module:NUMBEROF/data')local map = data.mapdata = data.dataresult = data[site]if result thenresult = getValue(result, action, map)endendendif result thenif wantComma thenresult = mw.language.getContentLanguage():formatNum(result)endreturn result -- number or formatted stringendreturn -1endlocal function rank(frame)-- Rank sites in a specified sister project by their number of articles.local args = frame:getParent().argslocal parm = trimArg(args[1], 1) -- a number like 12 or a site name like "af" (not "af.wikipedia")local base = trimArg(args[2]) or 'wikipedia' -- base of full site name like "wikipedia" or "wikiquote"local wantComma = trimArg(args[3])local data = mw.loadData('Module:NUMBEROF/' .. (base == 'wikipedia' and 'rank' or 'other'))data = data[base]if data thenlocal resultparm = tonumber(parm) or parmif type(parm) == 'number' thenresult = data.rankByIndex[parm]elseresult = data.rankBySite[parm]if result and wantComma thenresult = mw.getContentLanguage():formatNum(result)endendif result thenreturn result -- number or stringendendreturn -1endreturn {main = main,rank = rank,}
🔥 Top keywords: Начална страницаЕвропейско първенство по футбол 2024Рамадан АталайСпециални:ТърсенеСписък на страните по телефонен кодДаниил БългарскиДелян ПеевскиКалоян МетодиевЧихуахуа (куче)Сиви вълциЛятно часово времеАхмед ДоганРосен ЖелязковНиколай МарковБългарияРадио Свободна ЕвропаДжесика ЛангРегистрационен номер на МПС (България)Ивелин МихайловРая НазарянЦветелина ЯневаБодичекЕвропейско първенство по футболДвижение за права и свободиПарламентарни избори в България (2024)Кристиано РоналдоДейвид КопърфийлдМера според мера (1981)Спасителят в ръжтаИскра МихайловаЙордан ЦоневНародно събрание3 юлиРосица КироваДжевдет ЧакъровУран (планета)Румбата, аз и РоналдоЯвор БожанковДжулай