Module:Protection banner

Revision as of 12:39, 2 March 2014 by en>Mr. Stradivarius (add a (very) preliminary sketch of what the main function might look like)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Protection banner/doc

-- This module implements {{pp-meta}} and its daughter templates such as
-- {{pp-dispute}}, {{pp-vandalism}} and {{pp-sock}}.

local categories = {
	{
		name = 'Wikipedia semi-protected user and user talk pages',
		type = 'edit',
		level = 'semi',
		ns = {[2] = true, [3] = true}, -- User and user talk
		reason - 'all'
	},
	{
		name = 'Semi-protected project pages',
		type = 'edit',
		level = 'semi',
		ns = {[4] = true}, -- Project
		reason = 'all'
	},
	{
		name = 'Semi-protected images',
		type = 'edit',
		level = 'semi',
		ns = {[6] = true}, -- File
		reason = 'all'
	},
	{
		name = 'Wikipedia semi-protected templates',
		type = 'edit',
		level = 'semi',
		ns = {[10] = true}, -- Template
		reason = 'all'
	},
	{
		name = 'Semi-protected portals',
		type = 'edit',
		level = 'semi',
		ns = {[100] = true}, -- Portal
		reason = 'all'
	},
	{
		name = 'Semi-protected talk pages',
		type = 'edit',
		level = 'semi',
		ns = 'talk',
		reason = 'all'
	},
	{
		name = 'Wikipedia pages semi-protected against vandalism',
		type = 'edit',
		level = 'semi',
		ns = 'all',
		reason = 'vandalism'
	},
	{
		name = 'Wikipedia protected user and user talk pages',
		type = 'edit',
		level = 'full',
		ns = {[2] = true, [3] = true}, -- User and user talk
		reason = 'all'
	},
	{
		name = 'Protected images',
		type = 'edit',
		level = 'full',
		ns = 'file',
		reason = 'all'
	},
	{
		name = 'Protected project pages',
		type = 'edit',
		level = 'full',
		ns = {[6] = true}, -- File
		reason = 'all'
	},
	{
		name = 'Wikipedia protected templates',
		type = 'edit',
		level = 'full',
		ns = {[10] = true}, -- Template
		reason = 'all'
	},
	{
		name = 'Protected talk pages',
		type = 'edit',
		level = 'full',
		ns = 'talk',
		reason = 'all'
	},
	{
		name = 'Wikipedia pages protected against vandalism',
		type = 'edit',
		level = 'full',
		ns = 'all',
		reason = 'vandalism'
	},
	{
		name = 'Wikipedia pages semi-protected due to dispute',
		type = 'edit',
		level = 'semi',
		ns = 'all',
		reason = 'dispute'
	},
	{
		name = 'Wikipedia pages protected due to dispute',
		type = 'edit',
		level = 'full',
		ns = 'all',
		reason = 'dispute'
	},
	{
		name = 'Wikipedia pages move-protected due to dispute',
		type = 'move',
		level = 'full',
		ns = 'all',
		reason = 'dispute'
	},
	{
		name = 'Wikipedia move-protected user and user talk pages',
		type = 'move',
		level = 'full',
		ns = {[2] = true, [3] = true}, -- User and user talk
		reason = 'all'
	},
	{
		name = 'Wikipedia move-protected project pages',
		type = 'move',
		level = 'full',
		ns = {[4] = true}, -- Project
		reason = 'all'
	},
	{
		name = 'Wikipedia move-protected portals',
		type = 'move',
		level = 'full',
		ns = {[100] = true}, -- Portal
		reason = 'all'
	},
}
	
local error_categories = {
	incorrect = 'Wikipedia pages with incorrect protection templates',
	no_expiry = 'Wikipedia protected pages without expiry'
}

local template_types = {
	vandalism = {
		namespaces = false, -- defaults to all namespaces
		editLevels = false, -- all edit protection levels
		moveLevels = false, -- all move protection levels
		createLevels = false, -- all create protection levels
		header = false,
		reason = 'due to [[Wikipedia:Vandalism|vandalism]]',
		icon_reason = 'due to vandalism',
	}
}

--------------------------------------------------------------------------------
-- Main functions
--------------------------------------------------------------------------------

local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')

local p = {}

function p.main(frame)
	-- Get data
	local args = getArgs(frame)
	local title = p.getTitle(args.page)
	local protType, protLevel = p.getProtectionStatus(title)
	local namespace = p.getNamespace(title)
	local expiry = p.getExpiry(args.expiry)
	local reason = p.getReason(args.reason)

	-- Sort categories and build a category link with the best match
	categories = p.sortCategories(categories, protType, protLevel, namespace, expiry, reason)
	local category = categories[1].name
	category = string.format('[[Category:%s]]', category)

	-- Find whether we are small or not and output a padlock or a banner as appropriate
	local isSmall = yesno(args.small, true)
	if isSmall then
		return p.exportPadlock()
	else
		return p.exportBanner()
	end
end

return p