<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ANUMBEROF</id>
	<title>Module:NUMBEROF - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ANUMBEROF"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:NUMBEROF&amp;action=history"/>
	<updated>2026-04-21T13:23:01Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:NUMBEROF&amp;diff=144041&amp;oldid=prev</id>
		<title>imported&gt;Johnuniq: update from sandbox to allow aliases</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:NUMBEROF&amp;diff=144041&amp;oldid=prev"/>
		<updated>2022-02-26T04:29:51Z</updated>

		<summary type="html">&lt;p&gt;update from sandbox to allow aliases&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local aliases = {&lt;br /&gt;
	wikidata = &amp;#039;www.wikidata&amp;#039;,&lt;br /&gt;
	meta = &amp;#039;meta.wikimedia&amp;#039;,&lt;br /&gt;
	commons = &amp;#039;commons.wikimedia&amp;#039;,&lt;br /&gt;
	foundation = &amp;#039;foundation.wikimedia&amp;#039;,&lt;br /&gt;
	wikimania = &amp;#039;wikimania.wikimedia&amp;#039;,&lt;br /&gt;
	wikitech = &amp;#039;wikitech.wikimedia&amp;#039;,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local function trimArg(arg, i)&lt;br /&gt;
	arg = mw.text.trim(arg or &amp;#039;&amp;#039;)&lt;br /&gt;
	if arg == &amp;#039;&amp;#039; then&lt;br /&gt;
		if i then&lt;br /&gt;
			error(&amp;#039;Parameter &amp;#039; .. i .. &amp;#039; is missing. See template documentation&amp;#039;)&lt;br /&gt;
		end&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	return mw.ustring.lower(arg)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getValue(stats, action, map)&lt;br /&gt;
	if action == &amp;#039;depth&amp;#039; then&lt;br /&gt;
		-- https://meta.wikimedia.org/wiki/Wikipedia_article_depth&lt;br /&gt;
		-- This gives silly results if, for example, the number of articles is small.&lt;br /&gt;
		local n = { &amp;#039;articles&amp;#039;, &amp;#039;edits&amp;#039;, &amp;#039;pages&amp;#039; }&lt;br /&gt;
		if map then&lt;br /&gt;
			for i, v in ipairs(n) do&lt;br /&gt;
				n[i] = map[v]&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		for i, v in ipairs(n) do&lt;br /&gt;
			n[i] = stats[v] or 0&lt;br /&gt;
		end&lt;br /&gt;
		local articles, edits, pages = n[1], n[2], n[3]&lt;br /&gt;
		if pages == 0 or articles == 0 then&lt;br /&gt;
			return 0&lt;br /&gt;
		end&lt;br /&gt;
		return math.floor((edits/pages) * ((pages - articles)/articles)^2)&lt;br /&gt;
	end&lt;br /&gt;
	if map then&lt;br /&gt;
		action = map[action]&lt;br /&gt;
	end&lt;br /&gt;
	return stats[action]&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getIfLocal(site, action)&lt;br /&gt;
	-- If wanted site is the local site where module is running,&lt;br /&gt;
	-- return numberof result for given action, or nil.&lt;br /&gt;
	-- This is faster than reading the cached table, and gives the current value.&lt;br /&gt;
	local localSite = string.match(mw.site.server, &amp;#039;.*//(.*)%.org$&amp;#039;)  -- examples: &amp;#039;af.wikipedia&amp;#039;, &amp;#039;commons.wikimedia&amp;#039;&lt;br /&gt;
	if site == localSite then&lt;br /&gt;
		if action == &amp;#039;activeusers&amp;#039; then&lt;br /&gt;
			action = &amp;#039;activeUsers&amp;#039;&lt;br /&gt;
		end&lt;br /&gt;
		return getValue(mw.site.stats, action)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function main(frame)&lt;br /&gt;
	local metaWords = { active = true, closed = true, languages = true, }&lt;br /&gt;
	local args = frame:getParent().args&lt;br /&gt;
	local action = trimArg(args[1], 1)  -- activeusers, admins, articles, edits, files, pages, users, depth, active, closed, languages&lt;br /&gt;
	if action:sub(1, 8) == &amp;#039;numberof&amp;#039; then  -- numberofX is an alias for X&lt;br /&gt;
		action = trimArg(action:sub(9), 1)&lt;br /&gt;
	end&lt;br /&gt;
	local wantMeta = metaWords[action]&lt;br /&gt;
	local site = trimArg(args[2], 2)&lt;br /&gt;
	site = aliases[site] or site&lt;br /&gt;
	if not wantMeta and not site:find(&amp;#039;.&amp;#039;, 1, true) then&lt;br /&gt;
		-- site is like &amp;quot;af&amp;quot; or &amp;quot;af.wikipedia&amp;quot; or &amp;quot;af.wikiquote&amp;quot; etc., including &amp;quot;total&amp;quot;&lt;br /&gt;
		site = site .. &amp;#039;.wikipedia&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	local wantComma = trimArg(args[3])  -- nil for no commas in output; &amp;quot;N&amp;quot; or anything nonblank inserts commas&lt;br /&gt;
	local result&lt;br /&gt;
	if wantMeta then&lt;br /&gt;
		local data = mw.loadData(&amp;#039;Module:NUMBEROF/meta&amp;#039;)&lt;br /&gt;
		local nrActive = data.nrActive[site]&lt;br /&gt;
		local nrClosed = data.nrClosed[site]&lt;br /&gt;
		if nrActive or nrClosed then&lt;br /&gt;
			-- If either is set, site is valid but there may not be an entry for both active and closed.&lt;br /&gt;
			nrActive = nrActive or 0&lt;br /&gt;
			nrClosed = nrClosed or 0&lt;br /&gt;
			if action == &amp;#039;active&amp;#039; then&lt;br /&gt;
				result = nrActive&lt;br /&gt;
			elseif action == &amp;#039;closed&amp;#039; then&lt;br /&gt;
				result = nrClosed&lt;br /&gt;
			elseif action == &amp;#039;languages&amp;#039; then&lt;br /&gt;
				result = nrActive + nrClosed&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		result = getIfLocal(site, action)&lt;br /&gt;
		if not result then&lt;br /&gt;
			local data = mw.loadData(&amp;#039;Module:NUMBEROF/data&amp;#039;)&lt;br /&gt;
			local map = data.map&lt;br /&gt;
			data = data.data&lt;br /&gt;
			result = data[site]&lt;br /&gt;
			if result then&lt;br /&gt;
				result = getValue(result, action, map)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if result then&lt;br /&gt;
		if wantComma then&lt;br /&gt;
			result = mw.language.getContentLanguage():formatNum(result)&lt;br /&gt;
		end&lt;br /&gt;
		return result  -- number or formatted string&lt;br /&gt;
	end&lt;br /&gt;
	return -1&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function rank(frame)&lt;br /&gt;
	-- Rank sites in a specified sister project by their number of articles.&lt;br /&gt;
	local args = frame:getParent().args&lt;br /&gt;
	local parm = trimArg(args[1], 1)  -- a number like 12 or a site name like &amp;quot;af&amp;quot; (not &amp;quot;af.wikipedia&amp;quot;)&lt;br /&gt;
	local base = trimArg(args[2]) or &amp;#039;wikipedia&amp;#039;  -- base of full site name like &amp;quot;wikipedia&amp;quot; or &amp;quot;wikiquote&amp;quot;&lt;br /&gt;
	local wantComma = trimArg(args[3])&lt;br /&gt;
	local data = mw.loadData(&amp;#039;Module:NUMBEROF/&amp;#039; .. (base == &amp;#039;wikipedia&amp;#039; and &amp;#039;rank&amp;#039; or &amp;#039;other&amp;#039;))&lt;br /&gt;
	data = data[base]&lt;br /&gt;
	if data then&lt;br /&gt;
		local result&lt;br /&gt;
		parm = tonumber(parm) or parm&lt;br /&gt;
		if type(parm) == &amp;#039;number&amp;#039; then&lt;br /&gt;
			result = data.rankByIndex[parm]&lt;br /&gt;
		else&lt;br /&gt;
			result = data.rankBySite[parm]&lt;br /&gt;
			if result and wantComma then&lt;br /&gt;
				result = mw.getContentLanguage():formatNum(result)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if result then&lt;br /&gt;
			return result  -- number or string&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return -1&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return {&lt;br /&gt;
	main = main,&lt;br /&gt;
	rank = rank,&lt;br /&gt;
}&lt;/div&gt;</summary>
		<author><name>imported&gt;Johnuniq</name></author>
	</entry>
</feed>