Module:Report

local loader = require('Module:Loader') local string, table, yesno, lu, arguments, userM = loader.require('String', 'Table', 'Yesno', 'LibU', 'Arguments', 'User')

local checkType, pipeline, getArgs, mergeArgsSyntax = lu.checkType, lu.pipeline, arguments.getArgs, arguments.mergeArgsSyntax local sep = ' • '

-- Begin Exports local p = {}

-- Helper Functions local function bracket(s) return string.wrapHtml( ('(%s)'):format(s), ' ', { style = 'font-size: 10px' } ) end

function p._buildLinks(user, isIp) checkType(1, user, 'string') checkType(2, isIp, { 'boolean', 'nil' }) local ret = {} local res = userM.genLinks(user) if not isIp then table.push(ret, res['wall'], res['contribs']) end table.push(ret, res['posts'], res['delcontribs'], res['logs'], res['blocklog'], res['abuselog'], res['block'], res['nuke']) if isIp then table.push( ret, res['whois'], res['proxy'], res['spam']) end return res['usercontribs'] .. ' ' .. bracket(table.concat(ret, sep)) end p.buildLinks = p._buildLinks

- -- Template: Report -- -- Generates a Report about a user - function p.main(frame) local args = getArgs(frame) local user = args['reported_user'] or args['ru'] or args['user'] or args['u'] or args[1] local reporter = args['reporter'] or args['r'] or args[2] local timestamp = args['timestamp'] or args['ts'] or args[3] local reason = args['reason'] or args['res'] or args[4] if not user then return error('Please provide a username to report!') elseif not reporter then return error('Please provide your signature!') elseif not reason then return error('Please provide a reason why you are reporting %s!', userM._trimUser(user)) end return p._main(user, reporter, timestamp, reason) end function p._main(user, reporter, timestamp, reason) local function reportLink(user) return p._buildLinks(userM._trimUser(user), userM.isIp(user)) end checkType(1, user, 'string') checkType(2, reporter, 'string') checkType(3, timestamp, 'string') checkType(4, reason, 'string') local links = reportLink(user) local reporter = userM._trimUser(reporter) local split = mw.text.split(user, '%s*,%s*') local res = userM.genLinks(reporter) if #split > 1 and type(split) == 'table' then local tmp = {} for i, v in ipairs(split) do			table.push(tmp, v)		end links = pipeline(table.map(split, function(v) return string.wrapTag(reportLink(v), 'li') end), 'ul', string.wrapTag) end local userinfo = table.concat({		res['wall'], res['contribs'],	}, sep) local listitems = table.map({		('Reported User%s: %s'):format((#split > 1 and type(split) == 'table') and 's' or '', links),		('Signature: %s %s'):format( res['user'], bracket(userinfo) ),		'Timestamp: ' .. timestamp,		'Reason: ' .. reason,	}, function(v)		return string.wrapHtml(v, 'li')	end) return string.wrapHtml(listitems, 'ul') end

- -- Template: Deletion request -- -- Generates a deletion request for a page - function p.delete(frame) local args = getArgs(frame) return p._delete(table.unpack(table.deepCopy(args))) end function p._delete(...) local function buildPageLinks(page) checkType(1, page, 'string', true) page = page or mw.title.getCurrentTitle.fullText local res = userM.genLinks(page) local ret = { res['edit'], res['history'], res['latest'], res['links'], res['subpages'], res['logs'], res['abuselog'], res['undelete'], res['protect'], res['delete'], res['move'], }		return string.wrapLink(page) .. bracket(table.concat(ret, sep)) end local page, reporter, timestamp, reason, comments = ... checkTypeArgs({		'string',		'string',		'string',		'string',		'string',	}, ...) local page = string.trim(page) local reason = string.trim(reason) local links = buildPageLinks(page) local reporter = userM._trimUser(reporter) local comments = string.trim(comments) local timestamp = string.trim(timestamp) local listitems = table.map({		'Page: ' .. links,		'Timestamp: ' .. timestamp,		'Reporter: ' .. reporter,		'Reason for report: ' .. reason,		'Addtional comments: ' .. reason,	}, function(v)		return string.wrapHtml(v, 'li')	end) return string.wrapHtml(listitems, 'ul') end

- -- Template: AFPage - function p.afpage(frame) local args = getArgs(frame) return p._afpage(args) end function p._afpage(args) if (table.length(args) < 1) then return '' end return table.concat(table.map(mergeArgsSyntax(args), function(v) return ('%s'):format(v, v)	end), ' ') end

--Finish Module/Exports return p