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