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:Draft topics/sandbox

From Wikipedia, the free encyclopedia
local getArgs = require('Module:Arguments').getArgs
local resolveRedirect = require('Module:Resolve category redirect')
local p = {}

local map = {
	['biography'] = 'biographies',
	['women'] = 'women',
	['food-and-drink'] = 'food and drink',
	['internet-culture'] = 'Internet culture',
	['linguistics'] = 'linguistics',
	['literature'] = 'literature',
	['books'] = 'books',
	['entertainment'] = 'entertainment',
	['films'] = 'films',
	['media'] = 'media',
	['music'] = 'music',
	['radio'] = 'radio',
	['software'] = 'software',
	['television'] = 'television',
	['video-games'] = 'video games',
	['performing-arts'] = 'performing arts',
	['philosophy-and-religion'] = 'philosophy and religion',
	['sports'] = 'sports',
	['architecture'] = 'architecture',
	['comics-and-anime'] = 'comics and anime',
	['fashion'] = 'fashion',
	['visual-arts'] = 'visual arts',
	['geographical'] = 'geographical topics',
	['africa'] = 'Africa',
	['central-africa'] = 'Central Africa',
	['eastern-africa'] = 'Eastern Africa',
	['northern-africa'] = 'Northern Africa',
	['southern-africa'] = 'Southern Africa',
	['western-africa'] = 'Western Africa',
	['central-america'] = 'Central America',
	['north-america'] = 'North America',
	['south-america'] = 'South America',
	['asia'] = 'Asia',
	['central-asia'] = 'Central Asia',
	['east-asia'] = 'East Asia',
	['north-asia'] = 'North Asia',
	['south-asia'] = 'South Asia',
	['southeast-asia'] = 'Southeast Asia',
	['west-asia'] = 'West Asia',
	['eastern-europe'] = 'Eastern Europe',
	['europe'] = 'Europe',
	['northern-europe'] = 'Northern Europe',
	['southern-europe'] = 'Southern Europe',
	['western-europe'] = 'Western Europe',
	['oceania'] = 'Oceania',
	['business-and-economics'] = 'business and economics',
	['education'] = 'education',
	['history'] = 'history',
	['military-and-warfare'] = 'military and warfare',
	['politics-and-government'] = 'politics and government',
	['society'] = 'society',
	['transportation'] = 'transportation',
	['biology'] = 'biology',
	['chemistry'] = 'chemistry',
	['computing'] = 'computing',
	['earth-and-environment'] = 'earth and environment',
	['engineering'] = 'engineering',
	['libraries-and-information'] = 'libraries and information',
	['mathematics'] = 'mathematics',
	['medicine-and-health'] = 'medicine and health',
	['physics'] = 'physics',
	['stem'] = 'STEM',
	['space'] = 'space',
	['technology'] = 'technology'
}

local allowed = {}
for _, v in pairs(map) do
	allowed[v] = true
end

local function resolve(cat, frame)
	local full = 'Draft articles about ' .. cat
	local ok, result = pcall(function()
		return resolveRedirect.rtarget(full, frame)
	end)

	if not ok or not result or result == '' then
		return cat
	end

	result = result:gsub('^Category:%s*', '')
	result = result:gsub('^Draft articles about%s+', '')

	return result
end

function p.main(frame)
	local args = getArgs(frame)
	local ns = mw.title.getCurrentTitle().namespace

	if ns ~= 118 and ns ~= 2 then
		return '[[Category:Draft topics used in wrong namespace]]'
	end

	if not args[1] then
		return '[[Category:Draft articles tagged with invalid topic parameter]]'
	end

	local output = {}
	local hasError = false

	for _, topic in ipairs(args) do
		local base = map[topic] or topic

		local resolved = resolve(base, frame)

		if not allowed[resolved] then
			hasError = true
		else
			table.insert(output, '[[Category:Draft articles about ' .. resolved .. ']]')
		end
	end

	if hasError then
		table.insert(output, '[[Category:Draft articles tagged with invalid topic parameter]]')
	end

	return table.concat(output)
end

return p