https://de.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3ANUMBEROF Modul:NUMBEROF - Versionsgeschichte 2025-11-10T11:06:39Z Versionsgeschichte dieser Seite in Wikipedia MediaWiki 1.46.0-wmf.1 https://de.wikipedia.org/w/index.php?title=Modul:NUMBEROF&diff=260335875&oldid=prev Kenneth 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 = &#039;www.wikidata&#039;,<br /> meta = &#039;meta.wikimedia&#039;,<br /> commons = &#039;commons.wikimedia&#039;,<br /> foundation = &#039;foundation.wikimedia&#039;,<br /> wikimania = &#039;wikimania.wikimedia&#039;,<br /> wikitech = &#039;wikitech.wikimedia&#039;,<br /> }<br /> <br /> local function trimArg(arg, i)<br /> arg = mw.text.trim(arg or &#039;&#039;)<br /> if arg == &#039;&#039; then<br /> if i then<br /> error(&#039;Parameter &#039; .. i .. &#039; is missing. See template documentation&#039;)<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 == &#039;depth&#039; 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 = { &#039;articles&#039;, &#039;edits&#039;, &#039;pages&#039; }<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, &#039;.*//(.*)%.org$&#039;) -- examples: &#039;af.wikipedia&#039;, &#039;commons.wikimedia&#039;<br /> if site == localSite then<br /> if action == &#039;activeusers&#039; then<br /> action = &#039;activeUsers&#039;<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) == &#039;numberof&#039; 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(&#039;.&#039;, 1, true) then<br /> -- site is like &quot;af&quot; or &quot;af.wikipedia&quot; or &quot;af.wikiquote&quot; etc., including &quot;total&quot;<br /> site = site .. &#039;.wikipedia&#039;<br /> end<br /> local wantComma = trimArg(args[3]) -- nil for no commas in output; &quot;N&quot; or anything nonblank inserts commas<br /> local result<br /> if wantMeta then<br /> local data = mw.loadData(&#039;Module:NUMBEROF/meta&#039;)<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 == &#039;active&#039; then<br /> result = nrActive<br /> elseif action == &#039;closed&#039; then<br /> result = nrClosed<br /> elseif action == &#039;languages&#039; 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(&#039;Module:NUMBEROF/data&#039;)<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 &quot;af&quot; (not &quot;af.wikipedia&quot;)<br /> local base = trimArg(args[2]) or &#039;wikipedia&#039; -- base of full site name like &quot;wikipedia&quot; or &quot;wikiquote&quot;<br /> local wantComma = trimArg(args[3])<br /> local data = mw.loadData(&#039;Module:NUMBEROF/&#039; .. (base == &#039;wikipedia&#039; and &#039;rank&#039; or &#039;other&#039;))<br /> data = data[base]<br /> if data then<br /> local result<br /> parm = tonumber(parm) or parm<br /> if type(parm) == &#039;number&#039; 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