Module:Report

-- -- @authors Noreplyz -- Borrowed from VSTF Wiki. -- --[[                                Module:Report

Module for report templates. Proofreads user input. This module is invoked using Template:Report spam, Template:Report vandalism, Template:Report profile and Template:Report filter.

--]] --

local p = {} local fallback = require('Module:Fallback') local i18n = require('Module:Report/i18n')

-- remove excess or wrongly entered content function trim(s) s = s:match( "^%s*(.-)%s*$" ) return s end

function trim_wiki(s) s = s:match( "^%s*(.-)%s*$" ) s = s:gsub("http:%/%/","") s = s:gsub("%.wikia%.com.*", "") return s end

function trim_page(s) s = s:match( "^%s*(.-)%s*$" ) s = s:gsub("http:%/%/","") s = s:gsub("^.*%.wikia%.com%/wiki%/","") s = s:gsub("^.*%.wikia%.com%/","") s = s:gsub(" ","_") return s end

function trim_user(s) s = s:match( "^%s*(.-)%s*$" ) s = s:gsub("http:%/%/","") s = s:gsub("^.*%.wikia%.com%/wiki%/","") s = s:gsub("^.*%.wikia%.com%/","") s = s:gsub("User:","") s = s:gsub("Special:Contributions%/","") s = s:gsub("Special:Contribs%/","") s = s:gsub(" ","_") s = s:gsub("&","%%26") return s end

function trim_reason(s) s = s:match( "^%s*(.-)%s*$" ) s = s:gsub( "\\\\", "|" ) return s end

function trim_id(s) s = s:match( "^%s*(.-)%s*$" ) s = s:gsub("#","") return s end

function crosswikilinks(user, wiki) local ippattern = "[^%d+%.%d+%.%d+%.%d+$]" local cwret = {} cwret[#cwret + 1] = ' ' if (string.match(user, ippattern) == nil) then cwret[#cwret + 1] = '(.. user .. ' ML &bull; '   else        cwret[#cwret + 1] = '([http://c.wikia.com/wiki/Special:LookupContribs?target=' .. user .. ' LC] &bull; ' end cwret[#cwret + 1] = '[http://' .. wiki .. '.wikia.com/wiki/Special:CheckUser?user=' .. user .. ' CU] &bull; ' .. '[http://c.wikia.com/wiki/Special:Phalanx?type=8&target=' .. user .. '&wpPhalanxCheckBlocker=' .. user .. ' Phalanx])'   cwret[#cwret + 1] = ' '    return table.concat(cwret) end

-- creates the general format of the report -- reportType: string of the type of user (Spammer, Vandal, Profile, Phalanx) function createReport(frame, reportType) local tArgs = frame:getParent    -- all arguments local ret = {}                     -- the return string

-- check how many total users local numArgs = 0 for key, value in ipairs(tArgs.args) do numArgs = numArgs + 1 end -- report params local wiki = trim_wiki(tArgs.args[1] or "") local reason = trim_reason(tArgs.args[2] or "") local user = "" local crosswiki = trim(tArgs.args["crosswiki"] or "") local socks = trim(tArgs.args["socks"] or "") local reporter = tArgs.args[numArgs - 1] or "" local time = tArgs.args[numArgs] or "" local lang = frame:preprocess( "" ) -- report-specific params local skin = "" if reportType == fallback.langSwitchCode(i18n, lang, "profile") then skin = "?useskin=wikia" end local page = "" local blockId = "" if reportType == "Phalanx" then page = trim_page(tArgs.args[2] or "") blockId = trim_id(tArgs.args[3] or "") reason = tArgs.args[4] or "" end

-- start report creation ret[#ret + 1] = ' \n' ret[#ret + 1] = '*' .. fallback.langSwitchCode(i18n, lang, "wiki") .. ': http://' .. wiki .. '.wikia.com \n' if reportType == "Phalanx" then -- Filter problem only ret[#ret + 1] = '*'.. fallback.langSwitchCode(i18n, lang, "page") .. ': http://' .. wiki .. '.wikia.com/wiki/' .. page .. ' \n' ret[#ret + 1] = '*'.. fallback.langSwitchCode(i18n, lang, "blockid") .. ': http://community.wikia.com/wiki/Special:PhalanxStats/' .. blockId .. ' \n' else if crosswiki == "yes" then ret[#ret + 1] = "*''" .. fallback.langSwitchCode(i18n, lang, "cwmsg") .. "''\n" end -- Spam, Vandalism or Profile report if numArgs >= 20 then ret[#ret + 1] = ' \n' end for key, value in ipairs(tArgs.args) do            if (key >= 3 and key <= (numArgs - 2)) then user = trim_user(value) or "" ret[#ret + 1] = '*' .. reportType .. ': http://' .. wiki .. '.wikia.com/wiki/Special:Contributions/' .. user .. skin .. ' '               if (reportType == fallback.langSwitchCode(i18n, lang, "spammer")) then ret[#ret + 1] = ' (DelContribs) ' end -- add c/w links if (crosswiki == "yes") then ret[#ret + 1] = crosswikilinks(user, wiki) end ret[#ret + 1] = '\n' end end if numArgs >= 20 then ret[#ret + 1] = ' \n' end if socks ~= "" then ret[#ret + 1] = "*''".. fallback.langSwitchCode(i18n, lang, "spmsg") .. "''\n" for sock in string.gmatch(socks, '([^\n]+)') do               sock = trim_user(sock) or "" ret[#ret + 1] = '**' .. fallback.langSwitchCode(i18n, lang, "sock") .. ': ' .. sock .. '' ret[#ret + 1] = crosswikilinks(sock, wiki) ret[#ret + 1] = '\n' end end

end ret[#ret + 1] = '*' .. fallback.langSwitchCode(i18n, lang, "reason") .. ': '.. reason ..'\n' ret[#ret + 1] = '*' .. fallback.langSwitchCode(i18n, lang, "sig") .. ': -- ' .. reporter .. ' (' .. fallback.langSwitchCode(i18n, lang, "talk") .. ') ' .. time .. '\n' ret[#ret + 1] = ' '

return table.concat(ret) end

function p.spam(frame) local lang = frame:preprocess( "" ) return createReport(frame, fallback.langSwitchCode(i18n, lang, "spammer")) end

function p.vandalism(frame) local lang = frame:preprocess( "" ) return createReport(frame, fallback.langSwitchCode(i18n, lang, "vandal")) end

function p.profile(frame) local lang = frame:preprocess( "" ) return createReport(frame, fallback.langSwitchCode(i18n, lang, "profile")) end

function p.filter_problem(frame) return createReport(frame, "Phalanx") end

return p --