Module:Disambiguation

local p = {}

function p.l_image(i) if i == nil or i == "No Image Available At All.png" then i = "No Image Available.png" end return i end

function p.l_name(s_page, s_title, s_main_title, s_main_name) local s = "" local i   local j

i = string.find(s_page,"(",1,true)   j = string.len(s_page)    s_name = string.sub(s_page, 1, i-2)    if s_name ~= s_main_name        then s = s..""..s_name.." "        else if s_title ~= nil and s_title ~= ""            then                 j = string.find(s_title, "]]",1,true)                if j ~= nil                     then                        i = string.find(s_title, "|",1,true)                        if i == nil                             then s_title = string.sub(s_title, 3, j-1)                             else s_title = string.sub(s_title, i+1, j-1)                        end                end                if s_title ~= s_main_title and s_title ~= s_main_name                    then s = s..""..s_title.." "                end            end        end

return s end

function p.image(frame) s_image = p.l_image(frame.args[1]) return '' --return ' ' end

function p.name(frame) return p.l_name(frame.args["page"], frame.args["title"], frame.args["main_title"], frame.args["main_name"]) end

function p.reality(frame) local s_page = frame.args[1] local i   local j    local s    i = string.find(s_page,"(",1,true)    j = string.len(s_page)    s = string.sub(s_page, i+1, j-1)	return frame:expandTemplate{ title = 'Number to Name', args = { s } }..'('..s..')' end

function p.box(frame) local s_page = frame.args["page"] local s_image = frame.args["image"] local s_title = tostring(frame.args["title"]) local s_main_title = frame.args["main_title"] local s_main_name = frame.args["main_name"] local s_name local s_reality local i   local j    local si    local sn = "" local sr   i = string.find(s_page,"(",1,true)    j = string.len(s_page)    s_reality = string.sub(s_page, i+1, j-1)    s_name = string.sub(s_page, 1, i-2)    sr = frame:expandTemplate{ title = 'Number to Name', args = { s_reality } }..'('..s_reality..')'    if s_image == nil or s_image == "No Image Available At All.png"        then s_image = "No Image Available.png"           end	si = '   '     if s_name ~= s_main_name        then sn = ""..s_name.." "        else if s_title ~= nil and s_title ~= ""            then                 j = string.find(s_title, "]]",1,true)                if j ~= nil                     then                        i = string.find(s_title, "|",1,true)                        if i == nil                             then s_title = string.sub(s_title, 3, j-1)                             else s_title = string.sub(s_title, i+1, j-1)                        end end if s_title ~= s_main_title and s_title ~= s_main_name then sn = ""..s_title.." " end end end

return si..sn..sr..' ' end

function p.sortlist(frame) local s = frame.args["list"] local s_main_title = frame.args["main_title"] local s_main_name = frame.args["main_name"] local s_page local s_image local s_title local s_name local s_reality local l = mw.text.split(s,"_",true) local r = {} local k1   local j1    local k2    local j2     local k    local j       local s1    local s2    local s_pad local v

--for i, v in ipairs( l ) do   v = l[2] j = string.find(v,"*",1,true) s_page = string.sub(v, 1, j-1) k = string.find(v,"*",j+1,true) s_image = p.l_image(string.sub(v, j+1, k-1)) s_title = tostring(string.sub(v, k+1, string.len(v))) j, k = string.find(s_page," (Earth-TRN",1,true)       if j == nil            then j, k = string.find(s_page," (Earth-",1,true) end s_name = string.sub(s_page, 1, j)       s_reality = string.sub(s_page, j+2, string.len(s_page)-1) s1 = string.sub(s_page, k+1, string.len(s_page)-1) s2 = string.sub(s_page, j, k)       s_pad = string.rep("0", 20)

table.insert(r, {s2..s_pad..s1, s_page, s_name, s_reality}) --end --table.sort(r)

--s = '' --for i, v in ipairs( r ) do   --    s = s..r[i]..', ' --end

return unpack(r, 1, 2)--s2..s_pad..s1, s_page, s_name, s_reality end

return p