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,
     Template:Report filter and Template:Badwiki.
 
--]]
--------------------------------------------------------------------------
 
local Report = {}
local fallback = require('Dev:Fallback')
local switch = require('Module:Report/i18n')
local getArgs = require('Dev:Arguments').getArgs
local wikialang = require('Module:Report/wikialang')
 
-- remove excess or wrongly entered content
local function trim(s)
    s = s:match( "^%s*(.-)%s*$" )
    return s
end
 
local function trimURL(s)
    s = s:match( "^%s*(.-)%s*$" )
    s = s:gsub("http:%/%/","")
    s = s:gsub("https:%/%/","")
    s = s:gsub("%/+$", "/")
    return s
end
 
local function trim_wiki(s)
    s = s:match( "^%s*(.-)%s*$" )
    s = s:gsub("http:%/%/","")
    s = s:gsub("https:%/%/","")
    s = s:gsub("%.wikia%.com.*", "")
    s = s:gsub("%.fandom%.com.*", "")
    return s
end
 
local 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("^.*%.fandom%.com%/wiki%/","")
    s = s:gsub("^.*%.fandom%.com%/","")
    s = s:gsub(" ","_")
    return s
end
 
local 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("^.*%.fandom%.com%/wiki%/","")
    s = s:gsub("^.*%.fandom%.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
 
local function trim_reason(s)
    s = s:match( "^%s*(.-)%s*$" )
    s = s:gsub( "\\\\", "|" )
    return s
end
 
local function trim_id(s)
    s = s:match( "^%s*(.-)%s*$" )
    s = s:gsub("#","")
    return s
end
 
local 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)
local 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 Report._badWiki(args)
    local wiki = args[1] or 'WIKI'
    local reason = args[2] or 'spam'
    local domain = args[3] or nil
 
    -- es.community, fandom
    if domain then
        if not domain == 'wikia' and not domain == 'fandom' then
            domain = 'wikia'
        end
        wiki, lang = Report._splitWikiFromPartial(wiki)
    -- es.community.wikia.com or community.fandom.com/es
    elseif string.match(wiki, 'wikia%.com') or string.match(wiki, 'fandom%.com') then
        wiki, domain, lang = Report._splitWikiFromURL(wiki)
    -- es.community
    else
        wiki, lang = Report._splitWikiFromPartial(wiki)
        domain = 'wikia'
    end
 
    local langAndWiki = wiki
    if lang ~= '' then
        langAndWiki = lang .. '.' .. wiki
    end
    local ret = mw.html.create('span'):attr('class', 'plainlinks')
        :tag('span'):attr('class', 'closeme')
            :wikitext('[https://community.wikia.com/wiki/Special:WikiFactory/' .. langAndWiki .. '/close <small>close me</small>] ')
            :done()
        :wikitext('[' .. Report._getWikiURL(wiki, domain, lang) .. ' ' .. langAndWiki .. ' Wiki] ')
        :tag('code')
            :wikitext('reason: ')
            :tag('span'):attr('class', 'QuickReason')
                :wikitext(reason)
                :done()
            :done()
        :done()
 
    return tostring(ret)
end
 
-- Splits wiki, domain and language from a full URL
-- example: http://community.fandom.com/es/
function Report._splitWikiFromURL(url)
    url = trimURL(url) .. '/'
 
    -- try wikia.com parse
    local domain = 'wikia'
    local res, _, lang, wikiname = string.find(url, '([^%.]-)%.*([^%.]*)%.wikia%.com.*')
    -- try fandom.com parse
    if not res then
        domain = 'fandom'
        res, _, wikiname, lang = string.find(url, '([^%.]-)%.fandom%.com%/*([^%/]*)%/*.*')
    end
    -- revert to whatever was provided
    if not res then
        domain = 'wikia'
        wikiname = url
    end
    if lang ~= '' and not wikialang[lang] then
        lang = ''
    end
    return wikiname, domain, lang
end
 
-- Splits wiki, domain and language from a standard entry
-- example: es.community, fandom
function Report._splitWikiFromPartial(wiki)
    local res, _, lang, wikiname = string.find(wiki, '([^%.]-)%.*([^%.]-)$')
    if not res then
        lang = ''
        wikiname = wiki
    end
    if lang ~= '' and not wikialang[lang] then
        lang = ''
    end
    return wikiname, lang
end
 
-- Returns a wiki URL based on domain and language
function Report._getWikiURL(wiki, domain, lang)
    if domain == 'fandom' then
        if lang == '' then
            return 'https://' .. wiki .. '.fandom.com/'
        else
            return 'https://' .. wiki .. '.fandom.com/' .. lang .. '/'
        end
    else
        if lang == '' then
            return 'https://' .. wiki .. '.wikia.com/'
        else
            return 'http://' .. lang .. '.' .. wiki .. '.wikia.com/'
        end
    end
end
 
function Report.spam(frame)
    return createReport(frame, "spammer")
end
 
function Report.vandalism(frame)
    return createReport(frame, "vandal")
end
 
function Report.profile(frame)
    return createReport(frame, "profile")
end
 
function Report.filter_problem(frame)
    return createReport(frame, "Phalanx")
end
 
function Report.badWiki(frame)
    local args = getArgs(frame)
    return Report._badWiki(args)
end
 
return Report
-- </nowiki>