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"
}
--local current_page = mw.title.getCurrentTitle()
local output = ""
local n = 1
local current_page = mw.title.new("Premadasa Hegoda")
local namespace = current_page.nsText
while true do -- possibly expensive
page = mw.title.makeTitle('Wikipedia', namespaceMap[namespace]..'/'..current_page.text..(n > 1 and " ("..n.."nd nomination)" or ""))
if page.exists then
output = output .. "[["..page.prefixedText.."]]"
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
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(substituteMsgParams(criterion:lower()..'.message', tag['message'])), -- Main text, in bold
frame:preprocess(substituteMsgParams(criterion:lower()..'.extra', tag['extra'])) 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, {
wrappers = {
--'Template:Sandbox/ProcrastinatingReader'
}
})
return p.build(frame, args)
end
return p