Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

Jump to content

Module:Archive URL counts/data

From Wikipedia, the free encyclopedia
-- Return a table of URL statistics to be accessed once per page using mw.loadData.
-- Data is pulled from Commons:Data:Wikipedia statistics/exturls.tab

local function last_update_get (description)
	return description:match ('%a%a%a %d%d? %d%d:%d%d:%d%d UTC %d%d%d%d');		-- extract and return the date substring; we'll prettify it later
end


local function makeData()
	local statistics = mw.ext.data.get('Wikipedia statistics/exturls.tab')
	local data = {}
	
	-- The schema fields dynamically map the column names to their index
	local map = {}
	for i, v in ipairs(statistics.schema.fields) do
		if i > 1 then
			map[v.name] = i - 1  -- skip 'site' column, names are lowercase
		end
	end

	-- Build the fast-lookup table
	-- Since there are 16 data columns (excluding 'site'), we unpack them all
	for _, v in ipairs(statistics.data) do
		data[v[1]] = { 
			v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9],
			v[10], v[11], v[12], v[13], v[14], v[15], v[16], v[17]
		}
	end
	
	return {
		data = data,
		map = map,
		last_update = last_update_get (statistics.description),					-- <statistics.description> holds the date of the table's last update; extract the date
	}
end

return makeData()