Marvel Database
Advertisement
Marvel Database

Documentation for this module may be created at Module:Category Message Templates/doc

-- module for message template placed in categories.
local p = {}
local h = require("Module:HF")
local design = require('Module:Design')
local getArgs = require('Dev:Arguments').getArgs


function p.test()
	local basepagename = mw.title.getCurrentTitle().baseText
	local subpagename = mw.title.getCurrentTitle().subpageText
	local root = mw.title.getCurrentTitle().rootText
	local full = mw.title.getCurrentTitle().fullText
	local prefixed = mw.title.getCurrentTitle().prefixedText
	local text = mw.title.getCurrentTitle().text
	
	return 'base='..basepagename..'<br>subpage='..subpagename..'<br>root='..root..'<br>prefixed='..prefixed..'<br>full='..full..'<br>text='..text
end


--------------------------------------------------------------------------------
function p.marvel_staff_categories(frame)
	local args = getArgs(frame)
	local basepagename = mw.title.getCurrentTitle().baseText
	local subpagename = mw.title.getCurrentTitle().subpageText
	local list1 = {'Editor', 'Editor-in-Chief', 'Cover Artist', 'Writer', 'Penciler', 'Inker', 'Colorist', 'Letterer', 'Director', 'Producer'}
	local list2 = {'Creator', 'Cover Artist Images', 'Penciler Images', 'Inker Images', 'Colorist Images', 'Letterer Images'}
	local list3 = {
		{'Editor-in-Chief', 'List of all known comic(s) that were produced while ', ' was Editor-in-Chief.', 'Marvel Staff/Editors-in-Chief'},
		{'Cover Artist', 'List of all known comic(s) where ', ' created the cover.', 'Marvel Staff/Cover Artists'},
		{'Editor', 'List of all known work(s) that ', ' edited.', 'Marvel Staff/Editors'},
		{'Writer', 'List of all known work(s) that ', ' wrote.', 'Marvel Staff/Writers'},
		{'Penciler', 'List of all known comic(s) that ', ' penciled.', 'Marvel Staff/Pencilers'},
		{'Inker', 'List of all known comic(s) that ', ' inked.', 'Marvel Staff/Inkers'},
		{'Colorist', 'List of all known comic(s) that ', ' colored.', 'Marvel Staff/Colorists'},
		{'Letterer', 'List of all known comic(s) that ', ' lettered.', 'Marvel Staff/Letterers'},
		{'Director', 'List of all known work(s) directed by ', '.', 'Marvel Staff/Directors'},
		{'Producer', 'List of all known work(s) produced by ', '.', 'Marvel Staff/Producers'},
		{'Creator', 'List of all known subject(s) created by ', '.', 'Subjects by Creator'},
		{'Cover Artist Images', 'List of all known covers drawn by ', '.', 'Images by Cover Artist'},
		{'Penciler Images', 'List of all images on the database penciled by ', '.', 'Images by Penciler'},
		{'Inker Images', 'List of all images on the database inked by ', '.', 'Images by Inker'},
		{'Colorist Images', 'List of all images on the database colored by ', '.', 'Images by Colorist'},
		{'Letterer Images', 'List of all images on the database lettered by ', '.', 'Images by Letterer'},
	}
	local i
	local category
	local message = ''
	local subcategories1 = {}
	local subcategories2 = {}
	local help = ''
	local output_category = ''
	local output = ''
	
	for i = 1, #list1 do
		category = basepagename..'/'..list1[i]
		if h.pages_in_category(category, 'pages')>0
			then table.insert(subcategories1, h.LinkToCategory(category, list1[i]))
			else table.insert(subcategories1, p.nonexistent_page(list1[i]))
		end
	end
	subcategories1 = mw.text.listToText(subcategories1, ' · ', ' · ')
	subcategories1 = '<br>'..tostring( mw.html.create('span'):css('font-size', '80%'):css('font-family', 'monospace'):wikitext(subcategories1) )
	
	for i = 1, #list2 do
		category = basepagename..'/'..list2[i]
		if h.pages_in_category(category, 'files')>0 or (list2[i] == 'Creator' and h.pages_in_category(category, 'pages')>0)
			then table.insert(subcategories2, h.LinkToCategory(category, list2[i]))
			else table.insert(subcategories2, p.nonexistent_page(list2[i]))
		end
	end
	subcategories2 = mw.text.listToText(subcategories2, ' · ', ' · ')
	subcategories2 = '<br>'..tostring( mw.html.create('span'):css('font-size', '80%'):css('font-family', 'monospace'):wikitext(subcategories2) )

	if subpagename ~= basepagename
		then
			for i = 1, #list3 do
				if subpagename == list3[i][1]
					then 
						message = list3[i][2]..h.Link(basepagename)..list3[i][3]
						output_category = list3[i][4]
						if h.in_list(list1, subpagename)
							then help = '<br>(If you find an article that is not shown here, please add "'..basepagename..'" into "'..string.gsub(subpagename, ' ', '')..'" field of said article.)'
							elseif subpagename == 'Creator'
								then help = '<br>(If you find an article that is not shown here, please add "'..basepagename..'" into "Creators" field of said article.)'
							else 
								help = '<br>(If you find an image in the database that is not shown here, please add "'..basepagename
								help = help..'" into "'..string.gsub(string.gsub(subpagename, ' ', ''), 'Images', '')..'" field of said image.)'
						end
						break
				end
			end
			if message ~= ''
				then 
					message = design.span(message).bold
					help = tostring(mw.html.create('span'):css('font-size', '80%'):wikitext(help))
					output = design.messagebox({message..help..subcategories1..subcategories2})
					output = output..h.Category(output_category)
			end
	end
	
	return output
end


--------------------------------------------------------------------------------
-- used in Template:Weight Category
function p.weight_category(frame)
	local units  = require('Module:Units')	
	local pagename = mw.title.getCurrentTitle().text	
	local function lbs_to_kg(weightLbs)
		return h.round(tonumber(weightLbs) * units['lbs'].kg, 2)
	end
	local i
	local value1
	local value2
	local value3
	local sortname
	local category
	local help = {}
	local output_categories = {'Weight'}
	local output = 'List of characters with '
	
	value1, value2 = string.match(pagename, 'Weight (%d+)%-(%d+) lbs')
	if value1 ~= nil and value2 ~= nil
		then 
			sortname = lbs_to_kg(value1) * 1000
			if value2 == '9'
				then output = output..'weight below 10 lbs ('..lbs_to_kg(10)..' kg)'
				else output = output..'weight between '..value1..' lbs ('..lbs_to_kg(value1)..' kg) and '..value2..' lbs ('..lbs_to_kg(value2)..' kg)'
			end
		else 
			output = output..string.lower(pagename)
			sortname = lbs_to_kg(1000) * 1000
	end
	output = design.span(output..'.').bold
	sortname = ' '..string.rep('0', 10-#tostring(sortname))..sortname
	
	value1 = lbs_to_kg(10)
	category = 'Weight 0-9 lbs ('..value1..' kg)'
	text = '< 10 lbs ('..value1..' kg)'
	table.insert(help, h.LinkToCategory(category, text))
	
	value1 = lbs_to_kg(10)
	value2 = lbs_to_kg(20)
	category = 'Weight 10-19 lbs ('..value1..'-'..value2..' kg)'
	text = '10-19 lbs ('..value1..'-'..value2..' kg)'
	table.insert(help, h.LinkToCategory(category, text))
	
	i = 20
	while i <= 280 do
		value1 = lbs_to_kg(i)
		value2 = lbs_to_kg(i+20)
		text = i..'-'..(i+19)..' lbs ('..value1..'-'..value2..' kg)'
		category = 'Weight '..text
		table.insert(help, h.LinkToCategory(category, text))
		i = i + 20
	end
	
	i = 300
	while i <= 900 do
		value1 = lbs_to_kg(i)
		value2 = lbs_to_kg(i+100)
		text = i..'-'..(i+99)..' lbs ('..value1..'-'..value2..' kg)'
		category = 'Weight '..text
		table.insert(help, h.LinkToCategory(category, text))
		i = i + 100
	end
	
	value1 = lbs_to_kg(1000)
	category = 'Weight above 1000 lbs ('..value1..' kg)'
	text = '> 1000 lbs ('..value1..' kg)'
	table.insert(help, h.LinkToCategory(category, text))

	table.insert(help, h.LinkToCategory('Variable Weight', 'Variable'))

	help = mw.text.listToText(help, ' · ', ' · ')
	help = tostring(mw.html.create('span'):css('font-size', '70%'):wikitext(help))
	
	output = design.messagebox({output..'<br>'..help})

	return output..h.add_categories(output_categories, sortname)
end


--------------------------------------------------------------------------------
-- used in Template:Height Category
function p.height_category(frame)
	local units  = require('Module:Units')	
	local pagename = mw.title.getCurrentTitle().text	
	local function ft_to_m(heightFt)
		return tonumber( string.format("%.2f", tonumber(heightFt) * units['ft'].m) )
	end
	local i
	local j
	local value1
	local value2
	local value3
	local sortname
	local category
	local help = {}
	local output_categories = {'Height'}
	local output = 'List of characters with '
	
	value1, value2 = string.match(pagename, 'Height (%d)%-(%d) ft')
	if value1 ~= nil and value2 ~= nil
		then 
			sortname = ft_to_m(value1) * 1000
			if value2 == '1'
				then output = output..'height below 1 ft. ('..ft_to_m(1)..' m)'
				else output = output..'height between '..value1..' ft. ('..ft_to_m(value1)..' m) and '..value2..' ft. ('..ft_to_m(value2)..' m)'
			end
		else 
			output = output..string.lower(pagename)
			if string.find(pagename, ' above 8 ') ~= nil
				then sortname = ft_to_m(8) * 1000
				elseif string.find (pagename, 'Variable') ~= nil
					then sortname = '9999'
				else
					value1, value2 = string.match(pagename, '(%d+) ft%. (%d+) in')
					sortname = ft_to_m(tonumber(value1) + tonumber(value2)/12) * 1000
			end
	end
	output = design.span(output..'.').bold
	sortname = ' '..string.rep('0', 4-#tostring(sortname))..sortname
	
	value1 = ft_to_m(1)
	category = 'Height 0-1 ft. ('..value1..' m)'
	text = '< 1 ft. ('..value1..' m)'
	table.insert(help, h.LinkToCategory(category, text))
	for i = 1, 4 do
		value1 = ft_to_m(i)
    	value2 = ft_to_m(i+1)
    	text = i..'-'..(i+1)..' ft. ('..value1..'-'..value2..' m)'
    	category = 'Height '..text
    	table.insert(help, h.LinkToCategory(category, text))
    end
    for j = 5, 6 do
    	for i = 0, 11 do
    		value1 = ft_to_m(j + i/12)
    		text = j..' ft. '..i..' in. ('..value1..' m)'
    		category = 'Height '..text
    		table.insert(help, h.LinkToCategory(category, text))
    	end
    end
    
	i = 7
	value1 = ft_to_m(i)
    value2 = ft_to_m(i+1)
    text = i..'-'..(i+1)..' ft. ('..value1..'-'..value2..' m)'
    category = 'Height '..text
    table.insert(help, h.LinkToCategory(category, text))

    value1 = ft_to_m(8)
    category = 'Height above 8 ft. ('..value1..' m)'
    text = '> 8 ft. ('..value1..' m)'
    table.insert(help, h.LinkToCategory(category, text))
    
   	table.insert(help, h.LinkToCategory('Variable Height', 'Variable'))
    
	help = mw.text.listToText(help, ' · ', ' · ')
	help = tostring(mw.html.create('span'):css('font-size', '70%'):wikitext(help))
	
	output = design.messagebox({output..'<br>'..help})
	
	return output..h.add_categories(output_categories, sortname)
end


--------------------------------------------------------------------------------
-- currently not working
function p.chronological_sort(frame)
	local pagename = "Xavier's School for Gifted Youngsters/Appearances" --mw.title.getCurrentTitle().text
	local CS = require('Module:Chronological Sort')
	return design.messagebox({CS.main(frame, pagename)})
end


--------------------------------------------------------------------------------
-- used in Template:Power Grid Category
function p.power_grid_category(frame)
	local description = mw.loadData('Module:Power Grid/Description')
	local args = getArgs (frame)
	local subpageText = mw.title.getCurrentTitle().subpageText
	local baseText = mw.title.getCurrentTitle().baseText
	local rootText = mw.title.getCurrentTitle().rootText
	local i
	local j
	local navigation_types = {}
	local navigation_values = {}
	local value 
	local category
	local output_category = ''
	local output = ''

	for i = 1,6 do
		category = 'Power Grid/'..description[i].label
		table.insert(navigation_types, h.LinkToCategory(category, description[i].label))
	end
	navigation_types = mw.text.listToText(navigation_types, ' · ', ' · ')
	navigation_types = tostring( mw.html.create('span'):css('font-size', '80%'):css('font-family', 'monospace'):wikitext(navigation_types) )
	navigation_types = 'This category is a part of the power ratings presented in official Marvel handbooks.<br>'..navigation_types

	if baseText == rootText
		then
			output_category = h.Category(baseText, subpageText)
			for i = 1,6 do
				if description[i].label == subpageText
					then output = design.span(string.upper(description[i].label)).bold..' — '..description[i].tooltip
				end
			end
			output = navigation_types..'\n----'..output
		else
			for i = 1,6 do
				if description[i].label == string.match(baseText, '/(.+)')
					then
						output = design.span(description[i].label).bold..' — '..description[i].tooltip
						for j = 1,7 do
							category = description[i].values[j].category
							table.insert(navigation_values,  h.LinkToCategory(category, j))
							if category == baseText..'/'..subpageText
								then 
									value = design.span(string.upper(description[i].values[j].tooltip)).bold
									output_category = h.Category(baseText, j)
							end
						end
						navigation_values = mw.text.listToText(navigation_values, ' · ', ' · ')
						output = navigation_types..'\n----'..output..'<br>'..navigation_values..'<br>'..value
				end
			end
	end
	output = design.messagebox({output})

	return output..output_category
end


--------------------------------------------------------------------------------
-- used in Template:Races by Location
function p.races_by_location(frame)
	local args = getArgs(frame)
	local pagename = mw.title.getCurrentTitle().baseText
	local page_content = h.get_content(pagename)
	local galaxy = h.get_field_value(page_content, 'Galaxy') 
	local dimension = h.get_field_value(page_content, 'Dimension') 
	local star_system = h.get_field_value(page_content, 'StarSystem') 
	local planet = h.get_field_value(page_content, 'Planet') 
	local page_type = args[1]
	local place = args[2]
	local output_categories = {}
	local output = ''
	
	if (not h.isempty(galaxy) and pagename == galaxy) or (not h.isempty(page_type) and string.lower(page_type) == 'galaxy')
		then
			output = 'galaxy'
			table.insert(output_categories, 'Races by Galaxy')
		elseif (not h.isempty(dimension) and pagename == dimension) or (not h.isempty(page_type) and string.lower(page_type) == 'dimension')
			then
				output = 'dimension'
				table.insert(output_categories, 'Races by Dimension')
		elseif (not h.isempty(star_system) and pagename == star_system) or (not h.isempty(page_type) and string.lower(page_type) == 'star system')
			then
				output = 'star system'
				table.insert(output_categories, 'Races by Star System')
				if not h.isempty(galaxy)
					then table.insert(output_categories, galaxy..'/Races')
					elseif not h.isempty(dimension)
						then table.insert(output_categories, dimension..'/Races')	
					elseif not h.isempty(place)
						then table.insert(output_categories, place..'/Races')
				end
		elseif (not h.isempty(planet) and pagename == planet) or (not h.isempty(page_type) and string.lower(page_type) == 'planet')
			then
				output = 'planet'
				table.insert(output_categories, 'Races by Planet')
				if not h.isempty(star_system)
					then table.insert(output_categories, star_system..'/Races')
					elseif not h.isempty(galaxy)
						then table.insert(output_categories, galaxy..'/Races')
					elseif not h.isempty(dimension)
						then table.insert(output_categories, dimension..'/Races')
					elseif not h.isempty(place)
						then table.insert(output_categories, place..'/Races')
				end
		else table.insert(output_categories, 'Races by Place of Origin')
	end
	
	table.insert(output_categories, pagename)
	output = 'Races which originated from '..h.Link(pagename, pagename)..' '..output..'.'
	output = design.span(output).bold
	output = design.messagebox({output})

	return output..h.add_categories(output_categories, pagename)
end


--------------------------------------------------------------------------------
-- used in:
--		Template:Appearances Category
--		Template:Mentions Category
--		Template:Minor Appearances Category
--		Template:Images Category
--		Template:Quotes
--		Template:Items by User
function p.standard_subcategories_and_subpages(frame)
	local basepagename = mw.title.getCurrentTitle().baseText
	local subpagename = mw.title.getCurrentTitle().subpageText
	local pagetype = getArgs(frame)[1]
	local s
	
	if string.find(basepagename, 'Killed by ') ~= nil
		then s = string.match(basepagename, 'Killed by (.+)')
		else s = basepagename
	end
	
	if h.isempty(pagetype)
		then pagetype = require('Module:PageType').get_page_type(s)
	end

	if pagetype == 'Category' and string.find(basepagename, ' Season ') ~= nil
		then pagetype = 'Season'
		elseif (h.isempty(pagetype) or pagetype == 'Unknown') and not h.in_list({'Appearances', 'Handbook Appearances', 'Minor Appearances', 'Mentions', 'Handbook Mentions', 'Invocations', 'Items', 'Quotes', 'Images', 'Gallery'}, subpagename)
			then 
				basepagename = mw.title.getCurrentTitle().text
				pagetype = require('Module:PageType').get_page_type(basepagename)
	end

	if h.in_list({'Comic', 'Volume', 'Episode', 'Season', 'Series', 'Video Game', 'Film', 'Movie'}, pagetype)
		then return p.lua_standard_subcategories_and_subpages2(basepagename, subpagename, pagetype)
		else return p.lua_standard_subcategories_and_subpages(basepagename, subpagename, pagetype)
	end
end

-- for sources - comic issues, episodes, video games, etc.
function p.lua_standard_subcategories_and_subpages2(basepagename, subpagename, pagetype)
	local standard = require('Module:StandardizedName')
	local sortname = standard.name_for_sorting({basepagename})
	local i
	local category
	local list = {}
	local list1 = {'Reprints', 'Images'}
	local list2 = {'Images'}
	local list_of_subpages = {}
	local help = ''
	local info = ''
	local output_categories = {}
	local output = ''
	
	pagetype = pagetype or require('Module:PageType').get_page_type(basepagename)
	if pagetype == 'Category' and string.find(basepagename, ' Season ') ~= nil
		then pagetype = 'Season'
	end
	
	if pagetype == 'Volume' or pagetype == 'Comic'
		then 
			list = list1
			info = standard.lua_get_title_volume_issue(basepagename, 'Vol')
		elseif h.in_list({'Episode', 'Season', 'Series', 'Film', 'Movie'}, pagetype)
			then 
				if subpagename == basepagename
					then list = list2
				end
				if pagetype == 'Episode' or pagetype == 'Season'
					then info = standard.lua_get_title_volume_issue(basepagename, 'Season')
				end
		elseif pagetype == 'Video Game' 
			then list = list2
	end
	
	for i = 1, #list do
		category = basepagename..'/'..list[i]
		if list[i] == 'Images'
			then s = 'files'
			else s = 'subcats'
		end
		if h.pages_in_category(category, s) > 0
			then table.insert(list_of_subpages, h.LinkToCategory(category, list[i]) )
			else table.insert(list_of_subpages, p.nonexistent_page(list[i]) )
		end
	end
	
	if pagetype == 'Video Game'
		then
			category = basepagename..'/Gallery'
			if h.exists(category)
				then table.insert(list_of_subpages, h.Link(category, 'Gallery') )
				else table.insert(list_of_subpages, p.nonexistent_page('Gallery') )
			end
	end
	if not h.isempty(list_of_subpages)
		then
			list_of_subpages = mw.text.listToText(list_of_subpages, ' · ', ' · ')
			list_of_subpages = '<br>'..tostring( mw.html.create('span'):css('font-size', '80%'):css('font-family', 'monospace'):wikitext(list_of_subpages) )
		else list_of_subpages = ''
	end
	
	if h.in_list({'Reprints', 'Images', 'Gallery', 'Seasons'}, subpagename) and subpagename ~= basepagename
		then
			if subpagename == 'Reprints'
				then 
					if pagetype == 'Comic'
						then 
							output = 'List of all known reprints of '..h.Link(basepagename, basepagename)..'.'
							help = '<br>(If you find an issue that is not shown here, please add "'
							help = help..basepagename..'" into "ReprintOf_" field of said issue.)'
							table.insert(output_categories, 'Comic Reprints by Issue')
							table.insert(output_categories, info.noissue..'/Reprints')
						else
							output = 'List of reprints by issue of '..h.Link(basepagename, basepagename)..'.'
							help = '<br>(If you find reprint of an issue from this volume that is not shown here, please add' 
							help = help..' original source into "ReprintOf_" field of said issue.)'
							table.insert(output_categories, 'Comic Reprints by Volume')
					end
				elseif subpagename == 'Images'
					then
						if pagetype == 'Season'
							then output = 'List of all notable images from '..h.Link(info.title..'#Season '..info.volume, basepagename)..'.'
							else output = 'List of all notable images from '..h.Link(basepagename, basepagename)..'.'
						end
						if pagetype == 'Volume'
							then help = '<br>(If you find an image that is not shown here, please add an issue of "'
							elseif pagetype == 'Season' or pagetype == 'Series'
								then help = '<br>(If you find an image that is not shown here, please add an episode of "'
							else help = '<br>(If you find an image that is not shown here, please add "'
						end
						help = help..basepagename..'" into "Source" field of said image.)'
						if pagetype == 'Comic'
							then 
								table.insert(output_categories, 'Comic Images by Issue')
								table.insert(output_categories, info.noissue..'/Images')
							elseif pagetype == 'Volume'
								then table.insert(output_categories, 'Comic Images by Volume')
							elseif pagetype == 'Episode'
								then 
									table.insert(output_categories, 'TV Screenshots by Episode')
									table.insert(output_categories, info.noissue..'/Images')
							elseif pagetype == 'Season'
								then 
									table.insert(output_categories, 'TV Screenshots by Season')
									table.insert(output_categories, info.title..'/Images')
							elseif pagetype == 'Series'
								then table.insert(output_categories, 'TV Screenshots by Series')
							elseif pagetype == 'Video Game'
								then table.insert(output_categories, 'Video Game Screenshots')	
							elseif pagetype == 'Film' or pagetype == 'Movie'  
								then table.insert(output_categories, 'Movie Screenshots by Movie')		
						end
				elseif subpagename == 'Gallery'
					then
						output = 'Gallery of all notable images from '..h.Link(basepagename, basepagename)..'.'
						help = h.Link('Marvel Database:Gallery Guidelines', 'Gallery Guidelines')
						help = '<br>(If you create a gallery or add image(s) to existing one, please follow our '..help..').'
						table.insert(output_categories, pagetype..' Galleries')
			end
		else
			--basepagename = mw.title.getCurrentTitle().text
			--pagetype = require('Module:PageType').get_page_type(basepagename)
			if pagetype == 'Volume'
				then
					output = 'List of all known comic issues from '..h.Link(basepagename, basepagename)..' volume.'
					help = h.Link('Marvel Database:Comic Template', 'Comic Template')
					help = '<br>(If you find an issue that is not shown here, please add the '..help..' to it.)'
					table.insert(output_categories, 'Comic Categories')
				elseif pagetype == 'Season'
					then
						output = 'List of all known episodes from '..h.Link(info.title..'#Season '..info.volume, basepagename)..'.'
						help = h.Link('Marvel Database:Episode Template', 'Episode Template')
						help = '<br>(If you find an episode that is not shown here, please add the '..help..' to it.)'
						list = {}
						for i = 1, 30 do
							category = info.title..' Season '..i
							if h.exists('Category:'..category)
								then 
									category = h.LinkToCategory(category, 'Season '..i)
									table.insert(list, category)
							end
						end
						if not h.isempty(list)
							then
								list = mw.text.listToText(list, ' · ', ' · ')
								help = help..'<br>'..tostring( mw.html.create('span'):css('font-size', '80%'):css('font-family', 'monospace'):wikitext(list) )
						end
						table.insert(output_categories, 'Seasons')
			end
	end
	if help ~= ''
		then help = tostring(mw.html.create('span'):css('font-size', '80%'):wikitext(help))
	end
	output = design.span(output).bold..help..list_of_subpages
			
	return design.messagebox({output})..h.add_categories(output_categories, sortname)
end


-- for articles - characters, teams, etc.
function p.lua_standard_subcategories_and_subpages(basepagename, subpagename, pagetype)
	local sortname
	local i
	local category
	local list = {'Appearances', 'Handbook Appearances', 'Minor Appearances', 'Mentions', 'Handbook Mentions', 'Invocations', 'Items', 'Quotes', 'Images'}
	local list_of_subpages = {}
	local help = ''
	local s
	local killed_by = false
	local output_categories = {}
	local output = ''

	if string.find(basepagename, 'Killed by ') ~= nil
		then 
			basepagename = string.match(basepagename, 'Killed by (.+)')
			killed_by = true
	end

	sortname = require('Module:StandardizedName').name_for_sorting({basepagename})
	pagetype = pagetype or require('Module:PageType').get_page_type(basepagename)

	for i = 1, #list do
		category = basepagename..'/'..list[i]
		if list[i] == 'Images'
			then s = 'files'
			else s = 'pages'
		end
		if h.pages_in_category(category, s) > 0
			then table.insert(list_of_subpages, h.LinkToCategory(category, list[i]) )
			else table.insert(list_of_subpages, p.nonexistent_page(list[i]) )
		end
	end
	category = basepagename..'/Gallery'
	if h.exists(category)
		then table.insert(list_of_subpages, h.Link(category, 'Gallery') )
		else table.insert(list_of_subpages, p.nonexistent_page('Gallery') )
	end
	if h.in_list({'Character', 'Team', 'Organization', 'Race'}, pagetype) 
		then
			category = 'Killed by '..basepagename
			if h.pages_in_category(category, 'pages') > 0
				then table.insert(list_of_subpages, h.LinkToCategory(category, 'Victims') )
				else table.insert(list_of_subpages, p.nonexistent_page('Victims') )
			end
	end
	
	list_of_subpages = mw.text.listToText(list_of_subpages, ' · ', ' · ')
	list_of_subpages = '<br>'..tostring( mw.html.create('span'):css('font-size', '80%'):css('font-family', 'monospace'):wikitext(list_of_subpages) )
			
	if subpagename ~= basepagename
		then
			if h.in_list({'Appearances', 'Handbook Appearances', 'Minor Appearances', 'Mentions', 'Handbook Mentions', 'Invocations'}, subpagename)
				then
					if h.in_list({ 'Handbook Appearances', 'Handbook Mentions' }, subpagename)
						then output = 'List of all known '..string.lower(string.gsub(subpagename, 'Handbook ', ''))..' of '..h.Link(basepagename, basepagename)..' in '..h.LinkToCategory('Handbooks', 'handbooks')..'.'
						else output = 'List of all known '..string.lower(subpagename)..' of '..h.Link(basepagename, basepagename)..'.'
					end
					for i = 1,6 do
						if subpagename == list[i]
							then 
								--help = list2[i]
								if h.in_list({ 'Invocations', 'Handbook Mentions' }, list[i])
									then 
										table.insert(output_categories, list[i])
										table.insert(output_categories, basepagename..'/Mentions')
									elseif list[i] == 'Handbook Appearances'
										then
											table.insert(output_categories, list[i])
											table.insert(output_categories, basepagename..'/Appearances')
									else table.insert(output_categories, pagetype..' '..list[i])
								end
						end
					end
					help = '<br>(If you find a medium that is not shown here, please add "'..basepagename
					help = help..'" to the appearances section with a '..h.Link('Marvel Database: Appearance Tags', 'proper tag')..'.)'
				elseif subpagename == 'Items'
					then
						output = 'List of all notable items owned and/or used by '..h.Link(basepagename, basepagename)..'.'
						help = '<br>(If you find an item that is not shown here, please add "'..basepagename
						help = help..'" to the "CurrentOwner" or "PreviousOwners" sections.)'
						table.insert(output_categories, 'Items by User')
				elseif subpagename == 'Quotes'
					then
						output = 'List of all notable quotes by or about '..h.Link(basepagename, basepagename)..'.'
						help = '<br>(Please add any important quotations that may be missing, ensuring to cite the original source. '
						help = help..'Pages with a quote from this character will automatically be added here along with the quote.)'
						table.insert(output_categories, 'Quotes')
				elseif subpagename == 'Images'
					then
						output = 'List of all images of '..h.Link(basepagename, basepagename)..' on the database.'
						help = '<br>(If you find an image in the database that is not shown here, please add "'..basepagename..'" as an image subject.)'
						table.insert(output_categories, pagetype..' Images')
				elseif subpagename == 'Gallery'
					then
						output = 'Gallery of all notable images '
						if pagetype == 'Marvel Staff' or pagetype == 'User Art'
							then output = output..'by '
							else output = output..'of '
						end
						if pagetype == 'User Art'
							then output = output..h.Link('User:'..basepagename, 'User:'..basepagename)
							else output = output..h.Link(basepagename, basepagename)
						end
						output = output..' on the database.'
						help = h.Link('Marvel Database:Gallery Guidelines', 'Gallery Guidelines')
						help = '<br>(If you create a gallery or add image(s) to existing one, please follow our '..help..').'
						table.insert(output_categories, pagetype..' Galleries')
				elseif killed_by == true
					then
						output = 'List of all notable victims killed by '..h.Link(basepagename, basepagename)..'.'
						help = '<br>(If you find a character that is not shown here, please add "'..basepagename
						help = help..'" to the "KilledBy" field.)'
						table.insert(output_categories, 'Characters by Killer')
			end
			if ( pagetype ~= 'User Art' and not h.exists(basepagename) ) or ( pagetype == 'User Art' and not h.exists('User:'..basepagename) )
				then 
					output_categories = {} -- remove all previous categories
					if killed_by == true
						then table.insert(output_categories, 'Killed By Categories with Articles Needed')
						else table.insert(output_categories, subpagename..'  Categories with Articles Needed')
					end
			end
	end
	if help ~= ''
		then help = tostring(mw.html.create('span'):css('font-size', '80%'):wikitext(help))
	end
	output = design.span(output).bold..help..list_of_subpages
			
	return design.messagebox({output})..h.add_categories(output_categories, sortname)
end


--------------------------------------------------------------------------------
-- used in Template:Reality Category
function p.categories_by_reality(frame)
	local page_types = {'Character', 'Item', 'Location', 'Organization', 'Race', 'Team', 'Vehicle'}
	local basepagename = mw.title.getCurrentTitle().baseText
	local subpagename = mw.title.getCurrentTitle().subpageText
	local sortname = require('Module:Reality').get_reality_info({basepagename}).padded_number
	local i
	local category
	local list_of_subpages = {}
	local help = ''
	local output_categories = {}
	local output = ''
	
	if string.find(basepagename, ' by Reality') ~= nil
		then 
			for i = 1, #page_types do
				category = page_types[i]..'s by Reality'
				table.insert(list_of_subpages, h.LinkToCategory(category, page_types[i]..'s') )
			end
			list_of_subpages = mw.text.listToText(list_of_subpages, ' · ', ' · ')
		else
			for i = 1, #page_types do
				category = basepagename..'/'..page_types[i]..'s'
				if h.pages_in_category(category) > 0
					then table.insert(list_of_subpages, h.LinkToCategory(category, page_types[i]..'s') )
					else table.insert(list_of_subpages, p.nonexistent_page(page_types[i]..'s') )
				end
			end
			list_of_subpages = mw.text.listToText(list_of_subpages, ' · ', ' · ')
			list_of_subpages = '<br>'..tostring( mw.html.create('span'):css('font-size', '80%'):css('font-family', 'monospace'):wikitext(list_of_subpages) )
	end
	
	if subpagename == basepagename
		then
			if string.find(basepagename, ' by Reality') ~= nil
				then 
					category = string.match(basepagename, '(.+) by Reality')
					table.insert(output_categories, category)
				else
					output = 'Articles related to '..h.Link(basepagename, basepagename)..' reality.'
					table.insert(output_categories, 'Realities by Category')
			end
		else
			output = subpagename..' that originate from '..h.Link(basepagename, basepagename)..' reality.'
			table.insert(output_categories, subpagename..' by Reality')
			table.insert(output_categories, {basepagename, subpagename})
			help = '<br>(To add '..string.lower(string.sub(subpagename, 1, -1))..' to this list enter "'..basepagename..'" in the "Universe" field of its template.)'
			help = tostring(mw.html.create('span'):css('font-size', '80%'):wikitext(help))
	end
	output = design.span(output).bold..help..list_of_subpages
	
	return design.messagebox({output})..h.add_categories(output_categories, sortname)
end


--------------------------------------------------------------------------------
-- used in Template:Year of Debut Category
function p.debut_category(frame)
	local page_types = {'Character', 'Item', 'Location', 'Organization', 'Race', 'Reality', 'Team', 'Vehicle'}
	local page_types2 = {'Characters', 'Items', 'Locations', 'Organizations', 'Races', 'Realities', 'Teams', 'Vehicles'}
	local pagename = mw.title.getCurrentTitle().text
	local page_type
	local page_type2
	local year
	local i
	local category
	local help = {}
	local output_categories = {}
	local output = ''
	
	year, page_type = string.match(pagename, '^(%d%d%d%d) (.+) Debuts')
	if page_type == nil
		then
			page_type2 = string.match(pagename, '^(.+)s by Year of Debut')
			if page_type2 == 'Realitie'
				then page_type = 'Reality'
				else page_type = page_type2
			end
			output = p.debut_categories_navigation(page_type)
			table.insert(output_categories, page_type2..'s')
		else
			for i = 1, #page_types do
				if page_types[i] == page_type
					then page_type2 = page_types2[i]
				end
				category = year..' '..page_types[i]..' Debuts'
				if h.pages_in_category(category)>0
					then table.insert(help, h.LinkToCategory(category, page_types2[i]))
					else table.insert(help, p.nonexistent_page(page_types2[i]))
				end
			end
			help = mw.text.listToText(help, ' · ', ' · ')
			help = tostring(mw.html.create('span'):css('font-size', '80%'):wikitext(help))
			table.insert(output_categories, page_type2..' by Year of Debut')
			table.insert(output_categories, {year, page_type..' Debuts'})

			output = design.span(page_type2..' which first appeared in medium released in '..h.LinkToCategory(year, year)..'.').bold
			output = output..'<br>'..help
			output = design.messagebox({output})..p.debut_categories_navigation(page_type)
	end
	
	return output..h.add_categories(output_categories)
end


function p.debut_categories_navigation(page_type)
	local page_types = {'Character', 'Item', 'Location', 'Organization', 'Race', 'Reality', 'Team', 'Vehicle'}
	local page_types2 = {'Characters', 'Items', 'Locations', 'Organizations', 'Races', 'Realities', 'Teams', 'Vehicles'}
	local current_year = tonumber(mw.language.new('en'):formatDate('Y'))
	local header
	local i
	local category
	local help = {}
	local output = {}

	for i = 1939, current_year do
		category = i..' '..page_type..' Debuts'
		if h.pages_in_category(category)>0
			then table.insert(output, h.LinkToCategory(category, i))
			else table.insert(output, p.nonexistent_page(i))
		end
	end
	
	output = mw.text.listToText(output, ' ', ' ')
	output = mw.html.create('div'):css('font-family', 'monospace'):wikitext(output)
	for i = 1, #page_types do
		category = page_types2[i]..' by Year of Debut'
		table.insert(help, h.LinkToCategory(category, page_types2[i]))
		if page_type == page_types[i]
			then page_type = page_types2[i]
		end
	end
	help = mw.text.listToText(help, ' · ', ' · ')
	help = tostring(mw.html.create('span'):css('font-size', '80%'):wikitext(help))
	header = design.span(page_type..' by year of their first appearance.').bold
	output = header..'<br>'..help..'\n----\n'..tostring(output)
	return design.messagebox({output})
end


--------------------------------------------------------------------------------
function p.nonexistent_page(text)
	return tostring( mw.html.create('span'):css('color', 'silver'):wikitext(text))
end

return p
Advertisement