Module:Disambiguation

local p = {}

function p.l_d (t) local div = mw.html.create( 'div' ) div :css( 'height', '150px' ) :css( 'overflow', 'hidden' ) :wikitext( t ) return tostring( div ) end

function p.d (frame) return p.l_d(frame.args[1]) end

function p.l_image(i,p) if i == nil or i == "No Image Available At All.png" then i = "No Image Available.png" end return '' 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_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 = string.sub(s_title, 3, j-1)                         else s = string.sub(s_title, i+1, j-1)                    end            end    end    if s_name ~= s_main_name        then             if s ~= nil and s ~= "" and s ~= s_main_title and s ~= s_main_name                then return ""..s.."("..s_name..") "                else return ""..s_name.." "            end        else             if s ~= nil and s ~= "" and s ~= s_main_title and s ~= s_main_name                then return ""..s.." " end end end

function p.image(frame) return p.l_image(frame.args[1], frame.args[2]) 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 k   local j       local s1    local s2    local s_pad local v   local i=1 local r2 = {}

while next(l,i) ~= nil do       v = l[i] i = i + 1 j = string.find(v,"*",1,true) s_page = string.sub(v, 1, j-1) j, k = string.find(s_page," (Earth-TRN",1,true)       if j == nil            then j, k = string.find(s_page," (Earth-",1,true) end s1 = string.sub(s_page, k+1, string.len(s_page)-1) s2 = string.sub(s_page, j+2, k)       s_pad = string.rep("0", 20-string.len(s1)) table.insert(r, s2..s_pad..s1..'*'..v)   end table.sort(r) i=1

while i <= #r do       v = r[i] j = string.find(v,"*",1,true) k = string.find(v,"*",j+1,true) s_page = string.sub(v, j+1, k-1) j = string.find(v,"*",k+1,true) s_image = p.l_d(p.l_image(string.sub(v, k+1, j-1), s_page)) --s_title = p.l_name(s_page, tostring(string.sub(v, j+1, string.len(v))), s_main_title, s_main_name) --j = string.find(s_page,"Earth-",1,true) --k = string.sub(s_page, j, string.len(s_page)-1) --s_reality = frame:expandTemplate{ title = 'Number to Name', args = { k } }..'('..k..')' s = ' '..s_image..' ' --s = ' '..s_image..s_title..s_reality..' ' if math.fmod(i, 5) == 0 then s = s..' ' end table.insert(r2, s)       i = i + 1 end return table.concat( r2 ) --return ' ' end

return p