FANDOM


-- <nowiki>
-- @authors Noreplyz
 
--------------------------------------------------------------------------
--[[ 
                                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 switch = 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("https:%/%/","")
    s = s:gsub("%.wikia%.com.*", "")
    return s
end
 
function trim_page(s)
    s = s:match( "^%s*(.-)%s*$" )
    s = s:gsub("http:%/%/","")
    s = s:gsub("https:%/%/","")
    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("https:%/%/","")
    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, https)
    local ippattern = "[^%d+%.%d+%.%d+%.%d+$]"
    local cwret = {}
    cwret[#cwret + 1] = '<span style="font-size:11px;margin-left:10px;">'
    if (string.match(user, ippattern) == nil) then
        cwret[#cwret + 1] = '([https://community.wikia.com/wiki/Special:MultiLookup?wptarget='
        cwret[#cwret + 1] = user 
        cwret[#cwret + 1] = ' ML] &bull; '
    else
        cwret[#cwret + 1] = '([https://community.wikia.com/wiki/Special:LookupContribs?target='
        cwret[#cwret + 1] = user
        cwret[#cwret + 1] = ' LC] &bull; '
    end
    cwret[#cwret + 1] = '[' .. https
    cwret[#cwret + 1] = wiki
    cwret[#cwret + 1] = '.wikia.com/wiki/Special:CheckUser?user='
    cwret[#cwret + 1] = user
    cwret[#cwret + 1] = ' CU] &bull; '
    cwret[#cwret + 1] = '[https://community.wikia.com/wiki/Special:Phalanx?type=8&target=' 
    cwret[#cwret + 1] = user
    cwret[#cwret + 1] = '&wpPhalanxCheckBlocker='
    cwret[#cwret + 1] = user
    cwret[#cwret + 1] = ' Phalanx])'
    cwret[#cwret + 1] = '</span>'
    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
    local lang = frame:preprocess( "{{int:lang}}" )
    local i18n = fallback._langSwitch(switch, lang)
 
    -- 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 https = 'http://'
    if not string.find(wiki, '%.') then
        https = 'https://'
    end
 
    -- report-specific params
    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] = '<div class="reports">\n'
    ret[#ret + 1] = '*'
    ret[#ret + 1] = i18n["wiki"]
    ret[#ret + 1] = ': <span class="plainlinks">' .. https 
    ret[#ret + 1] = wiki
    ret[#ret + 1] = '.wikia.com</span> <span style="font-size:11px;margin-left:10px;">([' .. https 
    ret[#ret + 1] = wiki
    ret[#ret + 1] = '.wikia.com/wiki/Special:ListAdmins admins])</span>\n'
 
    if reportType == "Phalanx" then
        -- Filter problem only
        ret[#ret + 1] = '*'
        ret[#ret + 1] = i18n["page"]
        ret[#ret + 1] = ': <span class="plainlinks">' .. https
        ret[#ret + 1] = wiki
        ret[#ret + 1] = '.wikia.com/wiki/' 
        ret[#ret + 1] = page 
        ret[#ret + 1] = '</span>\n'
 
        ret[#ret + 1] = '*'
        ret[#ret + 1] = i18n["blockid"] 
        ret[#ret + 1] = ': <span class="plainlinks">https://community.wikia.com/wiki/Special:PhalanxStats/' 
        ret[#ret + 1] = blockId 
        ret[#ret + 1] = '</span>\n'
 
    else
        if crosswiki == "yes" then
            ret[#ret + 1] = "*''" .. i18n["cwmsg"] .. "''\n"
        end
        -- Spam, Vandalism or Profile report
        if numArgs >= 20 then
            ret[#ret + 1] = '<div class="reports-scrollbox">\n'
        end
        for key, value in ipairs(tArgs.args) do 
            if (key >= 3 and key <= (numArgs - 2)) then
                user = trim_user(value) or ""
                if user ~= "" then
                    ret[#ret + 1] = '*'
                    ret[#ret + 1] = i18n[reportType]
                    ret[#ret + 1] = ': <span class="plainlinks">' .. https
                    ret[#ret + 1] = wiki
                    ret[#ret + 1] = '.wikia.com/wiki/Special:Contributions/'
                    ret[#ret + 1] = user
                    ret[#ret + 1] = '</span>'
                    if (reportType == "spammer") then
                        ret[#ret + 1] = ' <span style="font-size:11px;">([[w:c:'
                        ret[#ret + 1] = wiki
                        ret[#ret + 1] = ':Special:DeletedContributions/'
                        ret[#ret + 1] = user
                        ret[#ret + 1] = '|DelContribs]])</span> '
                    end
                    -- add c/w links
                    if (crosswiki == "yes") then
                        ret[#ret + 1] = crosswikilinks(user, wiki, https)
                    end
                    ret[#ret + 1] = '\n'
                end
            end
        end
        if numArgs >= 20 then
            ret[#ret + 1] = '</div>\n'
        end
        if socks ~= "" then
            ret[#ret + 1] = "*''".. i18n["spmsg"] .. "''\n"
            for sock in string.gmatch(socks, '([^\n]+)') do
                sock = trim_user(sock) or ""
                ret[#ret + 1] = '**'
                ret[#ret + 1] = i18n["sock"]
                ret[#ret + 1] = ': [[w:c:'
                ret[#ret + 1] = wiki 
                ret[#ret + 1] = ':Special:Contributions/' .. sock 
                ret[#ret + 1] = '|' .. sock .. ']]'
                ret[#ret + 1] = crosswikilinks(sock, wiki, https)
                ret[#ret + 1] = '\n'
            end
        end
 
    end
    ret[#ret + 1] = '*' .. i18n["reason"] .. ': '
    ret[#ret + 1] = reason ..'\n'
    ret[#ret + 1] = '*' .. i18n["sig"] .. ': '
    ret[#ret + 1] = '-- [[User:'.. reporter ..'|' .. reporter .. ']] '
    ret[#ret + 1] = '([[User talk:'.. reporter .. '|' .. i18n["talk"] .. ']]) '
    ret[#ret + 1] = time .. '\n'
    ret[#ret + 1] = '</div>'
 
    return table.concat(ret)
end
 
function p.spam(frame)
    return createReport(frame, "spammer")
end
 
function p.vandalism(frame)
    return createReport(frame, "vandal")
end
 
function p.profile(frame)
    return createReport(frame, "profile")
end
 
function p.filter_problem(frame)
    return createReport(frame, "Phalanx")
end
 
return p
-- </nowiki>