Modulo:Nombro da

Dokumentado Dokumentado



Se vi havas demandon pri ĉi tiu Lua-modulo, tiam vi povas demandi en la diskutejo pri Lua-moduloj. La Intervikiaj ligiloj estu metataj al Vikidatumoj. (Vidu Helpopaĝon pri tio.)
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('Modulo:Nombro da/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('Modulo:Nombro da/dateno')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('Modulo:Nombro da/' .. (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,}