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:Signpost/archives index/sandbox

From Wikipedia, the free encyclopedia
local p = {}

local function catexists(title)
	local newTitle = mw.title.new
	if newTitle then
		return newTitle(title, 'Category').exists
	end
	return false
end

function p.main(frame)
	local args = frame:getParent().args
	
	local prefix = args.prefix or "Wikipedia:Wikipedia Signpost/Archives/"
	local startYear = tonumber(args.start) or 2005
	local finishYear = tonumber(args.finish) or tonumber(mw.language.new('en'):formatDate('Y'))
	local breakAfter = tonumber(args.break_after) or 10
	
	local output = {}
	local count = 0

	for year = startYear, finishYear do
		local linkTarget = string.format("%s%d", prefix, year)
		
		if catexists(linkTarget) then
			local entry = string.format("*[[%s|%d]]", linkTarget, year)
			count = count + 1
			
			if breakAfter > 0 and count % breakAfter == 0 then
				entry = entry .. "<br/>"
			end
			
			table.insert(output, entry)
		end
	end

	return table.concat(output, "\n")
end

return p