Jump to content

Module:Deletion sorting/sandbox: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Don't need this variable any more, since we're already rebuilding the list of args with any invalid ones removed.
Only two error messages, no need for sub-function
Line 1: Line 1:
local p = {}
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)
function p.delsort(frame)
Line 16: Line 11:
table.insert(args, title.rootText)
table.insert(args, title.rootText)
else
else
return makeError('Input contains forbidden characters.')
return mw.text.tag('strong', {['class']='error'}, 'Error in [[Template:Deletion sorting]]: Input contains forbidden characters.')
end
end
elseif k:sub(0,3) == 'sig' then
elseif k:sub(0,3) == 'sig' then
Line 25: Line 20:


if #args == 0 then
if #args == 0 then
if frame.args.example then args[1] = frame.args.example else return makeError('Category not specified.') end
if frame.args.example then
args[1] = frame.args.example
else
return mw.text.tag('strong', {['class']='error'}, 'Error in [[Template:Deletion sorting]]: Category not specified.')
end
end
end
local outStr = 'Note: This discussion has been included in the '
local outStr = 'Note: This discussion has been included in the '

Revision as of 16:34, 18 February 2022

local p = {}

function p.delsort(frame)
	local args = {}
	local sig = os.date("!%H:%M, %e %B %Y (UTC)")
	for k, v in pairs(frame:getParent().args) do
		if mw.ustring.match(v,'%S') then
			if type(k) == 'number' then
				local title = mw.title.new(v)
				if title and title.rootText then
					table.insert(args, title.rootText)
				else
					return mw.text.tag('strong', {['class']='error'}, 'Error in [[Template:Deletion sorting]]: Input contains forbidden characters.')
				end				
			elseif k:sub(0,3) == 'sig' then
				sig = v
			end
		end
	end

	if #args == 0 then
		if frame.args.example then
			args[1] = frame.args.example
		else
			return mw.text.tag('strong', {['class']='error'}, 'Error in [[Template:Deletion sorting]]: Category not specified.')
		end
	end
	local outStr = 'Note:  This discussion has been included in the '
	if #args == 1 then
		outStr = outStr..'[[Wikipedia:WikiProject Deletion sorting/'..args[1]..'|list of '..args[1]..'-related deletion discussions]]'
	else
		outStr = outStr .. '[[Wikipedia:WikiProject Deletion sorting|deletion sorting]] lists for the following topics: '
		for i = 1, #args do
			if i > 1 then
				if #args > 2 then outStr = outStr..', ' end
				if i == #args then outStr = outStr..' and ' end
			end
			outStr = outStr..'[[Wikipedia:WikiProject Deletion sorting/'..args[i]..'|'..args[i]..']]'
		end
	end
	outStr = outStr..'. '..sig
	return mw.text.tag('small', {['class']='delsort-notice'}, outStr)
end

return p