Module:Deletion sorting/sandbox: Difference between revisions
Appearance
Content deleted Content added
add sig |
Optimize code, use shorter names for multiple categories |
||
Line 7: | Line 7: | ||
function p.delsort(frame) |
function p.delsort(frame) |
||
local origArgs = frame:getParent().args |
|||
local args = {} |
local args = {} |
||
⚫ | |||
local cats = 0 |
|||
local sig = os.date("!%H:%M, %e %B %Y (UTC)") |
local sig = os.date("!%H:%M, %e %B %Y (UTC)") |
||
for k, v in pairs( |
for k, v in pairs(frame:getParent().args) do |
||
if |
if mw.ustring.match(v,'%S') then |
||
if |
if type(k) == 'number' then |
||
if k > maxArg then maxArg = k end |
|||
cats = cats + 1 |
|||
local title = mw.title.new(v) |
local title = mw.title.new(v) |
||
if title and title.rootText then |
|||
⚫ | |||
args |
table.insert(args, title.rootText) |
||
else |
|||
⚫ | |||
end |
|||
⚫ | |||
⚫ | |||
end |
end |
||
⚫ | |||
⚫ | |||
end |
end |
||
end |
end |
||
if |
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 makeError('Category not specified.') end |
||
end |
end |
||
local isfirst = true |
|||
local outStr = 'Note: This discussion has been included in the ' |
local outStr = 'Note: This discussion has been included in the ' |
||
if #args == 1 then |
|||
⚫ | |||
if args[i] then |
|||
else |
|||
⚫ | |||
outStr = outStr .. '[[Wikipedia:WikiProject Deletion sorting|deletion sorting]] lists for the following topics: ' |
|||
for i = 1, #args do |
|||
if isfirst then |
if isfirst then |
||
isfirst = false |
isfirst = false |
||
else |
else |
||
if |
if #args > 2 then outStr = outStr..', ' end |
||
if i == |
if i == #args then outStr = outStr..' and ' end |
||
end |
end |
||
outStr = outStr..'[[Wikipedia:WikiProject Deletion sorting/'..args[i]..'|'..args[i]..']]' |
|||
outStr = string.format( |
|||
⚫ | |||
outStr, |
|||
args[i], |
|||
args[i] |
|||
) |
|||
end |
end |
||
end |
end |
||
outStr = outStr..'. '..sig |
outStr = outStr..'. '..sig |
||
return mw.text.tag('small', {['class']='delsort-notice'}, outStr) |
return mw.text.tag('small', {['class']='delsort-notice'}, outStr) |
||
end |
end |
||
Revision as of 15:50, 18 February 2022
![]() | This is the module sandbox page for Module:Deletion sorting (diff). |
Implements {{Deletion sorting/multi}}.
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 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 makeError('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 makeError('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
local isfirst = true
outStr = outStr .. '[[Wikipedia:WikiProject Deletion sorting|deletion sorting]] lists for the following topics: '
for i = 1, #args do
if isfirst then
isfirst = false
else
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