Marvel Database
No edit summary
m (Protected "Module:Disambiguation" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)))
(43 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
local list_of_realities = mw.loadData( 'Module:Disambiguation/Realities' )
 
local list_of_realities = mw.loadData( 'Module:Disambiguation/Realities' )
 
local h = require("Module:HF")
 
local h = require("Module:HF")
  +
local pagetype = require("Module:PageType")
  +
local design = require("Module:Design")
  +
local module_reality = require("Module:Reality")
  +
local getArgs = require('Module:Arguments').getArgs
   
   
  +
-- main function used to create entire disambiguation page
function p.CauseOfDeath(frame)
 
  +
function p.disambiguation(frame)
local killed = frame.args[1]
 
local casualty = frame.args[2]
+
local args = getArgs (frame)
  +
local g_type
local suicide = frame.args[3]
 
local sacrifice = frame.args[4]
+
local g_main_name = args['main_name']
  +
local g_main_character = args['Main Character'] or ''
local link = ''
 
  +
local g_main_image_size = args['Main Image Size'] or '250px'
local text = ''
 
local output = {}
+
local g_main_version
local s = ''
+
local g_main_title
local t = {}
+
local g_main_image
  +
local g_no_image
 
  +
local g_logo = args['logo'] or ''
if h.isempty( killed ) == false
 
  +
local g_description = args['description'] or ''
then
 
  +
local g_alternative_names = {}
t = {}
 
  +
local g_include = {}
killed = h.explode( ";", killed )
 
  +
local g_exclude = {}
for i = 1,#killed do
 
  +
local g_includeComic = {}
link = h.lua_breaklink(killed[i], 1)
 
  +
local g_includeMovie = {}
text = h.lua_breaklink(killed[i], 2)
 
  +
local g_includeTV = {}
s = h.Link( link, text )..'[[Category:Killed by '..link..']]'
 
  +
local g_includeGame = {}
table.insert(t, s)
 
  +
local g_teams = {}
end
 
  +
local g_others = {}
table.insert(output, 'Killed by '..mw.text.listToText(t) )
 
  +
local g_related = {}
end
 
  +
local g_new_text = { {}, {}, {}, {}, {}, {}, {}, {}, {} }
 
  +
local g_page = mw.title.getCurrentTitle()
if h.isempty( casualty ) == false
 
  +
local g_pagename = g_page.text
then
 
  +
t = {}
 
  +
local list = ''
casualty = h.explode( ";", casualty )
 
  +
local all_versions = {}
for i = 1,#casualty do
 
  +
local comics = {}
link = h.lua_breaklink(casualty[i], 1)
 
  +
local movies = {}
text = h.lua_breaklink(casualty[i], 2)
 
  +
local tv = {}
s = h.Link( link, text )..'[[Category:'..link..' casualties]]'
 
  +
local games = {}
table.insert(t, s)
 
  +
local headers1 = { 'Alternate Reality Versions', 'Movies', 'Television', 'Video Games' }
end
 
  +
local headers2 = { 'Others', g_pagename..' Related', 'Teams' }
if h.isempty( output ) == false
 
  +
local tables = {}
then s = 'casualty of '
 
  +
local s = ''
else s = 'Casualty of '
 
  +
local s1 = ''
end
 
  +
local s2 = ''
table.insert(output, s..mw.text.listToText(t) )
 
  +
local output = {}
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
 
   
  +
table.insert(output, '__NOTOC__')
function p.test (pagename, realname, currentalias, main_version)
 
  +
table.insert(output, g_logo)
local r
 
  +
-- if 'main_name' parameter is not empty, then use DPL to create a list of alternate versions
local t1
 
  +
if not h.isempty(g_main_name)
local t2
 
  +
then
local k
 
  +
g_main_version = args['main']
local j
 
  +
g_main_title = args['main_title'] or g_main_name
local reality
 
  +
g_main_image = args['main_image']
local s_page
 
  +
table.insert(output, p.createBox_MainVersion({pagename = g_main_version,
local page_s = string.reverse(pagename)
 
  +
image = g_main_image,
realname = h.lua_breaklink(realname, 1)
 
  +
imageSize = g_main_image_size,
currentalias = h.lua_breaklink(currentalias, 1)
 
  +
description = g_description
  +
})
  +
)
   
  +
g_type = args['type'] or pagetype.get_page_type(g_main_version)
j = string.find(page_s,"( ",1,true)
 
  +
g_noimage = args['noimage']
k = string.find(page_s, ")",1,true)
 
  +
for i = 1,100 do
if j ~= nil and k ~= nil
 
  +
if not h.isempty(args['alternative'..i])
then
 
  +
then table.insert(g_alternative_names, args['alternative'..i])
reality = string.reverse(string.sub(page_s, k+1, j-1 ) )
 
  +
end
s_page = string.reverse(string.sub(page_s, j+2, #page_s) )
 
  +
if not h.isempty(args['include'..i])
end
 
  +
then table.insert(g_include, args['include'..i])
 
  +
end
if h.isempty(s_page) == false and mw.title.new(s_page..' (Earth-616)/Powers').exists == true
 
  +
if not h.isempty(args['includeComic'..i])
then
 
  +
then table.insert(g_includeComic, args['includeComic'..i])
r = 1
 
  +
end
elseif h.isempty( h.lua_redirectTarget(currentalias) ) == false
 
  +
if not h.isempty(args['includeMovie'..i])
then
 
  +
then table.insert(g_includeMovie, args['includeMovie'..i])
t1 = p.lua_get_main_from_disambig(currentalias)
 
  +
end
if h.isempty( t1 ) == false
 
  +
if not h.isempty(args['includeTV'..i])
then
 
  +
then table.insert(g_includeTV, args['includeTV'..i])
r = 2
 
  +
end
end
 
  +
if not h.isempty(args['includeGame'..i])
elseif h.isempty( h.lua_redirectTarget(realname) ) == false
 
  +
then table.insert(g_includeGame, args['includeGame'..i])
then
 
  +
end
t1 = p.lua_get_main_from_disambig(realname)
 
  +
if not h.isempty(args['exclude'..i])
if h.isempty( t1 ) == false
 
  +
then table.insert(g_exclude, args['exclude'..i])
then
 
  +
end
r = 3
 
  +
end
end
 
  +
list = frame:preprocess( p.lua_dpl_list(g_main_name, g_main_version, g_type, g_alternative_names, g_exclude, 500)..p.lua_dpl_list(g_main_name, g_main_version, g_type, g_alternative_names, g_exclude, 500, 500) )
end
 
  +
list = string.gsub(list, ' ', '')
  +
list = h.explode('@', list)
  +
  +
for i = 1, #list do
  +
s = mw.text.split(list[i], '~') --h.explode('~', list[i])
  +
s1, s2 = module_reality.lua_get_name_and_reality(s[1])
  +
table.insert( all_versions, { ['page'] = s[1], ['image'] = s[2], ['title'] = s[3], ['name'] = s1, ['reality'] = s2 } )
  +
end
  +
all_versions = h.join_tables(all_versions, p.lua_transform_from_old_format(g_include, true))
   
  +
for i = 1, #all_versions do
return r --reality.."__"..s_page.."__"
 
  +
s = all_versions[i].reality.type
end
 
  +
if s == 'Game'
  +
then table.insert(games, all_versions[i])
  +
elseif s == "TV"
  +
then table.insert(tv, all_versions[i])
  +
elseif s == "Movie"
  +
then table.insert(movies, all_versions[i])
  +
else table.insert(comics, all_versions[i])
  +
end
  +
end
  +
  +
comics = h.join_tables(comics, p.lua_transform_from_old_format(g_includeComic, false))
  +
movies = h.join_tables(movies, p.lua_transform_from_old_format(g_includeMovie, false))
  +
tv = h.join_tables(tv, p.lua_transform_from_old_format(g_includeTV, false))
  +
games = h.join_tables(games, p.lua_transform_from_old_format(g_includeGame, false))
   
  +
tables = { comics, movies, tv, games }
  +
table.insert( output, p.lua_createTOC(tables, headers1, g_pagename, g_main_title) )
  +
for i = 1,4 do
  +
table.insert(output, p.createSection({
  +
s_table = tables[i],
  +
header = headers1[i],
  +
main_name = g_main_name,
  +
main_title = g_main_title,
  +
disambiguation_pagename = g_pagename,
  +
noimage = g_noimage,
  +
old_format = false
  +
}) )
  +
end
  +
elseif not h.isempty(g_main_character)
  +
then
  +
g_main_character = mw.text.split(h.trim(g_main_character), ';', true)
  +
table.insert(output, p.createBox_MainVersion({
  +
pagename = h.break_link(g_main_character[1], 1),
  +
text = h.break_link(g_main_character[1], 2),
  +
image = h.trim(g_main_character[2]) or 'No Image Available.png',
  +
imageSize = g_main_image_size,
  +
description = g_description
  +
})
  +
)
  +
end
   
  +
for i = 1,9 do
function p.lua_get_main_from_disambig(pagename)
 
  +
table.insert(headers2, args['New Header'..i] or '')
local s = ''
 
  +
end
local r = ''
 
  +
local i = nil
 
  +
for i = 1,200 do
if h.isempty(pagename) == false
 
  +
table.insert(g_teams, args['Teams'..i])
then
 
  +
table.insert(g_others, args['Others'..i])
s = mw.title.new(pagename)
 
  +
table.insert(g_related, args['Related'..i])
if s.exists == true
 
  +
for j = 1,9 do
then
 
  +
table.insert(g_new_text[j], args['New Header'..j..'_'..i])
s = s:getContent()
 
  +
end
i = string.find(s, 'DisambiguationFull')
 
  +
end
if h.isempty(i) == false
 
  +
g_teams = p.lua_transform_from_old_format(g_teams, false)
then r = mw.text.trim( mw.ustring.gsub(s, ".+|main%s+=%s+(.-)\n.+", "%1") )
 
  +
g_others = p.lua_transform_from_old_format(g_others, false)
end
 
  +
g_related = p.lua_transform_from_old_format(g_related, false)
end
 
  +
end
 
  +
for j = 1,9 do
return r
 
  +
g_new_text[j] = p.lua_transform_from_old_format(g_new_text[j], false)
  +
end
  +
  +
tables = { g_others, g_related, g_teams,
  +
g_new_text[1], g_new_text[2], g_new_text[3], g_new_text[4], g_new_text[5],
  +
g_new_text[6], g_new_text[7], g_new_text[8], g_new_text[9]}
  +
  +
for i = 1,#tables do
  +
table.insert(output, p.createSection({
  +
s_table = tables[i],
  +
header = headers2[i],
  +
main_name = g_main_name,
  +
main_title = g_main_title,
  +
disambiguation_pagename = g_pagename,
  +
noimage = g_noimage,
  +
old_format = true
  +
}) )
  +
end
  +
  +
--return '<div valign="top">'..table.concat(output)..'</div>'
  +
return frame:preprocess( table.concat(output) )
 
end
 
end
   
   
function p.test20()
+
function p.lua_sort_by_reality(a, b)
local s = 'TRN7'
+
local reality1 = a.reality.number
local s2 = 'test (TRN756)'
+
local reality2 = b.reality.number
  +
local earth33 = {'33 1/3', '33⅓'}
 
  +
local output
if string.match(s, '^TRN%d+') ~= nil
 
  +
then s = 's ~= nil'
 
  +
if h.isempty(reality1) or h.isempty(reality2)
else s = 's == nil'
 
  +
then output = false
end
 
  +
else
if string.match(s2, '^TRN%d+') ~= nil
 
  +
if h.in_list(earth33, reality1)
then s2 = 's2 ~= nil'
 
  +
then reality1 = 33.3
else s2 = 's2 == nil'
 
end
+
end
  +
if h.in_list(earth33, reality2)
 
  +
then reality2 = 33.3
return s..s2
 
  +
end
  +
if tonumber(reality1) ~= nil
  +
then
  +
if tonumber(reality2) ~= nil
  +
then output = tonumber(reality1)<tonumber(reality2)
  +
else output = true
  +
end
  +
elseif tonumber(reality2) ~= nil
  +
then output = false
  +
else output = reality1<reality2
  +
end
  +
end
  +
  +
return output
 
end
 
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 = ''
 
   
  +
function p.lua_dpl_list(main_name, main_version, main_version_type, alternative_names, exclude, count, offset)
if not h.isempty(s)
 
  +
local template = '{Marvel Database:'..main_version_type..' Template}'
then
 
  +
local image = template..':Image, '
s = h.explode(';', s)
 
  +
local title = ''
if tonumber(s[1]) ~= nil or string.match(s[1], '^TRN%d+') ~= nil or list_of_realities[s[1]] ~= nil
 
  +
local s = ''
then
 
  +
local output = {}
reality = { p.lua_reality(s[1]) }
 
  +
output = reality[1]..'<br>('..h.Link(reality[2])..')'
 
  +
if not h.isempty(alternative_names)
else
 
  +
then alternative_names = mw.text.listToText(alternative_names, '%¦', '%¦')..'%'
if h.lua_isLink(s[1])
 
  +
else alternative_names = ''
then
 
  +
end
i = string.find(s[1], ']]', 1, true)
 
  +
if not h.isempty(exclude)
link = h.lua_breaklink(s[1],1)
 
  +
then exclude = mw.text.listToText(exclude, '%¦', '%¦')..'%'
text = h.lua_breaklink(s[1],2)
 
  +
else exclude = ''
if #s[1] > i+2
 
  +
end
then comment = string.sub(s[1], i+2, #s[1])
 
  +
end
 
  +
main_version_type = string.lower(main_version_type)
if not h.isempty( string.find(link, '(',1,true) )
 
  +
if main_version_type == 'character' or main_version_type == 'characters'
then
 
  +
then title = template..':CurrentAlias'
reality = { p.lua_reality(link, true) }
 
  +
else title = template..':OfficialName'
reality = '<br>'..reality[1]..'<br>('..h.Link(reality[2])..')'
 
  +
end
end
 
  +
else
 
  +
table.insert(output, '{{#dpl:')
link = s[1]
 
  +
table.insert(output, '|category = '..main_version_type..'s')
text = s[1]
 
  +
table.insert(output, '|namespace = ')
end
 
  +
table.insert(output, '|titlematch = '..main_name..' (%¦'..alternative_names)
output = tostring( mw.html.create( 'span' )
 
  +
table.insert(output, '|nottitlematch = '..main_version..'¦'..exclude)
:css( 'font-weight', 'bold' )
 
  +
table.insert(output, '|include = '..image..title)
:wikitext( h.Link(link,text)..comment )
 
  +
table.insert(output, '|mode = userformat')
:done() )..reality
 
  +
table.insert(output, '|secseparators = %PAGE%~,~,,@')
end
 
  +
table.insert(output, '|noresultsheader = &#x20;')
end
 
  +
--table.insert(output, '|eliminate = templates')
 
  +
table.insert(output, '|allowcachedresults = true')
return output
 
  +
if not h.isempty(count)
  +
then table.insert(output, '|count ='..count)
  +
end
  +
if not h.isempty(offset)
  +
then table.insert(output, '|offset ='..offset)
  +
end
  +
table.insert(output, '}}')
  +
  +
return table.concat(output)
 
end
 
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=""
 
   
  +
-- transform string in 'page; image' format into table
i = 1
 
  +
function p.lua_transform_from_old_format(list, redlinks)
while next(l,i) ~= nil do
 
  +
local i
v = l[i]
 
  +
local s_page = ''
i = i + 1
 
  +
local s_title = ''
s_page = ""
 
  +
local s_image = ''
s_title = ""
 
  +
local s_reality = ''
s_image = ""
 
  +
local s_name = ''
page_s = ""
 
  +
local s = ''
j = string.find(v,";",1,true)
 
  +
local output = {}
if j ~= nil
 
  +
then
 
  +
if not h.isempty(list)
s_image = mw.text.trim(string.sub(v,j+1,#v))
 
  +
then
s_page = string.sub(v,1,j-1)
 
  +
for i = 1, #list do
else
 
  +
s = list[i]
s_page = v
 
  +
if not h.isempty(s)
end
 
  +
then
s_title = h.lua_breaklink(s_page,2)
 
  +
s = mw.text.split(h.trim(s), ';', true)
s_page = h.lua_breaklink(s_page,1)
 
  +
s_page = h.break_link(s[1], 1)
page_s = string.reverse(s_page)
 
  +
s_title = h.break_link(s[1], 2)
j = string.find(page_s,"( ",1,true)
 
  +
s_image = h.trim(s[2] or '')
if j ~= nil and s_title == s_page
 
  +
s_name, s_reality = module_reality.lua_get_name_and_reality(s_page)
then s_title = string.reverse(string.sub(page_s, j+2, #page_s))
 
  +
if not h.isempty(s_reality) and s_title == s_page
end
 
  +
then s_title = s_name
if redlinks == true
 
  +
end
then s = s..s_page.."~"..s_image.."~ "..s_title.."@"
 
  +
if redlinks == true
else s = s..s_page.."~"..s_image.."~"..s_title.."@"
 
  +
then s_title = ' '..s_title
end
 
end
+
end
  +
return s
 
  +
table.insert( output, {
  +
['page'] = s_page,
  +
['image'] = s_image,
  +
['title'] = s_title,
  +
['name'] = s_name,
  +
['reality'] = s_reality }
  +
)
  +
end
  +
end
  +
end
  +
  +
return output
 
end
 
end
   
  +
function p.include (frame)
 
  +
-- creates box with image, link to page (if needed) and link to reality (if stated)
return p.lua_include(frame.args[1])
 
  +
function p.lua_createBox(s_table, main_name, main_title, disambiguation_pagename, noimage, old_format)
  +
local image = ''
  +
local name = ''
  +
local reality = ''
  +
local output = ''
  +
  +
if not h.isempty(s_table)
  +
then
  +
image = p.createBox_image( {
  +
image = s_table.image,
  +
page = s_table.page,
  +
noimage = noimage } )
  +
name = p.createBox_link( {
  +
page = s_table.page,
  +
name = s_table.name,
  +
title = s_table.title,
  +
main_name = main_name,
  +
main_title = main_title,
  +
disambiguation_pagename = disambiguation_pagename,
  +
old_format = old_format } )
  +
reality = p.createBox_reality( {s_table.reality} )
  +
  +
output = tostring( mw.html.create( 'div' )
  +
:css( 'width', '150px' )
  +
:css( 'float', 'left' )
  +
:css( 'text-align', 'center' )
  +
:css( 'margin-left', '10px' )
  +
:wikitext( image..name..reality )
  +
:done() )
  +
end
  +
  +
return output
 
end
 
end
   
  +
function p.lua_reality(r, e)
 
  +
function p.createBox_image(frame)
local j
 
  +
local args = getArgs (frame)
local k
 
  +
local image = args['image']
local s
 
  +
local imageSize = args['imageSize'] or '150px'
local s1
 
  +
local page = args['page']
local s2
 
  +
local noimage = args['noimage'] or 'No Image Available.png'
local s3
 
  +
local link = ''
 
  +
local output
if e == true or e == "true"
 
  +
then
 
  +
if not h.isempty(page)
s1 = string.reverse(r)
 
  +
then
s2 = string.find(s1, "( ",1,true) or string.find(s1, "(_",1,true)
 
  +
link = '|link='..page
s3 = string.find(s1, ")",1,true)
 
  +
if (string.find(page, ' Vol ') ~= nil and pagetype.get_page_type(page) == 'Volume') or
r = string.reverse(string.sub(s1, s3+1, s2-1))
 
  +
(string.find(page, '(Story Arc)') ~= nil and pagetype.get_page_type(page) == 'Story Arc')
end
 
  +
then imageSize = '100px'
 
  +
end
j,k = string.find(string.lower( r ),"earth-",1,true)
 
  +
end
if j ~= nil
 
  +
then s = string.sub(r,k+1,string.len(r))
 
  +
if h.isempty(image) or image == "No Image Available At All.png"
else s = r
 
  +
then image = noimage
end
 
  +
end
s2 = list_of_realities[s]
 
  +
if s2 ~= nil
 
  +
output = mw.html.create( 'div' )
then return s2[1], s2[2], s2[3]
 
  +
:css( 'height', '150px' )
elseif tonumber(r) ~= nil or string.match(r, '^TRN%d+') ~= nil
 
  +
:css( 'overflow', 'hidden' )
then return "Earth-"..r, "Earth-"..r, "Comic"
 
  +
:wikitext( '[[File:'..image..'|'..imageSize..link..']]' )
else return r, r, "Comic"
 
  +
:done()
end
 
  +
  +
return tostring(output)
 
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
 
   
  +
function p.createBox_link(frame)
s1, s2, s3 = p.lua_reality(r, e)
 
  +
local function bold_link(text1, text2)
if i == 3
 
  +
return tostring( mw.html.create( 'span' )
then return s3
 
  +
:css( 'font-weight', 'bold' )
elseif i == 2
 
  +
:wikitext( h.Link(text1, text2) )
then return s2
 
  +
:done()
else return s1
 
  +
)
end
 
  +
end
  +
local args = getArgs (frame, {trim = false})
  +
local old_format = args['old_format']
  +
local page = args['page']
  +
local name = args['name']
  +
local title = args['title']
  +
local main_name = args['main_name']
  +
local main_title = args['main_title']
  +
local disambiguation_pagename = args['disambiguation_pagename']
  +
local output = ''
  +
local subname = ''
  +
local i = ''
  +
  +
if old_format == true -- check for old disambiguation pages
  +
then
  +
if (string.find(page, ' Vol ') ~= nil and pagetype.get_page_type(page) == 'Volume')
  +
then output = '{{cvd|'..page..'}}'
  +
else output = bold_link(page, title)
  +
end
  +
else
  +
i, subname = string.match(name, '(.+)%((.+)%)')
  +
if not h.isempty(title)
  +
then
  +
title = h.break_link (title, 2)
  +
if not h.in_list({main_title, main_name, disambiguation_pagename}, title)
  +
then
  +
title = mw.text.trim(title)
  +
if not h.in_list({main_title, main_name, title, disambiguation_pagename}, name)
  +
then
  +
if not h.isempty(subname)
  +
then name = '<br />('..h.trim(i)..')<br />('..subname..')'
  +
else name = '<br />('..name..')'
  +
end
  +
output = bold_link(page, title..name)
  +
else output = bold_link(page, title)
  +
end
  +
elseif not h.in_list({main_title, main_name}, name)
  +
then
  +
if not h.isempty(subname)
  +
then name = h.trim(i)..'<br />('..subname..')'
  +
end
  +
output = bold_link(page, name)
  +
end
  +
elseif name ~= main_name and name ~= main_title
  +
then
  +
if not h.isempty(subname)
  +
then name = h.trim(i)..'<br />('..subname..')'
  +
end
  +
output = bold_link(page, name)
  +
end
  +
end
  +
  +
if not h.isempty(output)
  +
then output = output..'<br />'
  +
end
  +
  +
return output
 
end
 
end
  +
   
function p.lua_image(i,p,noimage)
+
function p.createBox_reality(frame)
  +
local args = getArgs (frame)
if h.isempty(i) == true or i == "No Image Available At All.png"
 
  +
local reality = args[1]
then
 
  +
local info
if h.isempty(noimage) == false
 
  +
local output = ''
then i = noimage
 
  +
else i = "No Image Available.png"
 
  +
if not h.isempty(reality)
end
 
  +
then
end
 
  +
if type(reality) == 'table'
return '[[File:'..i..'|150px|link='..p..']]'
 
  +
then info = reality
  +
else info = module_reality.get_reality_info({reality})
  +
end
  +
if info.name ~= info.description
  +
then output = info.description..'<br />([['..info.name..']])'
  +
else output = '([['..info.name..']])'
  +
end
  +
end
  +
  +
return output
 
end
 
end
   
  +
function p.image(frame)
 
  +
function p.createBox_MainVersion(frame)
return p.lua_image(frame.args[1], frame.args[2])
 
  +
local args = getArgs (frame)
  +
local pagename = args['pagename']
  +
local text = args['text'] or nil
  +
local image = args['image']
  +
local imageSize = args['imageSize']
  +
local description = args['description']
  +
local s_name
  +
local s_reality
  +
local div_box
  +
local div_clear = tostring(mw.html.create( 'div' ):css( 'clear', 'left' ):done() )
  +
local output = ''
  +
  +
s_name, s_reality = module_reality.lua_get_name_and_reality(pagename)
  +
s_name = string.match(s_name, '(.+) %(') or s_name
  +
s_name = text or s_name
  +
s_reality = p.createBox_reality({s_reality})
  +
s_name = '<br />'..p.createBox_link({page = pagename, title = s_name, old_format = true})
  +
image = '[[File:'..image..'|'..imageSize..'|link='..pagename..']]'
  +
  +
if not h.isempty(description)
  +
then
  +
div_box = tostring(mw.html.create( 'div' )
  +
:css( 'font-size', '125%' )
  +
:css( 'text-align', 'center' )
  +
:css( 'float', 'left' )
  +
:css( 'margin-right', '10px')
  +
:wikitext(image..s_name..s_reality)
  +
:done()
  +
)
  +
output = div_box..description
  +
else
  +
output = tostring(mw.html.create( 'div' )
  +
:css( 'font-size', '125%' )
  +
:css( 'text-align', 'center' )
  +
:attr('align', 'center')
  +
:wikitext(image..s_name..s_reality)
  +
:done()
  +
)
  +
end
  +
  +
return output..div_clear
 
end
 
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)
 
   
  +
function p.lua_createTOC(versions, headers, pagename, main_title)
if others == true
 
  +
local output = {}
then s = "<b>[["..s_page.."|"..s_title.."]]</b><br>"
 
  +
local bold_middot = tostring( mw.html.create( 'span' )
else
 
  +
:css( 'font-weight', 'bold' )
i = string.find(page_s,"( ",1,true)
 
  +
:wikitext( "&nbsp;&middot; " )
s_name = string.reverse( string.sub(page_s, i+2, #page_s) )
 
  +
:done()
if h.isempty(s_title) == false
 
  +
)
then
 
  +
local div_toc = mw.html.create( 'div' )
s_title = h.lua_breaklink (s_title, 2)
 
  +
:attr( 'align', 'center' )
if h.inlist({s_main_title, s_main_name}, s_title) == false
 
  +
:css( 'width', '100%' )
then
 
  +
:css( 'text-align', 'center' )
s_title = mw.text.trim(s_title)
 
  +
:css( 'border-top', '1px solid grey' )
if h.inlist({s_main_title, s_main_name, s_title}, s_name) == false
 
  +
:css( 'border-bottom', '1px solid grey' )
then s = "<b>[["..s_page.."|"..s_title.."<br>("..s_name..")]]</b><br>"
 
  +
:css( 'margin-top', '1em')
else s = "<b>[["..s_page.."|"..s_title.."]]</b><br>"
 
  +
:done()
end
 
  +
elseif h.inlist({s_main_title, s_main_name}, s_name) == false
 
  +
for i = 1, #versions do
then s = "<b>[["..s_page.."|"..s_name.."]]</b><br>"
 
  +
if not h.isempty(versions[i])
end
 
  +
then table.insert(output, h.Link(pagename..'#'..headers[i], headers[i]) )
elseif s_name ~= s_main_name and s_name ~= s_main_title
 
  +
end
then s = "<b>[["..s_page.."|"..s_name.."]]</b><br>"
 
  +
end
end
 
  +
end
 
  +
if h.exists(pagename..' Comic Books')
return s
 
  +
then table.insert(output, h.Link(pagename..' Comic Books', pagename..' Comics') )
  +
elseif not h.isempty(main_title) and h.exists(main_title..' Comic Books')
  +
then table.insert(output, h.Link(main_title..' Comic Books', main_title..' Comics') )
  +
end
  +
  +
if not h.isempty(output)
  +
then
  +
div_toc = div_toc:wikitext( mw.text.listToText(output, bold_middot, bold_middot) ):done()
  +
output = tostring(div_toc)
  +
else output = ''
  +
end
  +
  +
return output
 
end
 
end
   
  +
function p.name(frame)
 
  +
function p.createSection(frame)
local s_page = frame.args["page"] or frame.args[1]
 
  +
local args = getArgs (frame)
s_page = h.lua_breaklink(s_page, 1)
 
  +
local s_table = frame['s_table']
local i = string.find(s_page," (",1,true)
 
  +
local header = frame['header']
local s_name
 
  +
local main_name = frame['main_name']
if i == nil
 
  +
local main_title = frame['main_title']
then s_name = s_page
 
  +
local disambiguation_pagename = frame['disambiguation_pagename']
else s_name = string.sub(s_page, 1, i-1)
 
  +
local noimage = frame['noimage']
end
 
local s_title = frame.args["title"] or s_name
+
local old_format = frame['old_format']
  +
local row4 = {}
local s_main_title = frame.args["main_title"] or s_title
 
  +
local output = ''
local s_main_name = frame.args["main_name"] or s_name
 
  +
local function div_row(row)
local s_others = frame.args["others"] or true
 
  +
local output = mw.html.create( 'div' )
return p.lua_name(s_page, s_title, s_main_title, s_main_name, s_others)
 
  +
:css( 'display', 'table' )
  +
:css( 'margin', '0 auto' )
  +
:wikitext( row )
  +
:done()
  +
return tostring(output)
  +
end
  +
local div_clear = tostring(mw.html.create( 'div' ):css( 'clear', 'left' ):done() )
  +
  +
if not h.isempty(s_table)
  +
then
  +
if not old_format
  +
then table.sort(s_table, p.lua_sort_by_reality)
  +
end
  +
  +
output = {}
  +
if not h.isempty(header)
  +
then header = design.add_header(header, 2, 'center')
  +
else header = ''
  +
end
  +
for i = 1, #s_table do
  +
if #row4 < 4
  +
then table.insert(row4, p.lua_createBox(s_table[i], main_name, main_title, disambiguation_pagename, noimage, old_format) )
  +
end
  +
if #row4 == 4 or i == #s_table
  +
then
  +
table.insert( output, div_row(table.concat(row4)) )
  +
table.insert( output, div_clear )
  +
row4 = {}
  +
end
  +
end
  +
output = header..table.concat(output)
  +
end
  +
  +
return output
 
end
 
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)
 
  +
-- used in Template:Disambiguation Text
s_page = string.sub(v, 1, part-1)
 
  +
function p.disambiguation_text(frame)
page_s = string.reverse(s_page)
 
  +
local s = frame.args[1]
j = string.find(page_s,"( ",1,true)
 
  +
local reality = ''
k = string.find(page_s, ")",1,true)
 
  +
local link
if j ~= nil and k ~= nil
 
  +
local text
then s_reality = string.reverse(string.sub(page_s, k+1, j-1 ) )
 
  +
local comment = ''
end
 
  +
local i
j, k = string.find(s_page,"Earth-TRN",1,true)
 
  +
local output = ''
if j ~= nil
 
  +
then
 
  +
if not h.isempty(s)
s1 = string.sub(s_page, k+1, string.len(s_page)-1)
 
  +
then
s_pad = string.rep("0", 20-string.len(s1)-string.len("Earth-TRN"))
 
  +
s = h.explode(';', s)
s = "Earth-TRN"..s_pad..s1
 
  +
if tonumber(s[1]) ~= nil or string.match(s[1], '^TRN%d+') ~= nil or list_of_realities[s[1]] ~= nil
else
 
  +
then
j, k = string.find(s_page,"Earth-",1,true)
 
  +
reality = { p.lua_reality(s[1]) }
if j ~= nil
 
  +
output = reality[1]..'<br />('..h.Link(reality[2])..')'
then
 
  +
else
s1 = string.sub(s_page, k+1, string.len(s_page)-1)
 
  +
if h.is_link(s[1])
s_pad = string.rep("0", 20-string.len(s1)-string.len("Earth-"))
 
  +
then
s = "Earth-"..s_pad..s1
 
  +
i = string.find(s[1], ']]', 1, true)
else s = s_reality
 
  +
link = h.break_link(s[1],1)
end
 
  +
text = h.break_link(s[1],2)
end
 
  +
if #s[1] > i+2
j = string.find(v,"~",part+1,true)
 
  +
then comment = string.sub(s[1], i+2, #s[1])
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>'
 
  +
end
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
+
if not h.isempty( string.find(link, '(',1,true) )
  +
then
then
 
desc,earth,ttype = p.lua_reality(s_reality, false)
+
reality = { p.lua_reality(link, true) }
  +
reality = '<br />'..reality[1]..'<br />('..h.Link(reality[2])..')'
if desc ~= "" and earth ~= "" and desc == earth
 
  +
end
then s_reality = '<br>([['..earth..']])'
 
  +
else
else s_reality = desc..'<br>([['..earth..']])'
 
  +
link = s[1]
end
 
  +
text = s[1]
end
 
  +
end
s = s..'~'..s_image..s_title..s_reality..'</div></td>'
 
  +
output = tostring( mw.html.create( 'span' )
return s, ttype
 
  +
:css( 'font-weight', 'bold' )
  +
:wikitext( h.Link(link,text)..comment )
  +
:done() )..reality
  +
end
  +
end
  +
  +
return output
 
end
 
end
   
function p.lua_table(t, header)
+
function p.lua_reality(r, e)
local i = 1
+
local j
local s = ""
+
local k
local v
+
local s
  +
local s1
if #t ~= 0 then
 
  +
local s2
s = '<h2><center>'..header..'</center></h2><table align="center" style="text-align: center;"><tr valign="top">'
 
  +
local s3
--for i,v in ipairs(t) do
 
  +
while i <= #t do
 
v = t[i]
+
if e == true or e == "true"
  +
then
s = s..string.sub(v, string.find(v,"~",1,true)+1, string.len(v))
 
  +
s1 = string.reverse(r)
if math.fmod(i, 4) == 0 then s = s..'</tr><tr valign="top">' end
 
  +
s2 = string.find(s1, "( ",1,true) or string.find(s1, "(_",1,true)
i = i + 1
 
  +
s3 = string.find(s1, ")",1,true)
end
 
  +
r = string.reverse(string.sub(s1, s3+1, s2-1))
s = s..'</tr></table><br>'
 
end
+
end
  +
return s
 
  +
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
 
end
   
function p.disambiguation(frame)
+
function p.reality (frame)
local l = frame.args["list"]
+
local r = h.break_link(frame.args[1], 1)
local s_main_title = frame.args["main_title"]
+
local i = tonumber(frame.args[2])
local s_main_name = frame.args["main_name"]
+
local e = frame.args[3] or frame.args["extract"]
  +
local s1
local s_include = frame.args["include"]
 
  +
local s2
local s_noimage = frame.args["noimage"]
 
  +
local s3
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
 
   
  +
s1, s2, s3 = p.lua_reality(r, e)
for j=5,12 do
 
  +
if i == 3
if h.isempty(sections[j]) == false
 
  +
then return s3
then
 
  +
elseif i == 2
l = mw.text.split(p.lua_include(sections[j]),"@",true)
 
  +
then return s2
i = 1
 
  +
else return s1
while next(l,i) ~= nil do
 
  +
end
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
 
end
   

Revision as of 02:58, 14 April 2021

Documentation for this module may be created at Module:Disambiguation/doc

local p = {}
local list_of_realities = mw.loadData( 'Module:Disambiguation/Realities' )
local h = require("Module:HF")
local pagetype = require("Module:PageType")
local design = require("Module:Design")
local module_reality = require("Module:Reality")
local getArgs = require('Module:Arguments').getArgs


-- main function used to create entire disambiguation page
function p.disambiguation(frame)
	local args = getArgs (frame)
	local g_type
	local g_main_name = args['main_name']
	local g_main_character = args['Main Character'] or ''
	local g_main_image_size = args['Main Image Size'] or '250px'
	local g_main_version
	local g_main_title
	local g_main_image
	local g_no_image
	local g_logo = args['logo'] or ''
	local g_description = args['description'] or ''
	local g_alternative_names = {}
	local g_include = {}
	local g_exclude = {}
	local g_includeComic = {}
	local g_includeMovie = {}
	local g_includeTV = {}
	local g_includeGame = {}
	local g_teams = {}
	local g_others = {}
	local g_related = {}
	local g_new_text = { {}, {}, {}, {}, {}, {}, {}, {}, {} }
	local g_page = mw.title.getCurrentTitle()
	local g_pagename = g_page.text
	
	local list = ''
	local all_versions = {}
	local comics = {}
	local movies = {}
	local tv = {}
	local games = {}
	local headers1 = { 'Alternate Reality Versions', 'Movies', 'Television', 'Video Games' }
	local headers2 = { 'Others', g_pagename..' Related', 'Teams' }
	local tables = {}
	local s = ''
	local s1 = ''
	local s2 = ''
	local output = {}

	table.insert(output, '__NOTOC__')
	table.insert(output, g_logo)
	-- if 'main_name' parameter is not empty, then use DPL to create a list of alternate versions
	if not h.isempty(g_main_name)
		then
			g_main_version = args['main']
			g_main_title = args['main_title'] or g_main_name
			g_main_image = args['main_image']
			table.insert(output, p.createBox_MainVersion({pagename = g_main_version, 
														  image = g_main_image,
														  imageSize = g_main_image_size,
														  description = g_description
														}) 
						)

			g_type = args['type'] or pagetype.get_page_type(g_main_version)
			g_noimage = args['noimage']
			for i = 1,100 do
				if not h.isempty(args['alternative'..i])
					then table.insert(g_alternative_names, args['alternative'..i])
				end
				if not h.isempty(args['include'..i])
					then table.insert(g_include, args['include'..i])
				end
				if not h.isempty(args['includeComic'..i])
					then table.insert(g_includeComic, args['includeComic'..i])
				end
				if not h.isempty(args['includeMovie'..i])
					then table.insert(g_includeMovie, args['includeMovie'..i])
				end
				if not h.isempty(args['includeTV'..i])
					then table.insert(g_includeTV, args['includeTV'..i])
				end
				if not h.isempty(args['includeGame'..i])
					then table.insert(g_includeGame, args['includeGame'..i])
				end
				if not h.isempty(args['exclude'..i])
					then table.insert(g_exclude, args['exclude'..i])
				end	
			end
			list = frame:preprocess( p.lua_dpl_list(g_main_name, g_main_version, g_type, g_alternative_names, g_exclude, 500)..p.lua_dpl_list(g_main_name, g_main_version, g_type, g_alternative_names, g_exclude, 500, 500) )
			list = string.gsub(list, '&#x20;', '')
			list = h.explode('@', list)
			
			for i = 1, #list do
				s = mw.text.split(list[i], '~') --h.explode('~', list[i])
				s1, s2 = module_reality.lua_get_name_and_reality(s[1])
				table.insert( all_versions, { ['page'] = s[1], ['image'] = s[2], ['title'] = s[3], ['name'] = s1, ['reality'] = s2 } )
			end
			all_versions = h.join_tables(all_versions, p.lua_transform_from_old_format(g_include, true))

			for i = 1, #all_versions do
				s = all_versions[i].reality.type
				if s == 'Game'
					then table.insert(games, all_versions[i])
					elseif s == "TV" 
						then table.insert(tv, all_versions[i])
					elseif s == "Movie" 
						then table.insert(movies, all_versions[i])
					else table.insert(comics, all_versions[i])
				end
			end
			
			comics = h.join_tables(comics, p.lua_transform_from_old_format(g_includeComic, false))
			movies = h.join_tables(movies, p.lua_transform_from_old_format(g_includeMovie, false))
			tv =  h.join_tables(tv, p.lua_transform_from_old_format(g_includeTV, false))
			games = h.join_tables(games, p.lua_transform_from_old_format(g_includeGame, false))

			tables = { comics, movies, tv, games }
			table.insert( output, p.lua_createTOC(tables, headers1, g_pagename, g_main_title) )
			for i = 1,4 do
				 table.insert(output, p.createSection({
							s_table = tables[i], 
							header = headers1[i],
							main_name = g_main_name,
							main_title = g_main_title,
							disambiguation_pagename = g_pagename,
							noimage = g_noimage,
							old_format = false
					}) )
			end
		elseif not h.isempty(g_main_character)
			then
				g_main_character = mw.text.split(h.trim(g_main_character), ';', true)
				table.insert(output, p.createBox_MainVersion({
					pagename = h.break_link(g_main_character[1], 1), 
					text = h.break_link(g_main_character[1], 2), 
					image = h.trim(g_main_character[2]) or 'No Image Available.png',
					imageSize = g_main_image_size,
					description = g_description
				})
				)
	end

	for i = 1,9 do
		table.insert(headers2, args['New Header'..i] or '')
	end

	for i = 1,200 do
		table.insert(g_teams, args['Teams'..i])
		table.insert(g_others, args['Others'..i])
		table.insert(g_related, args['Related'..i])
		for j = 1,9 do
			table.insert(g_new_text[j], args['New Header'..j..'_'..i])
		end
	end
	g_teams = p.lua_transform_from_old_format(g_teams, false)
	g_others = p.lua_transform_from_old_format(g_others, false)
	g_related = p.lua_transform_from_old_format(g_related, false)

	for j = 1,9 do
		g_new_text[j] = p.lua_transform_from_old_format(g_new_text[j], false)
	end
	
	tables = { g_others, g_related, g_teams, 
			   g_new_text[1], g_new_text[2], g_new_text[3], g_new_text[4], g_new_text[5],
			   g_new_text[6], g_new_text[7], g_new_text[8], g_new_text[9]}

	for i = 1,#tables do
		table.insert(output, p.createSection({
							s_table = tables[i], 
							header = headers2[i],
							main_name = g_main_name,
							main_title = g_main_title,
							disambiguation_pagename = g_pagename,
							noimage = g_noimage,
							old_format = true
			}) )
	end

	--return '<div valign="top">'..table.concat(output)..'</div>'
	return frame:preprocess( table.concat(output) )
end


function p.lua_sort_by_reality(a, b)
	local reality1 = a.reality.number
	local reality2 = b.reality.number
	local earth33 = {'33 1/3', '33⅓'}
	local output
	
	if h.isempty(reality1) or h.isempty(reality2)
		then output = false
		else
			if h.in_list(earth33, reality1)
				then reality1 = 33.3
			end
			if h.in_list(earth33, reality2)
				then reality2 = 33.3
			end
			if tonumber(reality1) ~= nil
				then
					if tonumber(reality2) ~= nil
						then output = tonumber(reality1)<tonumber(reality2)
						else output = true
					end
				elseif tonumber(reality2) ~= nil
					then output = false
					else output = reality1<reality2
			end
	end

	return output
end


function p.lua_dpl_list(main_name, main_version, main_version_type, alternative_names, exclude, count, offset)
	local template = '{Marvel Database:'..main_version_type..' Template}'
	local image = template..':Image, '
	local title = ''
	local s = ''
	local output = {}
	
	if not h.isempty(alternative_names)
		then alternative_names = mw.text.listToText(alternative_names, '%¦', '%¦')..'%'
		else alternative_names = ''
	end
	if not h.isempty(exclude)
		then exclude = mw.text.listToText(exclude, '%¦', '%¦')..'%'
		else exclude = ''
	end

	main_version_type = string.lower(main_version_type)
	if  main_version_type == 'character' or main_version_type == 'characters'
		then title = template..':CurrentAlias'
		else title = template..':OfficialName'
	end
	
	table.insert(output, '{{#dpl:')
	table.insert(output, '|category = '..main_version_type..'s')
	table.insert(output, '|namespace = ')
	table.insert(output, '|titlematch = '..main_name..' (%¦'..alternative_names)
	table.insert(output, '|nottitlematch = '..main_version..'¦'..exclude)
	table.insert(output, '|include = '..image..title)
	table.insert(output, '|mode = userformat')
	table.insert(output, '|secseparators = %PAGE%~,~,,@')
	table.insert(output, '|noresultsheader = &#x20;')
	--table.insert(output, '|eliminate = templates')
	table.insert(output, '|allowcachedresults = true')
	if not h.isempty(count)
		then table.insert(output, '|count ='..count)
	end
	if not h.isempty(offset)
		then table.insert(output, '|offset ='..offset)
	end
	table.insert(output, '}}')
	
	return table.concat(output)
end


-- transform string in 'page; image' format into table
function p.lua_transform_from_old_format(list, redlinks)
	local i
	local s_page = ''
	local s_title = ''
	local s_image = ''
	local s_reality = ''
	local s_name = ''
	local s = ''
	local output = {}

	if not h.isempty(list)
		then
			for i = 1, #list do
				s = list[i]
				if not h.isempty(s)
					then
						s = mw.text.split(h.trim(s), ';', true)
						s_page = h.break_link(s[1], 1)
						s_title = h.break_link(s[1], 2)
						s_image = h.trim(s[2] or '')
						s_name, s_reality = module_reality.lua_get_name_and_reality(s_page)
						if not h.isempty(s_reality) and s_title == s_page
							then s_title = s_name
						end
						if redlinks == true
							then s_title = ' '..s_title
						end

						table.insert( output, { 
												['page'] = s_page, 
												['image'] = s_image, 
												['title'] = s_title, 
												['name'] = s_name, 
												['reality'] = s_reality } 
									)
				end
			end
	end
	
	return output
end


-- creates box with image, link to page (if needed) and link to reality (if stated)
function p.lua_createBox(s_table, main_name, main_title, disambiguation_pagename, noimage, old_format)
	local image = ''
	local name = ''
	local reality = ''
	local output = ''

	if not h.isempty(s_table)
		then
			image = p.createBox_image( { 
							image = s_table.image, 
							page = s_table.page, 
							noimage = noimage } )
			name = p.createBox_link( {
							page = s_table.page, 
							name = s_table.name, 
							title = s_table.title, 
							main_name = main_name, 
							main_title = main_title,
							disambiguation_pagename = disambiguation_pagename,
							old_format = old_format } )
			reality = p.createBox_reality( {s_table.reality} )

			output = tostring( mw.html.create( 'div' )
					:css( 'width', '150px' )
					:css( 'float', 'left' )
					:css( 'text-align', 'center' )
					:css( 'margin-left', '10px' )
					:wikitext( image..name..reality )
					:done() )
	end
	
	return output
end


function p.createBox_image(frame)
	local args = getArgs (frame)
	local image = args['image']
	local imageSize = args['imageSize'] or '150px'
	local page = args['page']
	local noimage = args['noimage'] or 'No Image Available.png'
	local link = ''
	local output
	
	if not h.isempty(page)
		then 
			link = '|link='..page
			if (string.find(page, ' Vol ') ~= nil and pagetype.get_page_type(page) == 'Volume') or
			   (string.find(page, '(Story Arc)') ~= nil and pagetype.get_page_type(page) == 'Story Arc') 
				then imageSize = '100px'
			end
	end
	
	if h.isempty(image) or image == "No Image Available At All.png"
		then image = noimage
	end
	
	output = mw.html.create( 'div' )
			 :css( 'height', '150px' )
			 :css( 'overflow', 'hidden' )
			 :wikitext( '[[File:'..image..'|'..imageSize..link..']]' )
			 :done() 

	return tostring(output)
end


function p.createBox_link(frame)
	local function bold_link(text1, text2) 
		return tostring( mw.html.create( 'span' )
							:css( 'font-weight', 'bold' )
							:wikitext( h.Link(text1, text2) )
							:done() 
						)
	end
	local args = getArgs (frame, {trim = false})
	local old_format = args['old_format']
	local page = args['page']
	local name = args['name']
	local title = args['title']
	local main_name = args['main_name']
	local main_title = args['main_title']
	local disambiguation_pagename = args['disambiguation_pagename']
	local output = ''
	local subname = ''
	local i = ''

	if old_format == true -- check for old disambiguation pages
		then 
			if (string.find(page, ' Vol ') ~= nil and pagetype.get_page_type(page) == 'Volume')
				then output = '{{cvd|'..page..'}}'
				else output = bold_link(page, title)
			end
		else
			i, subname = string.match(name, '(.+)%((.+)%)')
			if not h.isempty(title)
				then
					title = h.break_link (title, 2)
					if not h.in_list({main_title, main_name, disambiguation_pagename}, title)
						then 
							title = mw.text.trim(title)
							if not h.in_list({main_title, main_name, title, disambiguation_pagename}, name)
								then 
									if not h.isempty(subname)
										then name = '<br />('..h.trim(i)..')<br />('..subname..')'
										else name = '<br />('..name..')'
									end
									output = bold_link(page, title..name)
								else output = bold_link(page, title)
							end
						elseif not h.in_list({main_title, main_name}, name)
							then 
								if not h.isempty(subname)
									then name = h.trim(i)..'<br />('..subname..')'
								end
								output = bold_link(page, name)  
					end
				elseif name ~= main_name and name ~= main_title
					then 
						if not h.isempty(subname)
							then name = h.trim(i)..'<br />('..subname..')'
						end
						output = bold_link(page, name)
			end
	end
	
	if not h.isempty(output)
		then output = output..'<br />'
	end
	
	return output
end
	

function p.createBox_reality(frame)
	local args = getArgs (frame)
	local reality = args[1]
	local info
	local output = ''
	
	if not h.isempty(reality)
		then
			if type(reality) == 'table'
				then info = reality
				else info = module_reality.get_reality_info({reality})
			end
			if info.name ~= info.description
				then output = info.description..'<br />([['..info.name..']])'
				else output = '([['..info.name..']])'
			end
	end
	
	return output
end


function p.createBox_MainVersion(frame)
	local args = getArgs (frame)
	local pagename = args['pagename']
	local text = args['text'] or nil
	local image = args['image']
	local imageSize = args['imageSize']
	local description = args['description']
	local s_name
	local s_reality
	local div_box
	local div_clear = tostring(mw.html.create( 'div' ):css( 'clear', 'left' ):done() )
	local output = ''

	s_name, s_reality = module_reality.lua_get_name_and_reality(pagename)
	s_name = string.match(s_name, '(.+) %(') or s_name
	s_name = text or s_name
	s_reality = p.createBox_reality({s_reality})
	s_name = '<br />'..p.createBox_link({page = pagename, title = s_name, old_format = true})
	image = '[[File:'..image..'|'..imageSize..'|link='..pagename..']]'
	
	if not h.isempty(description)
		then
			div_box = tostring(mw.html.create( 'div' )
						:css( 'font-size', '125%' )
						:css( 'text-align', 'center' )
						:css( 'float', 'left' )
						:css( 'margin-right', '10px')
						:wikitext(image..s_name..s_reality)
						:done() 
					  )
			output = div_box..description
		else
			output = tostring(mw.html.create( 'div' )
						:css( 'font-size', '125%' )
						:css( 'text-align', 'center' )
						:attr('align', 'center')
						:wikitext(image..s_name..s_reality)
						:done() 
					  )
	end
	
	return output..div_clear
end


function p.lua_createTOC(versions, headers, pagename, main_title)
	local output = {}
	local bold_middot = tostring( mw.html.create( 'span' ) 
				:css( 'font-weight', 'bold' )
				:wikitext( "&nbsp;&middot; " )
				:done() 
			)
	local div_toc = mw.html.create( 'div' )
					:attr( 'align', 'center' )
					:css( 'width', '100%' )
					:css( 'text-align', 'center' )
					:css( 'border-top', '1px solid grey' )
					:css( 'border-bottom', '1px solid grey' )
					:css( 'margin-top', '1em')
					:done()

	for i = 1, #versions do
		if not h.isempty(versions[i])
			then table.insert(output, h.Link(pagename..'#'..headers[i], headers[i]) )
		end
	end
	
	if h.exists(pagename..' Comic Books')
		then table.insert(output, h.Link(pagename..' Comic Books', pagename..' Comics') )
		elseif not h.isempty(main_title) and h.exists(main_title..' Comic Books')
			then table.insert(output, h.Link(main_title..' Comic Books', main_title..' Comics') )
	end
	
	if not h.isempty(output)
		then 
			div_toc = div_toc:wikitext( mw.text.listToText(output, bold_middot, bold_middot) ):done()
			output = tostring(div_toc)
		else output = ''
	end
				
	return output
end


function p.createSection(frame)
	local args = getArgs (frame)
	local s_table = frame['s_table']
	local header = frame['header']
	local main_name = frame['main_name']
	local main_title = frame['main_title']
	local disambiguation_pagename = frame['disambiguation_pagename']
	local noimage = frame['noimage']
	local old_format = frame['old_format']
	local row4 = {}
	local output = ''
	local function div_row(row)
		local output = mw.html.create( 'div' )
					:css( 'display', 'table' )
					:css( 'margin', '0 auto' )
					:wikitext( row )
					:done()
		return tostring(output)
	end
	local div_clear = tostring(mw.html.create( 'div' ):css( 'clear', 'left' ):done() )
	
	if not h.isempty(s_table) 
		then
			if not old_format
				then table.sort(s_table, p.lua_sort_by_reality)
			end
			
			output = {}
			if not h.isempty(header)
				then header = design.add_header(header, 2, 'center')
				else header = ''
			end
			for i = 1, #s_table do
				if #row4 < 4
					then table.insert(row4, p.lua_createBox(s_table[i], main_name, main_title, disambiguation_pagename, noimage, old_format) )
				end
				if #row4 == 4 or i == #s_table
					then 
						table.insert( output, div_row(table.concat(row4)) )
						table.insert( output, div_clear )
						row4 = {}
				end
			end
			output = header..table.concat(output)
	end
	
	return output
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.is_link(s[1])
						then
							i = string.find(s[1], ']]', 1, true)
							link = h.break_link(s[1],1)
							text = h.break_link(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_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.break_link(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

return p