Jump to content

Module:NUMBEROF/data

Permanently protected module
From Meta, a Wikimedia project coordination wiki
Module documentation

Data retrieval from Commons. Invoked by Module:NUMBEROF one time per page.

-- Return a table of statistics to be accessed once per page using mw.loadData.
-- The table contains counts of edits, pages and more for each project.

local function makeData()
	local statistics = mw.ext.data.get('Wikipedia_statistics/data.tab') -- https://commons.wikimedia.org/wiki/Data:Wikipedia_statistics/data.tab
	local data = {}
	for _, v in ipairs(statistics.data) do
		-- Assume "site" is first entry of 8 columns.
		-- v[1] = ["site"] -- e.g. "aa.wikibooks", "aa.wikipedia", "ang.wikisource", "aa.wiktionary", or "commons.wikimedia"
		-- other columns in each row of "data.tab", currently:
		-- v[2] = ["activeusers"] -- integer
    	-- v[3] = ["admins"] -- integer
		-- v[4] = ["articles"] -- integer
    	-- v[5] = ["edits"] -- integer
		-- v[6] = ["files"] -- integer
    	-- v[7] = ["pages"] -- integer
    	-- v[8] = ["users"] -- integer
		data[v[1]] = { v[2], v[3], v[4], v[5], v[6], v[7], v[8] }
	end
	local map = {}
	for i, v in ipairs(statistics.schema.fields) do
		-- Assume "site" is first entry and skip it.
		if i > 1 then
			map[v.name] = i - 1  -- name is lowercase
		end
	end
	return {
		data = data,
		map = map,
	}
end

return makeData()