Documentation for this module may be created at Module:Design/doc
local p = {}
local h = require("Module:HF")
local getArgs = require('Dev:Arguments').getArgs
--------------------------------------------------------------------------------------------
-- used in Template:Suit
function p.get_all_suit_images(frame)
local args = getArgs(frame)
local gallery_link = args.gallery_link
local i
local image
local image_text
local value
local output = {}
if h.isempty(gallery_link)
then
for i = 2, 30 do
image = args['Image'..i]
image_text = args['Image'..i..'_Text']
if not h.isempty(image)
then
if not h.isempty(image_text)
then value = image..'|'..(i - 1)..' - '..image_text
else value = image..'|'..(i - 1)
end
table.insert(output, value)
end
end
if not h.isempty(output)
then
output = '\n'..mw.text.listToText(output, '\n', '\n')
output = '<gallery widths="68px" position="center" captionalign="center" spacing="small">'..output..'</gallery>'
else
output = ''
end
else
for i = 2, 30 do
image = args['Image'..i]
image_text = args['Image'..i..'_Text']
if not h.isempty(image)
then
if not h.isempty(image_text)
then value = image..'|'..image_text
else value = image
end
table.insert(output, value)
end
end
if not h.isempty(output)
then
output = '\n'..mw.text.listToText(output, '\n', '\n')
gallery_link = 'See more images in '..h.Link(gallery_link, 'Gallery')
output = '<gallery widths="185px" position="center" captionalign="center" caption="'..gallery_link..'">'..output..'</gallery>'
else
output = ''
end
end
return frame:preprocess(output)
end
--------------------------------------------------------------------------------------------
function p.lua_create_navigation_gallery(list, noimage, crop, image_size, orientation, spacing, captionsize, position, captionalign)
local image
local text
local link1
local link2
local i
local div = mw.html.create('div'):addClass('navfaces')
local gallery = {}
local output = ''
if not h.isempty(list)
then
list = mw.text.split(list, '\n')
for i = 1, #list do
if string.find(list[i], ';') ~= nil
then text, image = string.match(list[i], '(.+);(.+)')
else
text = list[i]
image = noimage
end
link1 = string.match(text, '%[%[(.-)%]%]')
link2 = string.match(text, '%[%[(.-)%|.-%]%]')
if link2 ~= nil
then link1 = link2
end
table.insert(gallery, '\n'..image..'|'..text..'|link='..link1)
end
gallery = table.concat(gallery)
gallery = '<gallery widths="'..image_size..'" position="'..position..'" captionalign="'..captionalign..'" spacing="'..spacing..'" captionsize="'..captionsize..'" orientation="'..orientation..'" navigation="true">'..gallery..'</gallery>'
if h.isempty(crop) -- used to prevent cropping of images and focus on the top of the image
then output = tostring( mw.html.create('div'):addClass('navfaces'):wikitext(gallery) )
else output = gallery
end
end
return output
end
--------------------------------------------------------------------------------------------
-- used in Template:Navigation Gallery
function p.create_navigation_gallery(frame)
local args = getArgs(frame)
local list = args.list
local image_size = args.size or '150'
local noimage = args.noimage or 'No Image Available.png'
local orientation = args.orientation or 'square' -- none/landscape/portrait/square
local spacing = args.spacing or 'medium' -- small/medium/large
local crop = args.crop
local captionsize = args.captionsize or 'large'
local output = p.lua_create_navigation_gallery(list, noimage, crop, image_size, orientation, spacing, captionsize, 'center', 'center')
return frame:preprocess(output)
end
--------------------------------------------------------------------------------------------
-- used in Template:Residents Gallery
function p.create_residents_gallery(frame)
local args = getArgs(frame)
local i
local gallery
local description
local header
local section
local output = {}
for i = 1, 10 do
if not h.isempty(args['group'..i])
then
header = args['group'..i..'_header'] or ''
if not h.isempty(args['group'..i..'_description'])
then description = '\n'..args['group'..i..'_description']
else description = ''
end
gallery = p.lua_create_navigation_gallery(args['group'..i], 'No Image Available.png', _, '100', 'square', 'small', 'medium', 'center', 'center')
section = description..gallery
section = p.add_section(header, section, 3, 'center')
table.insert(output, tostring( mw.html.create('div'):wikitext(section) ) )
end
end
if #output > 0
then output = tostring( mw.html.create('div'):addClass('md-residents-gallery'):wikitext( table.concat(output) ) )
else output = ''
end
return frame:preprocess(output)
end
--------------------------------------------------------------------------------
-- used in Template:Speaker
function p.speaker(frame)
local args = getArgs(frame)
local link = args[1]
local text = args[2] or link
local category
if string.find(link, "Sign Language")
then
if link == "Sign Language"
then category = "Signers"
else category = "Signers of "..link
end
else
if link == 'Mandarin'
then link = 'Chinese'
end
category = "Speakers of "..link
end
return h.LinkToCategory(category, text)..h.Category(category)
end
--------------------------------------------------------------------------------
-- used in Template:Power Link and Template:Ability
function p.power_link(frame)
local list_of_powers = mw.loadData('Module:Character Template/Powers')
local list_of_abilities = mw.loadData('Module:Character Template/Abilities')
local args = getArgs (frame)
local type = args.type or 'power'
local link = args[1]
local text = args[2] or link
local link2
if type == 'power'
then link2 = list_of_powers[string.lower(link)]
else link2 = list_of_abilities[string.lower(link)]
end
link = link2 or link
return h.LinkToCategory(link, text)..h.Category(link)
end
--------------------------------------------------------------------------------
function p.green(text)
local output = ''
if not h.isempty(text)
then
output = mw.html.create( 'span' )
:addClass('green_text')
:wikitext('('..text..')')
:done()
output = tostring(output)
end
return output
end
--------------------------------------------------------------------------------
function p.span(text)
local italic = mw.html.create( 'span' ):css( 'font-style', 'italic' )
local bold = mw.html.create( 'span' ):css( 'font-weight', 'bold' )
local both = mw.html.create( 'span' ):css( 'font-weight', 'bold' ):css( 'font-style', 'italic' )
local output = { italic = '', bold = '', both = '' }
if not h.isempty(text)
then
output = {
italic = tostring(italic:wikitext(text):done()),
bold = tostring(bold:wikitext(text):done()),
both = tostring(both:wikitext(text):done()),
}
end
return output
end
---------------------------------------------------------------------------------------
-- used in Module:Volume_Template and Module:StandardizedName to format comic issues' story titles
function p.lua_get_comic_issue_story_title(story_title)
local output = ''
local tag = mw.html.create( 'span' )
:css( 'color', 'grey' )
:css( 'font-style', 'italic' )
if not h.isempty(story_title)
then
output = '"'..string.gsub(story_title, '"', '')..'"'
output = '<br />'..tostring( tag:wikitext(output):done() )
end
return output
end
--------------------------------------------------------------------------------
-- creates message box
function p.messagebox(frame)
local args = getArgs (frame, {parentOnly=true})
local width = args['width'] or '95%'
local textalign = args['text-align'] or 'center'
local fontsize = args['font-size'] or '100%'
local border = args['border']
local background = args['background']
local margin = args['margin'] or '1em'
local clear = args['clear'] or 'none'
local padding = args['padding'] or '5px'
local extrastyle = args['extrastyle'] or ''
local message = args[1] or args['Message'] or ''
local output_categories = p.lua_check_all_pages(mw.title.getCurrentTitle().text)
if args['width'] or args['text-align'] or args['font-size'] or args['border'] or args['background'] or args['margin'] or args['clear'] or args['padding'] or args['extrastyle']
then table.insert(output_categories, 'Outdated Fields/Messagebox')
end
local tag = mw.html.create( 'div' )
:attr( 'id', 'messageBox' )
:attr( 'align', 'center' )
:css( 'width', width )
:css( 'text-align', textalign )
:css( 'font-size', fontsize )
:css( 'border', '1px solid' )
:css( 'border-radius', '10px' )
:css( 'margin', margin )
:css( 'clear', clear )
:css( 'padding', padding )
:wikitext( message )
:done()
if not h.isempty(background)
then tag:css('background-color', background)
else tag:addClass('main_background_color')
end
if not h.isempty(border)
then tag:css('border-color', border)
else tag:addClass('main_border_color')
end
if not h.isempty(extrastyle)
then tag:cssText (extrastyle):done()
end
return tostring(tag)..h.add_categories(output_categories)
end
function p.lua_message(frame)
local args = getArgs (frame, {parentOnly=true})
local theme = args.theme or 'md-message--theme-main'
local output_categories = p.lua_check_all_pages(mw.title.getCurrentTitle().text)
local output = {}
if args.title
then table.insert(output, tostring( mw.html.create('div'):addClass('md-message__title'):wikitext(args.title) ))
end
if args.message
then table.insert(output, tostring( mw.html.create('div'):addClass('md-message__content'):wikitext(args.message) ))
end
if args.help
then table.insert(output, tostring( mw.html.create('div'):addClass('md-message__help'):wikitext(args.help) ))
end
if args.help2
then table.insert(output, tostring( mw.html.create('div'):addClass('md-message__help'):wikitext(args.help2) ))
end
if args.help3
then table.insert(output, tostring( mw.html.create('div'):addClass('md-message__help'):wikitext(args.help3) ))
end
output = table.concat(output)
return tostring( mw.html.create('div'):addClass('md-message'):addClass(theme):wikitext(output) )..h.add_categories(output_categories)
end
--------------------------------------------------------------------------------
-- creates message box with spoiler warning
function p.spoiler_warning()
return p.lua_message({
title = 'Spoiler Warning!',
message = 'This page may contain spoilers with plot and/or ending details about stories which have been only recently published or broadcast.',
help = 'See our '.. h.Link('Marvel Database:Spoilers', 'spoiler policy')..' for rules about such pages.',
theme = 'md-message--theme-spoiler'
})
end
--------------------------------------------------------------------------------
-- creates message box for stubs
function p.stub_message(frame)
return p.lua_message({
message = 'This article is a '.. h.Link('Marvel Database:Stubs', 'stub')..'. You can help Marvel Database by expanding it.'
})
end
--------------------------------------------------------------------------------
-- used in Template:Adaptation and Template:Adaptation2
function p.apocryphal_message()
return p.lua_message({
title = 'Apocryphal Subject Matter',
message = 'This article describes content which is adapted from other media and therefore may contain non-canonical elements which do not fit within accepted continuity.',
theme = 'md-message--theme-spoiler'
})
end
--------------------------------------------------------------------------------
-- used in Module:Category Message Templates and Module:Image Template
function p.lua_add_navigation_link(category, value, page_types)
local output = value
if h.pages_in_category(category, page_types) > 0
then output = h.LinkToCategory(category, value)
end
return output
end
--------------------------------------------------------------------------------
-- used in Module:Category Message Templates and Module:Image Template
function p.lua_add_navigation(navigation_list)
local separator = tostring( mw.html.create('div'):wikitext('·'))
local value
local output = {}
for i = 1, #navigation_list do
value = tostring( mw.html.create('div'):addClass('md-message__navigation-item'):wikitext(navigation_list[i]))
table.insert(output, value)
end
output = mw.text.listToText(output, separator, separator)
return tostring( mw.html.create('div'):addClass('md-message__navigation'):wikitext(output))
end
--------------------------------------------------------------------------------
-- creates table with "previous" and "next" sections
function p.table_previous_and_next(message, link_to_previous, link_to_next)
local td_left = mw.html.create('td')
:css('width', '10%')
:css('max-width', '20%')
:css('text-align', 'left')
local td_right = mw.html.create('td')
:css('width', '10%')
:css('max-width', '20%')
:css('text-align', 'right')
local td_left_arrow = mw.html.create('td')
:css('vertical-align', 'middle')
:css('font-size', '18px')
:css('width', '1%')
:wikitext('←')
local td_right_arrow = mw.html.create('td')
:css('vertical-align', 'middle')
:css('font-size', '18px')
:css('width', '1%')
:wikitext('→')
local td_empty = mw.html.create('td')
:css('width', '11%')
local tr = mw.html.create('tr')
local left = ''
local right = ''
local output = mw.html.create('table')
:css('width', '100%')
if h.isempty(message)
then message = ''
end
message = tostring( mw.html.create('td'):wikitext(message) )
if h.isempty(link_to_previous)
then left = tostring(td_empty)
else left = tostring(td_left_arrow)..tostring(td_left:wikitext(link_to_previous))
end
if h.isempty(link_to_next)
then right = tostring(td_empty)
else right = tostring(td_right:wikitext(link_to_next))..tostring(td_right_arrow)
end
tr = tostring( tr:wikitext(left..message..right) )
output = tostring( output:wikitext(tr) )
return output
end
--------------------------------------------------------------------------------
function p.show_hide(frame)
local args = getArgs (frame)
local title = args['title'] or args['header'] or ' '
local body = args['body'] or args['text'] or ''
local collapsed = args['collapsed']
local clear = args['clear'] or 'both'
local border = args['border']
local extrastyle = args['extrastyle']
local extrastyle2 = args['extrastyle2']
local extrastyle3 = args['extrastyle3']
local titlestyle = args['titlestyle']
local width = args['width'] or '100%'
local background = args['background']
local expandtext = args['expandtext'] or 'Expand'
local collapsetext = args['collapsetext'] or 'Collapse'
if h.isempty(collapsed) or collapsed == 'true' or collapsed == true
then collapsed = ' mw-collapsed'
else collapsed = ''
end
body = mw.html.create( 'div' )
:addClass('mw-collapsible-content')
:css('background-color', 'transparent')
:wikitext('\n'..body)
:done()
if not h.isempty(extrastyle3)
then body:cssText (extrastyle3):done()
end
body = tostring(body)
title = mw.html.create( 'div' )
:css('font-weight', 'bold')
:wikitext(title)
:done()
if not h.isempty(background)
then title:css('background-color', background)
else title:addClass('main_background_color')
end
if not h.isempty(titlestyle)
then title:cssText (titlestyle):done()
end
if not h.isempty(extrastyle2)
then title:cssText (extrastyle2):done()
end
title = tostring(title)
body = mw.html.create( 'div' )
:addClass('mw-collapsible'..collapsed)
:attr('data-expandtext', expandtext)
:attr('data-collapsetext', collapsetext)
:css( 'width', width )
:css( 'border', '1px solid' )
:css( 'font-size', '12px' )
:css( 'clear', clear )
:wikitext(title..body)
:done()
if not h.isempty(border)
then body:css('border-color', border)
else body:addClass('main_border_color')
end
if not h.isempty(extrastyle)
then body:cssText (extrastyle):done()
end
return tostring(body)
end
--------------------------------------------------------------------------------
function p.add_header(text, level, align)
local output = ''
level = level or '2'
align = align or 'left'
if not h.isempty(text)
then output = '\n'..tostring( mw.html.create( 'h'..level ):css('text-align', align):addClass('marvel_database_header'):wikitext( text ) )
end
return output
end
--------------------------------------------------------------------------------
function p.lua_add_tooltip(text, tooltip)
local output = mw.html.create('span'):addClass('tooltip'):attr('title', tooltip):wikitext(text)
return tostring(output)
end
--*******************************************************************************************
-- ************* functions for related sites *************
local list_of_sites = {
['Marvel'] = {'http://www.marvel.com', 'Marvel.com', 'http://www.marvel.com/characters/'},
['Wikipedia'] = {'Wikipedia', 'Wikipedia.org'},
['IMDB'] = {'http://www.imdb.com', 'IMDB.com', 'http://www.imdb.com/title/tt'},
['AM'] = {'http://www.allmovie.com', 'AllMovie.com', 'http://www.allmovie.com/movie/'},
['MCU'] = {'w:c:marvelcinematicuniverse', 'Marvel Cinematic Universe wiki'}, -- https://marvelcinematicuniverse.fandom.com/wiki/
['MM'] = {'w:c:marvel-movies', 'Marvel Movies wiki'}, -- https://marvel-movies.fandom.com/wiki/
['SMF'] = {'w:c:spiderman-films', 'Spider-Man Films wiki'}, -- https://spiderman-films.fandom.com/wiki/
['XM'] = {'w:c:xmenmovies', 'X-Men Movies wiki'}, -- https://xmenmovies.fandom.com/wiki/
['Appendix'] = {'http://www.marvunapp.com', 'the Appendix to the Handbook of the Marvel Universe', 'http://www.marvunapp.com/'}
}
--------------------------------------------------------------------------------
-- used in Marvel Database:Film Template
function p.get_related_site_label(frame)
local args = getArgs(frame)
local site = args[1]
local info = list_of_sites[site]
if h.in_list({'IMDB', 'AM', 'Marvel', "Appendix"}, site)
then output = 'on ['..info[1]..' '..info[2]..']'
elseif site == 'Wikipedia'
then output = 'on '..h.Link(info[1]..':', info[2])
else output = 'on '..h.Link(info[1], info[2])
end
return output
end
--------------------------------------------------------------------------------
-- used in Marvel Database:Film Template
function p.get_related_site_link(frame)
local args = getArgs(frame)
local site = args[1]
local link = args[2]
local text = args[3]
local info = list_of_sites[site]
local output = ''
if not h.isempty(link)
then
if h.isempty(text)
then text = link
end
if h.in_list({'IMDB', 'AM', 'Marvel', 'Appendix'}, site)
then output = '['..info[3]..link..' '..text..']'
else output = h.Link(info[1]..':'..link, text)
end
end
return output
end
--*******************************************************************************************
-- ************* functions for INFOBOX templates (most of them are called from 'Marvel Database:__' templates, like 'Marvel Database:Character Template') *************
--------------------------------------------------------------------------------
function p.lua_check_all_pages(pagename)
local pagecontent = h.get_content(pagename)
local lowercontent = string.lower(pagecontent)
local ml = string.find(lowercontent, '{{r|{{ml|', 1, true) ~= nil or string.find(lowercontent, '<ref>{{ml|', 1, true) ~= nil
local vl = string.find(lowercontent, '{{r|{{vl|', 1, true) ~= nil or string.find(lowercontent, '<ref>{{vl|', 1, true) ~= nil
local cl = string.find(lowercontent, '{{r|{{cl|', 1, true) ~= nil --or string.find(lowercontent, '<ref>{{cl|', 1, true) ~= nil
local sl = string.find(lowercontent, '{{r|{{sl|', 1, true) ~= nil or string.find(lowercontent, '<ref>{{sl|', 1, true) ~= nil
local wp = string.find(lowercontent, '{{r|{{wp|', 1, true) ~= nil --or string.find(lowercontent, '<ref>{{wp|', 1, true) ~= nil
local cite = string.find(lowercontent, '{{r|{{cite', 1, true) ~= nil or string.find(lowercontent, '<ref>{{cite', 1, true) ~= nil
local appendix = string.find(lowercontent, 'marvunapp', 1, true) ~= nil
local value
local list = {'dc', 'avp', 'image', 'imagecomics', 'darkhorse', 'valiant', 'startrek', 'memory-alpha', 'starwars', 'wookieepedia', 'disney', 'fortnite', 'lovecraft', 'mcu', 'marvelcinematicuniverse', 'tardis', 'doctorwho', 'conan', 'bighero6', 'transformers', 'muppet', 'muppets', 'lotr', 'brickipedia', 'lego', 'gijoe'}
local output_categories = {}
if ml
then table.insert(output_categories, 'References With Ml Template')
end
if vl
then table.insert(output_categories, 'References With Vl Template')
end
if cl
then table.insert(output_categories, 'References With Cl Template')
end
if sl
then table.insert(output_categories, 'References With Sl Template')
end
if cite
then table.insert(output_categories, 'References With Cite Template')
end
if wp
then table.insert(output_categories, 'References With WP Template')
end
if not ml and not vl and not cl and not sl and not cite and not wp and string.find(lowercontent, '{{r|{{', 1, true) ~= nil
then table.insert(output_categories, 'References With Other Templates')
end
if appendix
then table.insert(output_categories, 'Pages With Links To Marvel Appendix')
end
if string.find(lowercontent, 'historytext')
then table.insert(output_categories, 'Articles with HistoryText')
end
return output_categories
end
--------------------------------------------------------------------------------
-- Conditionally wraps an infobox field value in a collapsible div.
--
p.COLLAPSIBLE_MAX_LINES = 9
local COLLAPSIBLE_MAX_LINES = p.COLLAPSIBLE_MAX_LINES
function p.count_lines(text)
local s = text
s = string.gsub(s, '</[Bb][Rr]>', '\n')
s = string.gsub(s, '<[Bb][Rr]%s*/>', '\n')
s = string.gsub(s, '<[Bb][Rr]%s*>', '\n')
local n = 0
for line in string.gmatch(s .. '\n', '([^\n]*)\n') do
if string.find(line, '%S') then
n = n + 1
end
end
return n
end
local count_lines = p.count_lines
function p.add_infobox_row_collapsible(frame)
local args = getArgs(frame)
local value = args[1]
local output = ''
if h.isempty(value) then return output end
if not h.isempty(args.no_collapse) then
return value
end
if string.find(value, 'mw-collapsible', 1, true) ~= nil then
return value
end
if string.find(value, '{{Navigation', 1, true) ~= nil
or string.find(value, 'navfaces', 1, true) ~= nil then
return value
end
local fi, fj = string.find(string.lower(value), '; formerly ')
local ki, kj = string.find(string.lower(value), 'formerly:')
if fi ~= nil or ki ~= nil then
local current_part, formerly_part
if fi ~= nil then
current_part = string.sub(value, 1, fi - 1)
formerly_part = string.sub(value, fj + 1)
else
current_part = string.sub(value, 1, ki - 1)
formerly_part = string.sub(value, kj + 1)
end
local formerly_block
if count_lines(formerly_part) > COLLAPSIBLE_MAX_LINES then
formerly_block = p.show_hide({
title = 'Formerly',
body = formerly_part,
collapsed = 'true',
extrastyle = 'border: none;',
})
else
formerly_block = tostring(
mw.html.create('div')
:wikitext("\n'''" .. "Formerly:" .. "'''\n" .. formerly_part)
)
end
return current_part .. '<br>' .. formerly_block
end
if count_lines(value) > COLLAPSIBLE_MAX_LINES then
return p.show_hide({
title = '',
body = value,
collapsed = 'true',
extrastyle = 'border: none;',
})
end
return value
end
--------------------------------------------------------------------------------
function p.add_infobox_page_title(frame)
local standard = require("Module:StandardizedName")
local m_date = require("Module:Date")
local pagename = mw.title.getCurrentTitle().text
local pagecontent = h.get_content(pagename)
local sortname = ''
local args = getArgs (frame)
local page_type = args.page_type
local title = args.Title or args.EpisodeTitle
local alias = args.CurrentAlias
local name = args.Name
local image = args.Image
local noimage = args.NoImage
local info
local taskdate = h.get_field_value(pagecontent, "date_time")
local output_categories = p.lua_check_all_pages(pagename)
local output = ''
if not h.isempty(title)
then output = title
elseif not h.isempty(alias)
then output = alias
elseif not h.isempty(name)
then output = name
else output = string.gsub(pagename, ' %(.+%)', '')
end
if not h.is_link(output) and h.exists(output)
then output = h.Link(output)
end
if page_type == 'Episode'
then output = '"'..string.gsub(output, '"', '')..'"'
end
if taskdate == nil
then taskdate = ''
else taskdate = 'TASKDATE:' .. taskdate..';'
end
-- add default sort name
if page_type == 'Reality'
then
table.insert(output_categories, 'Realities')
sortname = '{{DEFAULTSORT:'..require("Module:Reality").get_reality_info({pagename}).padded_number..taskdate..'|noerror}}'
elseif page_type == 'Series'
then
sortname = '{{DEFAULTSORT:'..standard.lua_remove_the(pagename)..taskdate..'|noerror}}'
elseif h.in_list({'Feature Film','Short Film','Web Film','Stage Performance','Video Game', 'Novel'}, page_type)
then
local release_date = args['Release Date'] or ''
local sort_date = ''
local year = string.match(release_date, '^(%d%d%d%d)$')
local month
if year == nil
then
month, year = string.match(release_date, '^(%D+), (%d%d%d%d)$')
if year == nil
then
local release_info = m_date.lua_get_release_date_info(release_date)
if release_info.date ~= ''
then sort_date = release_info.year..m_date.get_month_number({release_info.month})..h.AddZeros(release_info.day, 2)
end
else
sort_date = year..m_date.get_month_number({month})..'00'
end
else
sort_date = year..'0000'
end
table.insert(output_categories, page_type..'s')
sortname = '{{DEFAULTSORT: '..sort_date..' '..standard.lua_remove_the(pagename)..taskdate..'MEDIA:'..page_type..';|noerror}}'
elseif page_type == 'Episode'
then
info = standard.lua_get_title_volume_issue(pagename, 'Season')
if not h.isempty(info.title)
then sortname = info.sortname.all
else sortname = standard.lua_remove_the(pagename)
end
local year = args.Year
local month = args.Month
local day = args.Day or 0
if not h.isempty(year) and not h.isempty(month) and not h.isempty(day)
then sortname = ' '..year..m_date.get_month_number({month})..h.AddZeros(day, 2)..' '..sortname
end
sortname = '{{DEFAULTSORT:'..sortname..taskdate..'MEDIA:Episode;|noerror}}__NOTOC__'
table.insert(output_categories, page_type..'s')
table.insert(output_categories, info.noissue)
elseif page_type == 'Creator'
then
table.insert(output_categories, 'Creators')
sortname = '{{DEFAULTSORT:'..pagename..taskdate..'|noerror}}'
elseif page_type == 'Event' and args.EditorialEvent == 'Yes'
then
table.insert(output_categories, 'Editorial Events')
sortname = '{{DEFAULTSORT:'..standard.name_for_sorting({pagename})..taskdate..'|noerror}}'
else
table.insert(output_categories, page_type..'s')
sortname = '{{DEFAULTSORT:'..standard.name_for_sorting({pagename})..taskdate..'|noerror}}'
end
-- add categories for main image
if not h.isempty(image)
then
image = string.gsub(image, 'File:', '')
if not h.exists('File:'..image) -- 'Image' field is filled, but such image doesn't exist on wiki
then table.insert(output_categories, page_type..' Image Correction Needed')
end
if h.in_list({'None.jpg', 'Needed.png'}, image)
then table.insert(output_categories, page_type..' Image Needed')
end
elseif not h.isempty(noimage) and string.lower(noimage) == 'yes'
then table.insert(output_categories, 'Unseen '..h.get_plural_page_type(page_type) )
else table.insert(output_categories, page_type..' Image Needed')
end
return frame:preprocess(output..sortname)..h.add_categories(output_categories)
end
--------------------------------------------------------------------------------
function p.add_infobox_gallery(frame)
local pagename = mw.title.getCurrentTitle().text
local args = getArgs (frame)
local page_type = args.page_type
local noimage = args.NoImage
local nogallery = args.NoGallery
local image = args.Image
local image_text = args.ImageText
local n = h.pages_in_category(pagename..'/Images', 'files')
local output_categories = {}
local output = ''
if h.isempty(nogallery)
then
if h.exists(pagename..'/Gallery')
then output = h.Link(pagename..'/Gallery', 'Gallery')
elseif h.isempty(noimage) and page_type ~= 'User' and page_type ~= 'Creator' and n > 1
then
output = h.Link(pagename..'/Gallery', 'Gallery')
table.insert(output_categories, page_type..' Gallery Page Needed')
end
elseif not h.isempty(image_text)
then output = tostring(image_text)
end
return output..h.add_categories(output_categories)
end
-------------------------------------------------------------------------------
function p.add_infobox_official_name(frame)
local args = getArgs (frame)
--local page_type = args.page_type
local name = args.Name
local name2 = args.Name2
local ref = args.NameRef
local output = ''
if not h.isempty(args.Name)
then
name = args.Name
name2 = args.Name2
ref = args.NameRef
elseif not h.isempty(args.OfficialName)
then
name = args.OfficialName
name2 = args.OfficialName2
ref = args.OfficialNameRef
elseif not h.isempty(args.RealName)
then
name = args.RealName
name2 = args.RealName2
ref = args.RealNameRef
end
if h.isempty(name)
then output = 'Unrevealed'
else
output = name
if not h.is_link(output) and h.exists(output)
then output = h.Link(output)
end
end
if not h.isempty(name2)
then output = output..' '..name2
end
if not h.isempty(ref)
then output = output..ref
end
return output
end
--------------------------------------------------------------------------------
function p.add_infobox_first_appearance(frame)
local standard = require("Module:StandardizedName")
local args = getArgs(frame)
local page_type = args.page_type
local value = args.First
local value2 = args.First2
local no_wiki_value
local debut
local output_categories = {}
local output = ''
if not h.isempty(value)
then
no_wiki_value = mw.text.nowiki(value)
if mw.ustring.find(no_wiki_value, '[[', 1, true) ~= nil
then
debut = string.match(no_wiki_value, '(%d%d%d%d)]]%)') or string.match(no_wiki_value, '(%d%d%d%d)%)')
output = value
else
output, debut = standard.lua_get_link_and_release_date(value)
if not h.isempty(debut)
then debut = string.match(debut, '(%d%d%d%d)')
end
end
if not h.isempty(debut)
then
if not h.isempty(page_type)
then table.insert(output_categories, debut..' '..page_type..' Debuts')
else table.insert(output_categories, debut..' Debuts')
end
end
elseif h.isempty(value2)
then
if not h.isempty(page_type)
then value = page_type..' First Appearance Needed'
else value = 'First Appearance Needed'
end
table.insert(output_categories, value)
output = h.LinkToCategory(value, 'Unknown')
end
if not h.isempty(value2)
then output = output..value2
end
return output..h.add_categories(output_categories)
end
--------------------------------------------------------------------------------
function p.add_infobox_last_appearance(frame)
local standard = require("Module:StandardizedName")
local args = getArgs(frame)
local last_appearance
local last_appearance2
local output = ''
if not h.isempty(args.Death) or not h.isempty(args.Death2)
then -- for 'Character Template'
last_appearance = args.Death
last_appearance2 = args.Death2
elseif not h.isempty(args.Destruction) or not h.isempty(args.Destruction2)
then -- for 'Item Template', 'Vehicle Template', 'Location Template', 'Reality Template'
last_appearance = args.Destruction
last_appearance2 = args.Destruction2
else -- for 'Team Template', 'Organization Template', 'Race Template'
last_appearance = args.Last
last_appearance2 = args.Last2
end
if not h.isempty(last_appearance)
then
if mw.ustring.find(mw.text.nowiki(last_appearance), '[[', 1, true) ~= nil
then output = last_appearance
elseif string.find(string.lower(last_appearance), 'off-panel', 1, true) ~= nil
then output = 'Off-panel'
else output = standard.lua_get_link_and_release_date(last_appearance)
end
end
if not h.isempty(last_appearance2)
then output = output..last_appearance2
end
return output
end
--------------------------------------------------------------------------------
function p.add_infobox_creators(frame)
local SC = require("Module:StaffCorrection")
local args = getArgs(frame)
local page_type = args.page_type
local creators = args.Creators
local creators2 = args.Creators2
local output_categories = {}
local output = ''
if not h.isempty(creators)
then output, output_categories = SC.lua_get_creators(creators)
elseif not h.isempty(creators2)
then output = output..creators2
else table.insert(output_categories, page_type..' Creators Needed')
end
return output..h.add_categories(output_categories)
end
--------------------------------------------------------------------------------------------------
function p.add_infobox_identity(frame)
local args = getArgs (frame)
local page_type = args.page_type
local value = args.Identity
local category = ''
if not h.isempty(value)
then
category = value..' Identity '..page_type..'s'
value = h.LinkToCategory(category, value)
category = h.Category(category)
else value = ''
end
if not h.isempty(args.Identity2)
then value = value..' '..args.Identity2
end
return value..category
end
--------------------------------------------------------------------------------------------------
function p.add_infobox_status(frame)
local args = getArgs (frame)
local status = args.Status
local status_lower = string.lower(args.Status)
local page_type = h.get_plural_page_type(args.page_type)
local output_category = ''
local output = ''
if ( page_type == 'Realities' and h.in_list({'existing', 'destroyed', 'merged'}, status_lower) )
or ( page_type == 'Species' and status_lower == 'extinct' )
then
output_category = status..' '..page_type
output = h.LinkToCategory(output_category, status)
end
if h.in_list({'Organizations', 'Teams'}, page_type)
then
if h.in_list({'active', 'exist', 'exists', 'existing'}, status_lower)
then
output_category = 'Active '..page_type
output = h.LinkToCategory(output_category, 'Active')
elseif h.in_list({'defunct', 'disbanded', 'inactive'}, status_lower)
then
output_category = 'Defunct '..page_type
output = h.LinkToCategory(output_category, 'Defunct')
end
end
if status_lower == 'unknown'
then
output_category = page_type..' With Unknown Status'
output = h.LinkToCategory(output_category, status)
end
if output == ''
then
output_category = 'Status Correction Needed'
output = h.LinkToCategory(output_category, status)
end
return output..h.Category(output_category)
end
--------------------------------------------------------------------------------------------------
function p.add_infobox_members_group_header(frame)
local pagename = mw.title.getCurrentTitle().text
local category = pagename..'/Members'
local n = h.pages_in_category(category, 'pages')
local output = 'Members'
if n > 0
then output = h.LinkToCategory(category, output)
end
return output
end
--------------------------------------------------------------------------------
function p.add_infobox_reality(frame)
local module_reality = require("Module:Reality")
local args = getArgs (frame)
local page_type = args.page_type
local pagename = mw.title.getCurrentTitle().text
local i
local reality1 = args.Reality
local reality2 = args.Reality2
local reality_from_pagename
local dimension = ''
local value
local category
local output_categories = {}
local output = {}
if string.find(pagename, '(', 1, true) ~= nil
then
_, reality_from_pagename = module_reality.lua_get_name_and_reality(pagename)
end
if h.isempty(reality1) and h.isempty(reality2)
then
if h.in_list({'/Characters', '/Teams', '/Organizations'}, page_type)
then table.insert(output_categories, 'Unspecified Reality')
end
if not h.isempty(reality_from_pagename)
then reality1 = reality_from_pagename.name
end
end
if not h.isempty(reality1)
then
reality1 = mw.text.split(reality1, ';')
for i = 1, #reality1 do
value = h.trim(reality1[i])
if not h.isempty(reality_from_pagename) and not h.isempty(reality_from_pagename.dimension) and (reality_from_pagename.name == value or reality_from_pagename.number == value)
then
dimension = h.Link(reality_from_pagename.dimension.link, reality_from_pagename.dimension.name..' '..reality_from_pagename.dimension.type)
table.insert(output, h.Link(reality_from_pagename.name)..' ('..dimension..')')
table.insert(output_categories, reality_from_pagename.name..page_type)
table.insert(output_categories, reality_from_pagename.dimension.name..page_type)
else
value = module_reality.get_reality_info({value, 1})
if value ~= nil
then
table.insert(output, h.Link(value))
table.insert(output_categories, value..page_type)
end
end
end
end
if not h.isempty(reality2)
then
value = module_reality.get_reality_info({reality2, 1})
if value ~= nil
then
table.insert(output, h.Link(value))
table.insert(output_categories, value..page_type)
else
table.insert(output, reality2)
end
end
output = mw.text.listToText(output, ', ', ', ')
return output..h.add_categories(output_categories)
end
--------------------------------------------------------------------------------------------------
-- used for 'ProductionCompanies' and 'Network' fields in 'Film Template' and 'Series Template'
function p.get_value_and_category_from_field(frame)
local args = getArgs(frame)
local field = args.field
local i
local value = ''
local output_categories = {}
local output = ''
if not h.isempty(field)
then
field = h.explode(";", field)
output = {}
for i = 1, #field do
value = h.trim(field[i])
if h.exists('Category:'..value)
then
table.insert(output_categories, value)
value = h.LinkToCategory(value, value)
end
table.insert(output, value)
end
output = mw.text.listToText(output, ', ', ', ')
end
return output..h.add_categories(output_categories)
end
--------------------------------------------------------------------------------
function p.add_overview_and_toc(overview)
local output = '__TOC__'
if not h.isempty(overview)
then output = '\n'..overview..'<br>'..output
end
return output
end
--------------------------------------------------------------------------------
function p.add_quote(args, speaker_needed, source_needed)
local output_categories = {}
local output = ''
if not h.isempty(args.Quotation)
then output, output_categories = require("Module:Quote").main(args.Quotation, args.Speaker, args.QuoteSource, speaker_needed, source_needed)
end
if not h.isempty(args.BlockQuote)
then
output = args.BlockQuote
table.insert(output_categories, 'BlockQuotes')
end
return output, output_categories
end
--------------------------------------------------------------------------------
-- used to add sections like "Notes", "Trivia", etc.
function p.add_section(header, section, header_level, header_align)
local output_categories = p.lua_check_all_pages(mw.title.getCurrentTitle().text)
local output = ''
header_level = header_level or 2
if not h.isempty(section)
then
section = tostring( mw.html.create('div'):addClass('marvel_database_section'):wikitext( '\n'..section ) )
output = p.add_header(header, header_level, header_align)..section
end
return output..h.add_categories(output_categories)
end
--------------------------------------------------------------------------------
function p.add_history_section(args, page_type)
local value = args.History or args.HistoryText
local category = ''
local output = ''
if h.isempty(value)
then category = page_type..' Stubs'
else
output = p.add_section('History', value, 2)
if args.HistoryText
then category = 'Articles with HistoryText'
end
end
return output, category
end
--------------------------------------------------------------------------------
-- one function to add 'Quote', 'Overview' section, 'TOC' and 'History' section at the same time
function p.add_quote_overview_toc_history(args, page_type)
local value
local categories = {}
local output_categories = {}
local output = {}
value, categories = p.add_quote(args)
output_categories = h.join_tables(output_categories, categories)
table.insert(output, value)
table.insert( output, p.add_overview_and_toc(args.Overview) )
value, categories = p.add_history_section(args, page_type)
output_categories = h.join_tables(output_categories, categories)
table.insert(output, value)
return output, output_categories
end
--------------------------------------------------------------------------------
-- one function to add 'Notes', 'Trivia', 'See Also', 'Recommended Reading' and 'Links and References' sections at the same time
function p.add_notes_trivia_see_also_recommended_links_references(args, page_type, pagename)
local value
local categories = {}
local output_categories = {}
local output = {}
table.insert( output, p.add_section('Accolades', args.Accolades, 2) )
table.insert( output, p.add_section('Notes', args.Notes, 2) )
table.insert( output, p.add_section('Trivia', args.Trivia, 2) )
table.insert( output, p.add_header('See Also', 2) )
--add links to standard sub-pages/categories - "Appearances", "Minor Appearances", Mentions", "Images", "Quotes"
value, categories = p.add_links_to_standard_subpages(pagename, page_type)
output_categories = h.join_tables(output_categories, categories)
output = h.join_tables(output, value)
table.insert( output, p.add_section('Recommended Reading', args.Recommended, 2) )
table.insert( output, p.add_links_and_references(args, pagename) )
return output, output_categories
end
--------------------------------------------------------------------------------
-- used to add links to standard sub-pages/categories - "Appearances", "Minor Appearances", Mentions", "Images", "Quotes"
function p.add_links_to_standard_subpages(pagename, page_type)
local list_for_reality = {'Characters', 'Teams', 'Organizations', 'Locations', 'Items', 'Vehicles', 'Races'}
local s = ''
local nation_info
local value
local category
local output_categories = {}
local output = {}
value, categories = p.links_to_subcategories(pagename..'/Appearances', 'pages', pagename, ' appearance(s) of ', page_type..' Appearances Category Needed')
output_categories = h.join_tables(output_categories, categories)
table.insert(output, value)
value, categories = p.links_to_subcategories(pagename..'/Handbook Appearances', 'pages', pagename, ' appearance(s) in handbook(s) of ', page_type..' Appearances Category Needed')
output_categories = h.join_tables(output_categories, categories)
table.insert(output, value)
value, categories = p.links_to_subcategories(pagename..'/Minor Appearances', 'pages', pagename, ' minor appearance(s) of ', page_type..' Minor Appearances Category Needed')
output_categories = h.join_tables(output_categories, categories)
table.insert(output, value)
value, categories = p.links_to_subcategories(pagename..'/Mentions', 'pages', pagename, ' mention(s) of ', page_type..' Mentions Category Needed')
output_categories = h.join_tables(output_categories, categories)
table.insert(output, value)
value, categories = p.links_to_subcategories(pagename..'/Handbook Mentions', 'pages', pagename, ' mention(s) in handbook(s) of ', page_type..' Mentions Category Needed')
output_categories = h.join_tables(output_categories, categories)
table.insert(output, value)
value, categories = p.links_to_subcategories(pagename..'/Invocations', 'pages', pagename, ' invocation(s) of ', page_type..' Mentions Category Needed')
output_categories = h.join_tables(output_categories, categories)
table.insert(output, value)
if h.in_list({'Film', 'Series', 'Episode', 'Video Game', 'Board Game', 'Novel'}, page_type)
then value, categories = p.links_to_subcategories(pagename..'/Images', 'files', pagename, ' image(s) from ', page_type..' Images Category Needed')
else value, categories = p.links_to_subcategories(pagename..'/Images', 'files', pagename, ' image(s) of ', page_type..' Images Category Needed')
end
output_categories = h.join_tables(output_categories, categories)
table.insert(output, value)
value, categories = p.links_to_subcategories(pagename..'/Quotes', 'pages', pagename, ' quotation(s) by or about ', 'Quotes Category Needed')
output_categories = h.join_tables(output_categories, categories)
table.insert(output, value)
value, categories = p.links_to_subcategories('Killed by '..pagename, 'pages', pagename, ' victim(s) killed by ', 'Killed By Category Needed')
output_categories = h.join_tables(output_categories, categories)
table.insert(output, value)
if page_type == 'Team' or page_type == 'Organization'
then
value, categories = p.links_to_subcategories(pagename..'/Members', 'pages', pagename, ' member(s) of ', 'Members Category Needed')
output_categories = h.join_tables(output_categories, categories)
table.insert(output, value)
end
if page_type == 'Race'
then
value, categories = p.links_to_subcategories(string.gsub(pagename, '%(Race%)', ''), 'pages', pagename, ' representative(s) of ', 'Race Category Needed')
output_categories = h.join_tables(output_categories, categories)
table.insert(output, value)
end
if h.in_list({'Location', 'Event', 'Storyline', 'Story Arc'}, page_type)
then
value, categories = p.links_to_subcategories(pagename, 'pages', pagename, ' article(s) related to ', page_type..' Category Needed')
output_categories = h.join_tables(output_categories, categories)
table.insert(output, value)
if page_type == 'Location'
then
nation_info = mw.loadData('Module:Nation and Citizenship')
nation_info = nation_info[string.lower(pagename)]
if nation_info ~= nil
then
value, categories = p.links_to_subcategories(nation_info.d_categories[1], 'pages', pagename, ' citizen(s) of ', page_type..' Category Needed')
output_categories = h.join_tables(output_categories, categories)
table.insert(output, value)
end
end
end
if page_type ~= 'Reality'
then
value, categories = p.links_to_subcategories(pagename..'/Items', 'pages', pagename, ' item(s) used/owned by ', 'Items Category Needed')
output_categories = h.join_tables(output_categories, categories)
table.insert(output, value)
else
for i = 1, #list_for_reality do
s = ' '..string.lower(list_for_reality[i])
value, categories = p.links_to_subcategories(pagename..'/'..list_for_reality[i], 'pages', pagename, s..' that originate from ', list_for_reality[i]..' Category Needed')
output_categories = h.join_tables(output_categories, categories)
table.insert(output, value)
end
end
if page_type ~= 'Creator' and table.concat(output) == ''
then table.insert(output_categories, page_type..' Articles with no Subcategories')
end
return output, output_categories
end
function p.links_to_subcategories(category, page_types, pagename, text, needed)
local n = h.pages_in_category(category, page_types)
local output_category = ''
local output = ''
if n > 0
then
output = '\n* '..h.LinkToCategory(category, n..text..pagename)
if not h.exists('Category:'..category)
then output_category = needed
end
end
return output, output_category
end
--------------------------------------------------------------------------------
function p.add_links_and_references(args, pagename)
local module_reality = require("Module:Reality")
local name_without_reality = module_reality.lua_get_name_and_reality(pagename)
local list_of_links1 = {"Marvel", "Wikipedia", "IMDB ID", "AM ID", "MCU", "Appendix", "Marvel Movies", "X-Men Movies", "Spider-Man Films"}
local list_of_links2 = {"Marvel", "Wikipedia", "IMDB", "AM", "MCU", "Appendix", "MM", "XM", "SMF"}
local i
local value
local output = {}
table.insert(output, p.add_header('Links and References', 2) )
for i = 1, #list_of_links1 do
value = list_of_links1[i]
if not h.isempty(args[value])
then
if h.isempty(name_without_reality)
then name_without_reality = pagename
end
value = p.get_related_site_link({list_of_links2[i], args[value], name_without_reality})..' '..p.get_related_site_label({list_of_links2[i]})
table.insert(output, '\n*'..value)
end
end
value = args.OfficialWebsite
if not h.isempty(value)
then
--value = '<span class="plainlinks">['..value..' Official website of '..pagename..']</span>'
table.insert(output, '\n'..value)
end
value = args.Links
if not h.isempty(value)
then table.insert(output, '\n'..value)
end
table.insert(output, p.add_list_of_references() )
return table.concat(output)
end
--------------------------------------------------------------------------------
function p.add_list_of_references()
local output = mw.html.create('div')
:css('overflow', 'auto')
:css('height', 'auto')
:css('max-height', '250px')
:css('width', '99%')
:css('font-size', '12px')
:css('border', '1px solid #AAAAAA')
:wikitext('<references group="note" /><references />')
return p.add_header('References', 3)..'\n'..tostring(output)
end
--------------------------------------------------------------------------------
--[[ used in templates for all main articles:
* Marvel Database:Character Template
* Marvel Database:Location Template
* Marvel Database:Race Template
* Marvel Database:Reality Template
* Marvel Database:Item Template
* Marvel Database:Vehicle Template
* Marvel Database:Team Template
* Marvel Database:Organization Template
]]--
function p.add_message_for_main_articles(frame)
local args = getArgs(frame)
local pagename = mw.title.getCurrentTitle().text
local link_to_trn = h.Link('Marvel Database:Temporary Reality Numbers Policy', 'this page')
local trn = string.match(pagename, '.?(Earth%-TRN%d+).?')
local trn_message = ''
local stub_message = ''
local mcu_link = ''
local mcu = args.MCU
local mcu_message = ""
local mcu_image = ''
-- TRN message
if trn ~= nil
then
trn_message = 'The designation "' .. trn .. '" of this article is entirely ' .. p.span('unofficial').bold .. ' and is used by this wiki for internal purposes ' .. p.span('only').italic .. ' until an official designation is provided by Marvel.'
trn_message = p.lua_message({message = trn_message, help = '(For more information on TRNs, go to '..link_to_trn..')'})
end
-- Stub message
if h.isempty(args.History) and h.isempty(args.HistoryText)
then stub_message = p.stub_message(frame)
end
if not h.isempty(mcu)
then
mcu_link = list_of_sites['MCU'][1]..':'..mcu
mcu_image = h.Link('File:Marvel Cinematic Universe.png', 'frameless|120px|link='..mcu_link)
mcu_message = "For a more in-depth coverage of this page's subject, visit "..h.Link(mcu_link, 'its article').." on the "..mcu_image
mcu_message = p.lua_message({message = mcu_message})
end
return trn_message..stub_message..mcu_message
end
return p