FANDOM


local p = {}
local list_of_realities = mw.loadData( 'Module:Disambiguation/Realities' )
local h = require("Module:HF")
 
 
function p.CauseOfDeath(frame)
    local killed = frame.args[1]
    local casualty = frame.args[2]
    local suicide = frame.args[3]
    local sacrifice = frame.args[4]
    local link = ''
    local text = ''
    local output = {}
    local s = ''
    local t = {}
 
    if h.isempty( killed ) == false
        then
            t = {}
            killed = h.explode( ";", killed )
            for i = 1,#killed do
                link = h.lua_breaklink(killed[i], 1)
                text = h.lua_breaklink(killed[i], 2)
                s = h.Link( link, text )..'[[Category:Killed by '..link..']]'
                table.insert(t, s)
            end
            table.insert(output, 'Killed by '..mw.text.listToText(t) )
    end
 
    if h.isempty( casualty ) == false
        then
            t = {}
            casualty = h.explode( ";", casualty )
            for i = 1,#casualty do
                link = h.lua_breaklink(casualty[i], 1)
                text = h.lua_breaklink(casualty[i], 2)
                s = h.Link( link, text )..'[[Category:'..link..' casualties]]' 
                table.insert(t, s)
            end
            if h.isempty( output ) == false
                then s = 'casualty of '
                else s = 'Casualty of '
            end
            table.insert(output, s..mw.text.listToText(t) )
    end
 
    if h.isempty( suicide ) == false
        then 
            if h.isempty( output ) == false
                then s = 'suicide'
                else s = 'Suicide'
            end
            table.insert(output, s..'[[Category:'..'Suicide'..']]')
    end
 
    if h.isempty( sacrifice ) == false
        then 
            if h.isempty( output ) == false
                then s = 'self-sacrifice'
                else s = 'Self-sacrifice'
            end
            table.insert(output, s)
    end
 
    return mw.text.listToText( output, ';', '; ')
end
 
function p.test (pagename, realname, currentalias, main_version)
    local r
    local t1
    local t2
    local k
    local j
    local reality
    local s_page
    local page_s = string.reverse(pagename)
    realname = h.lua_breaklink(realname, 1)
    currentalias = h.lua_breaklink(currentalias, 1)
 
    j = string.find(page_s,"( ",1,true)
    k = string.find(page_s, ")",1,true)
    if j ~= nil and k ~= nil
        then 
            reality = string.reverse(string.sub(page_s, k+1, j-1 ) )
            s_page  = string.reverse(string.sub(page_s, j+2, #page_s) )
    end
 
    if h.isempty(s_page) == false and mw.title.new(s_page..' (Earth-616)/Powers').exists == true
        then 
            r = 1
        elseif h.isempty( h.lua_redirectTarget(currentalias) ) == false 
            then
                t1 = p.lua_get_main_from_disambig(currentalias)
                if h.isempty( t1 ) == false 
                    then
                        r = 2
                end
            elseif h.isempty( h.lua_redirectTarget(realname) ) == false 
                then
                    t1 = p.lua_get_main_from_disambig(realname)
                    if h.isempty( t1 ) == false 
                        then
                            r = 3
                    end
    end
 
    return r --reality.."__"..s_page.."__"
end
 
 
function p.lua_get_main_from_disambig(pagename)
    local s = ''
    local r = ''
    local i = nil
    if h.isempty(pagename) == false
        then
            s = mw.title.new(pagename)
            if s.exists == true 
                then
                    s = s:getContent()
                    i = string.find(s, 'DisambiguationFull')
                    if h.isempty(i) == false
                        then r = mw.text.trim( mw.ustring.gsub(s, ".+|main%s+=%s+(.-)\n.+", "%1") )
                    end
            end
    end
    return r
end
 
 
function p.test20()
    local s = 'TRN7'
    local s2 = 'test (TRN756)'
 
    if string.match(s, '^TRN%d+') ~= nil
        then s = 's ~= nil'
        else s = 's == nil'
    end
    if string.match(s2, '^TRN%d+') ~= nil
        then s2 = 's2 ~= nil'
        else s2 = 's2 == nil'
    end
 
    return s..s2
end
 
-- used in Template:Disambiguation Text
function p.disambiguation_text(frame)
    local s = frame.args[1]
    local reality = ''
    local link
    local text
    local comment = ''
    local i
    local output = ''
 
    if not h.isempty(s)
        then
            s = h.explode(';', s)
            if tonumber(s[1]) ~= nil or string.match(s[1], '^TRN%d+') ~= nil or list_of_realities[s[1]] ~= nil
                then
                    reality = { p.lua_reality(s[1]) }
                    output = reality[1]..'<br>('..h.Link(reality[2])..')'
                else
                    if h.lua_isLink(s[1])
                        then
                            i = string.find(s[1], ']]', 1, true)
                            link = h.lua_breaklink(s[1],1)
                            text = h.lua_breaklink(s[1],2)
                            if #s[1] > i+2
                                then comment = string.sub(s[1], i+2, #s[1])
                            end
                            if not h.isempty( string.find(link, '(',1,true) )
                                then 
                                    reality = { p.lua_reality(link, true) }
                                    reality = '<br>'..reality[1]..'<br>('..h.Link(reality[2])..')'
                            end 
                        else
                            link = s[1]
                            text = s[1]
                    end
                    output = tostring( mw.html.create( 'span' )
                                :css( 'font-weight', 'bold' )
                                :wikitext( h.Link(link,text)..comment )
                                :done() )..reality
            end
    end
 
    return output
end
 
 
function p.lua_include(list,redlinks)
    local l = mw.text.split(list,"@",true)
    local i
    local v
    local j
    local k
    local s_page
    local s_title
    local s_image
    local page_s
    local s=""
 
    i = 1
    while next(l,i) ~= nil do
        v = l[i]
        i = i + 1
        s_page = ""
        s_title = ""
        s_image = ""
        page_s = ""
        j = string.find(v,";",1,true)
        if j ~= nil
            then 
                s_image = mw.text.trim(string.sub(v,j+1,#v))
                s_page = string.sub(v,1,j-1)
            else 
                s_page = v
        end
        s_title = h.lua_breaklink(s_page,2)        
        s_page = h.lua_breaklink(s_page,1)
        page_s = string.reverse(s_page)
        j = string.find(page_s,"( ",1,true)
        if j ~= nil and s_title == s_page
            then s_title = string.reverse(string.sub(page_s, j+2, #page_s))
        end
        if redlinks == true
            then s = s..s_page.."~"..s_image.."~ "..s_title.."@"
            else s = s..s_page.."~"..s_image.."~"..s_title.."@"
        end
    end
    return s
end
 
function p.include (frame)
    return p.lua_include(frame.args[1])
end
 
function p.lua_reality(r, e)
    local j
    local k
    local s
    local s1
    local s2
    local s3
 
    if e == true or e == "true"
        then 
            s1 = string.reverse(r)
            s2 = string.find(s1, "( ",1,true) or string.find(s1, "(_",1,true)
            s3 = string.find(s1, ")",1,true)
            r = string.reverse(string.sub(s1, s3+1, s2-1))
    end
 
    j,k = string.find(string.lower( r ),"earth-",1,true)
    if j ~= nil
        then s = string.sub(r,k+1,string.len(r))
        else s = r
    end
    s2 = list_of_realities[s]
    if s2 ~= nil
        then return s2[1], s2[2], s2[3]
        elseif tonumber(r) ~= nil or string.match(r, '^TRN%d+') ~= nil
            then return "Earth-"..r, "Earth-"..r, "Comic"
            else return r, r, "Comic"   
    end
end
 
function p.reality (frame)
    local r = h.lua_breaklink(frame.args[1], 1)
    local i = tonumber(frame.args[2])
    local e = frame.args[3] or frame.args["extract"]
    local s1
    local s2
    local s3
 
    s1, s2, s3 = p.lua_reality(r, e)
    if i == 3
        then return s3
        elseif i == 2 
            then return s2
            else return s1
    end
end
 
function p.lua_image(i,p,noimage)
    if h.isempty(i) == true or i == "No Image Available At All.png"
        then
            if h.isempty(noimage) == false
                then i = noimage
                else i = "No Image Available.png"
            end
    end
    return '[[File:'..i..'|150px|link='..p..']]'
end
 
function p.image(frame)
	return p.lua_image(frame.args[1], frame.args[2])
end
 
function p.lua_name(s_page, s_title, s_main_title, s_main_name, others)
    local s = ""
    local i
    local j
    local s_name = ""
    local page_s = string.reverse(s_page)
 
    if others == true
        then s = "<b>[["..s_page.."|"..s_title.."]]</b><br>"
        else
            i = string.find(page_s,"( ",1,true)
            s_name = string.reverse( string.sub(page_s, i+2, #page_s) )
            if h.isempty(s_title) == false
                then 
                    s_title = h.lua_breaklink (s_title, 2)
                    if h.inlist({s_main_title, s_main_name}, s_title) == false
                        then
                            s_title = mw.text.trim(s_title)
                            if h.inlist({s_main_title, s_main_name, s_title}, s_name) == false
                                then s = "<b>[["..s_page.."|"..s_title.."<br>("..s_name..")]]</b><br>"
                                else s = "<b>[["..s_page.."|"..s_title.."]]</b><br>"
                            end
                        elseif h.inlist({s_main_title, s_main_name}, s_name) == false
                            then s = "<b>[["..s_page.."|"..s_name.."]]</b><br>"
                    end
                elseif s_name ~= s_main_name and s_name ~= s_main_title
                    then s = "<b>[["..s_page.."|"..s_name.."]]</b><br>"
            end
    end    
    return s
end
 
function p.name(frame)
    local s_page = frame.args["page"] or frame.args[1]
    s_page = h.lua_breaklink(s_page, 1)
    local i = string.find(s_page," (",1,true)
    local s_name 
    if i == nil 
        then s_name = s_page
        else s_name = string.sub(s_page, 1, i-1)
    end
    local s_title = frame.args["title"] or s_name
    local s_main_title = frame.args["main_title"] or s_title
    local s_main_name = frame.args["main_name"] or s_name
    local s_others = frame.args["others"] or true
	return p.lua_name(s_page, s_title, s_main_title, s_main_name, s_others)
end
 
function p.lua_box(v, s_main_title, s_main_name, others, noimage)
    local s_page
    local s_image
    local s_title
    local s_reality = ""
    local part
    local j
    local k
    local s = ""
    local page_s
    local s1
    local s2
    local s_pad
    local desc
    local earth
    local ttype
 
    part = string.find(v,"~",1,true)
    s_page = string.sub(v, 1, part-1)
    page_s = string.reverse(s_page)
    j = string.find(page_s,"( ",1,true)
    k = string.find(page_s, ")",1,true)
    if j ~= nil and k ~= nil
        then s_reality = string.reverse(string.sub(page_s, k+1, j-1 ) )
    end
    j, k = string.find(s_page,"Earth-TRN",1,true)
    if j ~= nil 
        then
            s1 = string.sub(s_page, k+1, string.len(s_page)-1)
            s_pad = string.rep("0", 20-string.len(s1)-string.len("Earth-TRN"))
            s = "Earth-TRN"..s_pad..s1
        else
            j, k = string.find(s_page,"Earth-",1,true)
            if j ~= nil
                then 
                    s1 = string.sub(s_page, k+1, string.len(s_page)-1)
                    s_pad = string.rep("0", 20-string.len(s1)-string.len("Earth-"))
                    s = "Earth-"..s_pad..s1
                else s = s_reality
            end
    end
    j = string.find(v,"~",part+1,true)       
    s_image = '<td><div style="width: 150px;"><div style="height: 150px; overflow: hidden">'..p.lua_image(string.sub(v, part+1, j-1), s_page, noimage)..'</div>'
    s_title = p.lua_name(s_page, tostring(string.sub(v, j+1, string.len(v))), s_main_title, s_main_name,others)
    if h.isempty(s_reality) == false
        then
            desc,earth,ttype = p.lua_reality(s_reality, false)
            if desc ~= "" and earth ~= "" and desc == earth 
                then s_reality = '<br>([['..earth..']])'
                else s_reality = desc..'<br>([['..earth..']])'
            end
        end
    s = s..'~'..s_image..s_title..s_reality..'</div></td>'
    return s, ttype
end
 
function p.lua_table(t, header)
    local i = 1
    local s = ""
    local v
    if #t ~= 0 then
        s = '<h2><center>'..header..'</center></h2><table align="center" style="text-align: center;"><tr valign="top">'
        --for i,v in ipairs(t) do
        while i <= #t do
            v = t[i]
            s = s..string.sub(v, string.find(v,"~",1,true)+1, string.len(v))
            if  math.fmod(i, 4) == 0 then s = s..'</tr><tr valign="top">' end
            i = i + 1
        end
        s = s..'</tr></table><br>'
    end
    return s
end
 
function p.disambiguation(frame)
    local l = frame.args["list"]
    local s_main_title = frame.args["main_title"]  
    local s_main_name = frame.args["main_name"]
    local s_include = frame.args["include"]
    local s_noimage = frame.args["noimage"]
    local headers = { "Alternate Reality Versions", "Movies", "Television", "Video Games", "Others", "Related", "Teams", frame.args["header1"], frame.args["header2"], frame.args["header3"], frame.args["header4"], frame.args["header5"] }
    local sections = { "", "", "", "", frame.args["others"], frame.args["related"], frame.args["teams"], frame.args["section1"], frame.args["section2"], frame.args["section3"], frame.args["section4"], frame.args["section5"] }
    local tables = { {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {} }
    local strings= { "", "", "", "", "", "", "", "", "", "", "", "" }
    local includes= { frame.args["includeComic"], frame.args["includeMovie"], frame.args["includeTV"], frame.args["includeGame"] }
    local s
    local v
    local i
    local j
    local ttype
    local d = ""
 
    l = mw.ustring.gsub(l,"&#x20;","")
    if h.isempty(s_include) == false
        then l = l..p.lua_include(s_include,true)
    end
    l = mw.text.split(l,"@",true)
    i = 1
    while next(l,i) ~= nil do
        v = l[i]
        i = i + 1
        s, ttype = p.lua_box(v, s_main_title, s_main_name, false, s_noimage)
        if ttype == "Game"
            then table.insert(tables[4], s)
            elseif ttype == "TV" then table.insert(tables[3], s)
            elseif ttype == "Movie" then table.insert(tables[2], s)
            else table.insert(tables[1], s)
        end
    end
    for j=1,4 do
        if h.isempty(includes[j]) == false
            then
                l = p.lua_include(includes[j])
                l = mw.text.split(l,"@",true)
                i = 1
                while next(l,i) ~= nil do
                    v = l[i]
                    i = i + 1
                    s = p.lua_box(v, s_main_title, s_main_name, false, s_noimage)
                    table.insert(tables[j], s)
                end
        end
    end
    for j=1,4 do
        table.sort(tables[j])
        strings[j] = p.lua_table(tables[j], headers[j])
    end
 
    for j=5,12 do
        if h.isempty(sections[j]) == false
            then 
                l = mw.text.split(p.lua_include(sections[j]),"@",true)
                i = 1
                while next(l,i) ~= nil do
                    v = l[i]
                    i = i + 1
                    s = p.lua_box(v, s_main_title, s_main_name, true, s_noimage)
                    table.insert(tables[j], s)
                end
                strings[j] = p.lua_table(tables[j], headers[j])
        end
    end    
 
    s = frame:preprocess( "{{FULLPAGENAME}}" ) 
    d = d.."[["..s.."#Alternate Reality Versions|Alternate Reality Versions]]"
    if h.isempty(s_main_title) == false and mw.title.new(s_main_title.." Comic Books").exists == true
        then d = d.."&nbsp;'''·'''&nbsp;[["..s_main_title.." Comic Books|Comics]]"
        elseif h.isempty(s_main_name) == false and mw.title.new(s_main_name.." Comic Books").exists == true
            then d = d.."&nbsp;'''·'''&nbsp;[["..s_main_name.." Comic Books|Comics]]"
    end
    for j=2,7 do
        if strings[j] ~= ""
            then d = d.."&nbsp;'''·'''&nbsp;[["..s.."#"..headers[j].."|"..headers[j].."]]"
        end
    end
    d = '<table align="center" style="width: 100%; text-align: center;" frame="hsides"><td>'..d..'</td></table>'
    return d,table.concat(strings)
end
 
return p
*Nota: Alcuni dei link qui sopra sono link affiliati, ciò significa che, senza costi aggiuntivi, Fandom riceverà una commissione nel caso tu decidessi di cliccare e fare un acquisto. I contenuti della comunità sono disponibili sotto la licenza CC-BY-SA a meno che non sia diversamente specificato.

Alcuni dei link qui sono link affiliati, ciò significa che, senza costi aggiuntivi, Fandom riceverà una commissione nel caso tu decidessi di cliccare e fare un acquisto.

Stream the best stories.

Alcuni dei link qui sono link affiliati, ciò significa che, senza costi aggiuntivi, Fandom riceverà una commissione nel caso tu decidessi di cliccare e fare un acquisto.

Get Disney+