Documentation for this module may be created at Module:Infobox/doc
local p = {}
local m = require("Module:Main")
local c = require("Module:Chapters")
local getArgs = require('Dev:Arguments').getArgs
------------------------------------------------------------------------------------------
function p.create_infobox(infobox, width)
width = width or '300px'
return tostring( mw.html.create( 'div' )
:attr('class', 'infobox')
:css( 'width', width )
:css( 'float', 'right' )
:css( 'clear', 'none' )
--:css( 'margin', '0px 0px 1em 1em' )
--:css( 'border', '1px solid'..m.get_main_color(2) )
:css( 'border', 'none' )
:css( 'border-radius', '0px 0px 10px 10px' )
:wikitext(infobox)
:done() )
end
------------------------------------------------------------------------------------------
function p.add_group(group, header)
local output = ''
if table.concat(group) ~= ''
then
header = mw.html.create( 'div' )
:css( 'clear', 'both' )
:css( 'text-align', 'center' )
:css( 'font-weight', 'bold' )
:css( 'padding', '10px' )
:css( 'height', '1.5em' )
:css( 'background', m.get_main_color(2))
:wikitext(header)
:done()
output = tostring(header)..'\n'..table.concat(group)
end
return output
end
------------------------------------------------------------------------------------------
function p.add_row(label, value)
local width_l = '40%'
local width_r = '60%'
local tag_label
local tag_value
local output = ''
if not m.empty(value)
then
if string.find(value, '^\n') == nil
then value = '\n'..value
end
tag_label = mw.html.create( 'div' )
:css( 'width', width_l )
:css( 'text-align', 'left' )
:css( 'float', 'left' )
:css( 'font-weight', 'bold')
:wikitext(label)
:done()
tag_value = mw.html.create( 'div' )
:css( 'width', width_r )
:css( 'text-align', 'left' )
:css( 'float', 'left' )
:wikitext(value)
:done()
tag_label = tostring(tag_label)
tag_value = tostring(tag_value)
output = mw.html.create( 'div' )
:css( 'padding', '10px')
:css( 'height', '1.5em' )
:css( 'text-align', 'center' )
:css( 'clear', 'left' )
:wikitext(tag_label..tag_value)
:done()
output = tostring(output)
end
return output
end
------------------------------------------------------------------------------------------
function p.add_horizontal_group(frame)
local args = getArgs (frame)
local centralheader = args['central_header'] or ''
local leftheader = args['left_header'] or ''
local lefttext = args['left_text'] or ''
local rightheader = args['right_header'] or ''
local righttext = args['right_text'] or ''
local totalwidth = args['total_width']
local tag_centralheader
local tag_leftheader
local tag_rightheader
local tag_lefttext
local tag_righttext
local output = ''
if not m.empty(righttext)
then
if not m.empty(totalwidth)
then totalwidth = tostring(tonumber(totalwidth)/2)..'px'
else totalwidth = '50%'
end
else totalwidth = '100%'
end
if not m.empty(centralheader)
then
tag_centralheader = mw.html.create( 'div' )
:css( 'width', '100%' )
:css( 'float', 'left' )
:css( 'font-weight', 'bold')
:wikitext(centralheader)
:done()
output = output..tostring(tag_centralheader)
else
tag_leftheader = mw.html.create( 'div' )
:css( 'width', totalwidth )
:css( 'float', 'left' )
:css( 'font-weight', 'bold')
:wikitext(leftheader)
:done()
output = output..tostring(tag_leftheader)
end
if not m.empty(righttext) and m.empty(centralheader)
then
tag_rightheader = mw.html.create( 'div' )
:css( 'width', totalwidth )
:css( 'float', 'left' )
:css( 'clear', 'right' )
:css( 'font-weight', 'bold')
:wikitext(rightheader)
:done()
output = output..tostring(tag_rightheader)
end
tag_lefttext = mw.html.create( 'div' )
:css( 'width', totalwidth )
:css( 'float', 'left' )
:css( 'clear', 'left' )
:wikitext(lefttext)
:done()
output = output..tostring(tag_lefttext)
if not m.empty(righttext)
then
tag_righttext = mw.html.create( 'div' )
:css( 'width', totalwidth )
:css( 'float', 'left' )
:css( 'text-align', 'center' )
:wikitext(righttext)
:done()
output = output..tostring(tag_righttext)
end
return tostring( mw.html.create( 'div' )
:css( 'border-top', '1px solid'..m.get_main_color(1) )
:css( 'text-align', 'center' )
--:css( 'clear', 'left' )
:wikitext(output)
:done() )
end
------------------------------------------------------------------------------------------
function p.add_section(header, section)
local output = ''
if not m.empty(section)
then output = m.header(header, 2)..'\n'..section
end
return output
end
------------------------------------------------------------------------------------------
function p.add_overview_and_toc(overview)
local output = '__TOC__'
if not m.empty(overview)
then output = overview..output
end
return output
end
------------------------------------------------------------------------------------------
function p.add_title(args)
local title = args['title']
local title_ref = args['title_ref']
local unofficial = args['unofficial']
local chinese_title = args['chinese_title']
local literal = args['literal']
local categories = {}
local output = mw.html.create('div')
:css('text-align', 'center')
:css('font-size', '150%')
:css('font-weight', 'bold')
:css( 'background', m.get_main_color(2))
:css( 'padding', '10px')
--:css( 'height', '5em' )
if m.empty(unofficial)
then
if m.empty(title_ref)
then
title_ref = ''
table.insert(categories, 'Citation Needed')
end
if not m.empty(chinese_title)
then chinese_title = '<br>'..chinese_title
else
chinese_title = ''
table.insert(categories, 'Chinese Variant Needed') --Pages without chinese title or name
end
else
title_ref = ''
chinese_title = ''
end
if m.empty(title)
then title = ''
end
if not m.empty(literal)
then literal = '<br>'..m.translation( {literal} )
else literal = ''
end
output = output:wikitext(title..title_ref..chinese_title..literal)
return tostring(output), categories
end
------------------------------------------------------------------------------------------
function p.add_appearances(first, last, last_header)
local chapters = require('Module:Chapters')
local header = 'Appearances'
local output_categories = {}
local output = {}
last_header = last_header or 'Last'
if m.empty(first)
then table.insert(output_categories, 'First Appearance Needed')
end
if not m.empty(first) or not m.empty(last)
then
output = { left_header = 'First',
left_text = chapters.lua_chapter_of_appearance(first),
right_header = last_header,
right_text = chapters.lua_chapter_of_appearance(last),
}
output = { p.add_horizontal_group(output) }
end
return p.add_group(output, header), output_categories
end
-----------------------------------------------------------------------------------------------
-- status alive/dead or existing/destroyed
function p.add_status(args, s_type)
local status = args.status
local last_appearance = args.last_appearance
local suicide
local suicide_name
local destroyed = {}
local killed = {}
local unconfirmed = s_type..'s with unconfirmed status'
local unknown = s_type..'s with unknown status'
local category = ''
local i
local value
local field_name
local category_name
local cause = ''
local categories = {}
local output = ''
if s_type == 'Character'
then
field_name = 'killed_by'
category_name = 'Killed by '
suicide_name = 'Suicide'
else
field_name = 'destroyed_by'
category_name = 'Destroyed by '
suicide_name = 'Self-Destruction'
end
if not m.empty(args.suicide)
then suicide = args.suicide
elseif not m.empty(args.self_destruction)
then suicide = args.self_destruction
else suicide = ''
end
if suicide ~= ''
then
if suicide == 'yes'
then
table.insert(categories, suicide_name)
cause_of_death = suicide_name
else
suicide = m.break_link(suicide, 1)
value = m.break_link(suicide, 2)
table.insert(categories, suicide_name)
table.insert(categories, category_name..suicide)
cause = suicide_name..'; forced by '..m.link(suicide, value)
end
end
for i = 1,10 do
value = args[field_name..i]
if not m.empty(value)
then
value = printf.get_text_comment_ref(value)
table.insert(categories, category_name..m.break_link(value.text,1) )
table.insert(destroyed, value.all)
end
end
if not m.empty(destroyed)
then cause = category_name..mw.text.listToText(destroyed)
end
--if not m.empty(args.destruction_cause)
-- then cause = args.destruction_cause
--end
if not m.empty(status)
then
if status == 'Exists'
then
category = 'Existing '..s_type..'s'
output = m.category_link(category, status)
table.insert(categories, category)
if not m.empty(last_appearance) or not m.empty(cause_of_destruction)
then table.insert(categories, unconfirmed)
end
elseif status == 'Destroyed'
then
category = 'Destroyed '..s_type..'s'
output = m.category_link(category, status)
table.insert(categories, category)
if m.empty(last_appearance)
then table.insert(categories, unconfirmed)
end
--if m.empty(cause_of_destruction)
-- then table.insert(categories, 'Cause of Destruction Needed')
--end
else
output = status
table.insert(categories, unknown)
end
elseif not m.empty(last_appearance) or not m.empty(cause_of_destruction)
then
category = 'Destroyed '..s_type..'s'
output = m.category_link(category, 'Destroyed')
table.insert(categories, category)
table.insert(categories, unconfirmed)
else
table.insert(categories, unknown)
end
return output, cause_of_destruction, categories
end
------------------------------------------------------------------------------------------
function p.add_navigation(text)
local tag = mw.html.create('div')
:css('clear', 'both')
:css('text-align', 'center')
:css('font-size', '80%')
:css('font-weight', 'bold')
:css( 'background', m.get_main_color(2))
:css( 'border-radius', '0px 0px 10px 10px' )
local output = ''
if not m.empty(text)
then output = tostring( tag:wikitext(text) )
end
return output
end
return p