https://de.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3ANUMBEROFModul:NUMBEROF - Versionsgeschichte2025-11-10T11:06:39ZVersionsgeschichte dieser Seite in WikipediaMediaWiki 1.46.0-wmf.1https://de.wikipedia.org/w/index.php?title=Modul:NUMBEROF&diff=260335875&oldid=prevKenneth Wehr: Test (Kopie von dawp)2025-10-05T15:38:26Z<p>Test (Kopie von dawp)</p>
<p><b>Neue Seite</b></p><div>local aliases = {<br />
wikidata = 'www.wikidata',<br />
meta = 'meta.wikimedia',<br />
commons = 'commons.wikimedia',<br />
foundation = 'foundation.wikimedia',<br />
wikimania = 'wikimania.wikimedia',<br />
wikitech = 'wikitech.wikimedia',<br />
}<br />
<br />
local function trimArg(arg, i)<br />
arg = mw.text.trim(arg or '')<br />
if arg == '' then<br />
if i then<br />
error('Parameter ' .. i .. ' is missing. See template documentation')<br />
end<br />
return nil<br />
end<br />
return mw.ustring.lower(arg)<br />
end<br />
<br />
local function getValue(stats, action, map)<br />
if action == 'depth' then<br />
-- https://meta.wikimedia.org/wiki/Wikipedia_article_depth<br />
-- This gives silly results if, for example, the number of articles is small.<br />
local n = { 'articles', 'edits', 'pages' }<br />
if map then<br />
for i, v in ipairs(n) do<br />
n[i] = map[v]<br />
end<br />
end<br />
for i, v in ipairs(n) do<br />
n[i] = stats[v] or 0<br />
end<br />
local articles, edits, pages = n[1], n[2], n[3]<br />
if pages == 0 or articles == 0 then<br />
return 0<br />
end<br />
return math.floor((edits/pages) * ((pages - articles)/articles)^2)<br />
end<br />
if map then<br />
action = map[action]<br />
end<br />
return stats[action]<br />
end<br />
<br />
local function getIfLocal(site, action)<br />
-- If wanted site is the local site where module is running,<br />
-- return numberof result for given action, or nil.<br />
-- This is faster than reading the cached table, and gives the current value.<br />
local localSite = string.match(mw.site.server, '.*//(.*)%.org$') -- examples: 'af.wikipedia', 'commons.wikimedia'<br />
if site == localSite then<br />
if action == 'activeusers' then<br />
action = 'activeUsers'<br />
end<br />
return getValue(mw.site.stats, action)<br />
end<br />
end<br />
<br />
local function main(frame)<br />
local metaWords = { active = true, closed = true, languages = true, }<br />
local args = frame:getParent().args<br />
local action = trimArg(args[1], 1) -- activeusers, admins, articles, edits, files, pages, users, depth, active, closed, languages<br />
if action:sub(1, 8) == 'numberof' then -- numberofX is an alias for X<br />
action = trimArg(action:sub(9), 1)<br />
end<br />
local wantMeta = metaWords[action]<br />
local site = trimArg(args[2], 2)<br />
site = aliases[site] or site<br />
if not wantMeta and not site:find('.', 1, true) then<br />
-- site is like "af" or "af.wikipedia" or "af.wikiquote" etc., including "total"<br />
site = site .. '.wikipedia'<br />
end<br />
local wantComma = trimArg(args[3]) -- nil for no commas in output; "N" or anything nonblank inserts commas<br />
local result<br />
if wantMeta then<br />
local data = mw.loadData('Module:NUMBEROF/meta')<br />
local nrActive = data.nrActive[site]<br />
local nrClosed = data.nrClosed[site]<br />
if nrActive or nrClosed then<br />
-- If either is set, site is valid but there may not be an entry for both active and closed.<br />
nrActive = nrActive or 0<br />
nrClosed = nrClosed or 0<br />
if action == 'active' then<br />
result = nrActive<br />
elseif action == 'closed' then<br />
result = nrClosed<br />
elseif action == 'languages' then<br />
result = nrActive + nrClosed<br />
end<br />
end<br />
else<br />
result = getIfLocal(site, action)<br />
if not result then<br />
local data = mw.loadData('Module:NUMBEROF/data')<br />
local map = data.map<br />
data = data.data<br />
result = data[site]<br />
if result then<br />
result = getValue(result, action, map)<br />
end<br />
end<br />
end<br />
if result then<br />
if wantComma then<br />
result = mw.language.getContentLanguage():formatNum(result)<br />
end<br />
return result -- number or formatted string<br />
end<br />
return -1<br />
end<br />
<br />
local function rank(frame)<br />
-- Rank sites in a specified sister project by their number of articles.<br />
local args = frame:getParent().args<br />
local parm = trimArg(args[1], 1) -- a number like 12 or a site name like "af" (not "af.wikipedia")<br />
local base = trimArg(args[2]) or 'wikipedia' -- base of full site name like "wikipedia" or "wikiquote"<br />
local wantComma = trimArg(args[3])<br />
local data = mw.loadData('Module:NUMBEROF/' .. (base == 'wikipedia' and 'rank' or 'other'))<br />
data = data[base]<br />
if data then<br />
local result<br />
parm = tonumber(parm) or parm<br />
if type(parm) == 'number' then<br />
result = data.rankByIndex[parm]<br />
else<br />
result = data.rankBySite[parm]<br />
if result and wantComma then<br />
result = mw.getContentLanguage():formatNum(result)<br />
end<br />
end<br />
if result then<br />
return result -- number or string<br />
end<br />
end<br />
return -1<br />
end<br />
<br />
return {<br />
main = main,<br />
rank = rank,<br />
}</div>Kenneth Wehr