Jump to content

Module:Deletion sorting/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Ahecht (talk | contribs) at 04:54, 18 February 2022 (fix example). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}

local function makeError(msg)
	msg ='Error in [[Template:Deletion sorting]]: ' .. msg
	return mw.text.tag('strong', {['class']='error'}, msg)
end

function p.delsort(frame)
	local origArgs = frame:getParent().args
	local args = {}
	local maxArg = 1
	local cats = 0
	local sig = os.date("!%H:%M, %e %B %Y (UTC)")
	for k, v in pairs(origArgs) do
		if type(k) == 'number' then
			if mw.ustring.match(v,'%S') then
				if k > maxArg then maxArg = k end
				cats = cats + 1
				local title = mw.title.new(v)
				if not title then return makeError('Input contains forbidden characters.') end
				args[k] = title.rootText
			end
		elseif v ~= '' and k:sub(0,3) == 'sig' then
			sig = v
		end
	end

	if cats < 1 then
		if frame.origArgs.example then args[1] = frame.origArgs.example else return makeError('Category not specified.') end
	end
	local isfirst = true
	local outStr = 'Note:  This discussion has been included in the '
	for i = 1, maxArg do
		if args[i] then
			if isfirst then
				isfirst = false
			else
				if ( (cats > 2) or ((cats == 2) and (args['c'] == '')) ) then outStr = outStr..', ' end
				if i == maxArg then outStr = outStr..' '..(args['c'] or 'and') .. ' ' end
			end
			outStr = string.format(
				'[[Wikipedia:WikiProject Deletion sorting/%s|list of %s-related deletion discussions]]',
				outStr,
				args[i],
				args[i]
			)
		end
	end
	outStr = outStr..'.'
	return mw.text.tag('small', {['class']='delsort-notice'}, outStr)

end

return p