Module:Sandbox/ProcrastinatingReader
Appearance
local p = {}
local getArgs = require('Module:Arguments').getArgs
local error = require('Module:Error')
local tableTools = require('Module:TableTools')
local data = mw.loadData('Module:Sandbox/ProcrastinatingReader/data')
-- G4 functions
local function getDeletionDiscussions()
local namespaceMap = {
[""] = "Articles for deletion",
["Category"] = "Categories for discussion",
["File"] = "Files for discussion",
["Template"] = "Templates for discussion",
["Module"] = "Templates for discussion",
}
--local current_page = mw.title.getCurrentTitle()
local output = ""
local n = 1
local current_page = mw.title.new("Premadasa Hegoda")
local nsPrefix = namespaceMap[current_page.nsText] or "Miscellany for deletion"
while true do -- possibly expensive if lots of noms
page = mw.title.makeTitle('Wikipedia', nsPrefix..'/'..current_page.text..(n > 1 and " ("..n.."nd nomination)" or ""))
if page.exists then
output = output ..(n > 1 and ", " or "").."[["..page.prefixedText.."|XfD"..(n > 1 and " ("..n..")" or "").."]]"
n = n + 1
else
break
end
end
return output
end
-- Message functions
local function substitute(msg, args)
return args and mw.message.newRawMessage( msg, args ):plain() or msg;
end
local function substituteMsgParams(msgKey, msg)
local replacements = {
['g4.message'] = {"{{fullurl:Special:Log|type=delete&page={{FULLPAGENAMEE}}}}"},
['g4.extra'] = {getDeletionDiscussions()}
}
return substitute(msg, replacements[msgKey])
end
local function buildMsgParams(criterion, key, data, args)
local msg = substituteMsgParams(criterion..'.'..key, data[key])
local appendMsg = ""
local extraParams = data['params']
if extraParams then
for k,param in pairs(extraParams) do
local keys = param.keys
for j,paramkey in pairs(keys) do
if args[paramkey] and param['append'][key] then -- check if we have a defined param given, and it matches what we're processing
-- assign to msg if we have appends
appendMsg = substitute(param['append'][key], args[paramkey])
end
end
end
end
return msg .. appendMsg
end
-- Returns
function p.build(frame, args)
local criterion = args['criterion']
if criterion == nil or data[criterion] == nil then
return error.error({message = "Valid CSD not provided"})
end
local cdata = data[criterion]
local tag = cdata.tag
if tag == nil then
return error.error({message = "CSD "..criterion.." does not have a tag"})
end
template = frame:expandTemplate{ title = 'db-meta', args = {
-- Required
' '..frame:preprocess(buildMsgParams(criterion:lower(), 'message', tag, args)), -- Main text, in bold
frame:preprocess(buildMsgParams(criterion:lower(), 'extra', tag, args)) or '', -- Main text, in italics
criterion = criterion, -- Criteron
-- Additional data
notes = tag['notes'] or '',
anotes = tag['anotes'] or '',
summary = data[criterion]['description'],
temp = data[criterion]['warn_template'],
-- Pass generic params onto db-meta
bot = args['bot'] or '',
raw = args['raw'] or '',
['self'] = tag['self'] or '',
image = args['image'] or '',
wiki = args['wiki'] or '',
blanked = args['blanked'] or '',
blankedtext = args['blanked-text'] or '',
pleaseblank = args['pleaseblank'] or '',
divblank = args['divblank'] or '',
help = args['help'] or ''
}}
categorisation = '<includeonly>' .. frame:expandTemplate{
title = 'cat handler',
args = {
['all'] = '{{NOINDEX}}[[:Category:Candidates for speedy deletion]][[:Category:'..cdata['tracking_category']..']]',
['nocat'] = 'false'
}
} .. '</includeonly>'
return template .. frame:preprocess(categorisation)
end
function p.main(frame)
local args = getArgs(frame)
return p.build(frame, args)
end
return p