Jump to content

Module:Speedy deletion

Lát'ọwọ́ Wikipedia, ìwé ìmọ̀ ọ̀fẹ́

Documentation for this module may be created at Module:Speedy deletion/doc

-- This module implements the speedy deletion templates.

local p = {}
local cfg = require('Module:Speedy deletion/config')
local getArgs = require('Module:Arguments').getArgs
local messageBox = require('Module:Message box').main
local categoryHandler = require('Module:Category handler')._main
local pageType = require('Module:Pagetype').main
local timeAgo = require('Module:TimeAgo').main
local toolbar = require('Module:Toolbar').main
local yesno = require('Module:Yesno')

-- Joins the tables a and b, and returns the result. Pairs in b override the
-- respective pairs in a, if they exist.
local function joinTables(a, b)
	local ret = {}
	for k, v in pairs(a) do
		ret[k] = v
	end
	for k, v in pairs(b) do
		ret[k] = v
	end
	return ret
end

local function makeText(stringOrTemplate, pagename, args)
	if type(stringOrTemplate) == "string" then
		return stringOrTemplate
	else
		return stringOrTemplate(pagename, args)
	end
end

local function fullUrl(pagename, args)
	return tostring(mw.uri.fullUrl(pagename, args))
end

-- Please call using p._csdSingle{...}.
function p._csdSingle(args)
	local currentTitle
	if args.demo then
		currentTitle = mw.title.new(args.demo)
	else
		currentTitle = mw.title.getCurrentTitle()
	end
	local frame = mw.getCurrentFrame()
	local language = mw.language.getContentLanguage()
	local pagename = currentTitle.fullText
	local code = args.criterion
	local criterion = cfg[code]
	if criterion.criterion then
		code = criterion.criterion
		criterion = joinTables(criterion, cfg[code])
	end
	local summary = makeText(criterion.summary, pagename, args)
	local description = makeText(criterion.description, pagename, args)
	local notes = makeText(criterion.notes or "", pagename, args)
	local pagetype = pageType({defaultns = "all"})
	local removalNotice, otherNotices, considerGoogle, revisionInfo, botNote
	local revisionUser = frame:preprocess("{{REVISIONUSER}}")
	local revisionTimestamp = frame:preprocess("{{REVISIONTIMESTAMP}}")
	if criterion.bySelf then
		removalNotice = frame:preprocess(cfg.removalNotices.withSelf)
		considerGoogle = ""
	else
		removalNotice = frame:preprocess(cfg.removalNotices.withoutSelf)
		considerGoogle = "Consider [[google:" .. mw.uri.encode(currentTitle.text) .. "| checking Google]]."
	end
	if args.bot ~= "" then
		botNote = cfg.botNote
	else
		botNote = ""
	end
	if revisionTimestamp ~= "" then
		revisionInfo =
			   " by [["
			.. frame:preprocess("{{ns:2}}")
			.. ":" .. revisionUser .. "|" .. revisionUser .. "]] <small>"
			.. toolbar({
					"[[Special:Contributions/" .. revisionUser .. "|contribs]]",
					"[[Special:Log/" .. revisionUser .. "|logs]]"
				})
			.. "</small> at "
			.. language:formatDate("H:i, j F Y (e)", revisionTimestamp)
			.. " ([" .. fullUrl(pagename, "action=purge") .. " "
			.. timeAgo({revisionTimestamp})
			.. "])</small>"
	elseif revisionUser ~= "" then
		revisionInfo =
			   " by [["
			.. frame:preprocess("{{ns:2}}")
			.. ":" .. revisionUser .. "|" .. revisionUser .. "]] <small>"
			.. toolbar({
					"[[Special:Contributions/" .. revisionUser .. "|contribs]]",
					"[[Special:Log/" .. revisionUser .. "|logs]]"
				})
			.. "</small>"
	else
		revisionInfo = ""
	end
	-- Will be filled in a later version (with contest button, ...).
	otherNotices = ""
	local text = 
		   -- FIXME
		   frame:preprocess(mw.message.newRawMessage(cfg.header, pagetype, args.bot or ""):plain())
		.. " " .. description
		.. mw.message.newRawMessage(cfg.seeCSD, code):plain()
		.. '<span id="delete-reason" style="display:none;">' .. mw.uri.encode(summary)
		.. '</span><span id="delete-criterion" style="display:none;">' .. code
		.. "</span><p class=\"verbose\">If this " .. pagetype
		.. " does not meet the criteria for speedy deletion, "
		.. removalNotice .. "</p>" .. otherNotices .. notes
		-- Message for administrators
		.. "<small><span class=\"sysop-show\">''Administrators: check [[Special:Whatlinkshere/"
		.. pagename .. "|links]], ["
		.. fullUrl(pagename, "action=history") .. " history] (["
		.. fullUrl(pagename, "diff=0") .. " last]), and ["
		.. fullUrl("Special:Log", {page = pagename}) .. " logs] before ["
		.. fullUrl(pagename, {
				wpReason = mw.uri.encode(mw.message.newRawMessage(cfg.deletionSummaryFormat, code, summary):plain()),
				action = "delete"
			}) .. " deletion]"
		.. botNote
		.. (criterion.anote or ".")
		.. considerGoogle .. "''<br/></span>"
		.. "This page was ["
		.. fullUrl(pagename, "diff=cur") .. " last edited] "
		.. revisionInfo
	return "__NOINDEX__" .. messageBox("mbox", {
		class = "mbox-db",
		type = "speedy",
		image = "none",
		style = "font-size: 95%;",
		text = text
	}) .. (categoryHandler{
		all = cfg.allCandidatesCategory .. criterion.category,
		nocat = yesno(args.nocat),
		page = pagename
	} or "")
end

function p.csdSingle(frame)
	return p._csdSingle(getArgs(frame))
end

return p