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

-- module for Marvel Database:Item Template
local p = {}
local getArgs = require('Module:Arguments').getArgs 
local h = require("Module:HF")
local design = require('Module:Design')
local standard = require("Module:StandardizedName")

function p.main(frame)
	local args = getArgs(frame)
	local pagename = mw.title.getCurrentTitle().text
	local page_type = 'Item'
	local value
	local categories = {}
	local output_categories = {}
	local output_infobox = {}
	local output = {}

	table.insert(output, '{{DEFAULTSORT:'..standard.name_for_sorting({pagename})..'|noerror}}')
	table.insert(output_categories, 'Items')

-- infobox
	value, categories = design.add_infobox_page_title_and_image(args, pagename, page_type)
	output_categories = h.join_tables(output_categories, categories)
	table.insert(output_infobox, value)

	table.insert(output_infobox, design.add_infobox_official_name(args, page_type) )
	table.insert(output_infobox, design.add_infobox_row('Aliases', args.Aliases) )

	value, categories = p.group_owners(args)
	output_categories = h.join_tables(output_categories, categories)
	table.insert(output_infobox, value)

	value, categories = p.group_characteristics(args)
	output_categories = h.join_tables(output_categories, categories)
	table.insert(output_infobox, value)
	
	value, categories = p.group_origin(args, pagename)
	output_categories = h.join_tables(output_categories, categories)
	table.insert(output_infobox, value)

	value, categories = design.add_infobox_appearances_and_creators(args, page_type)
	output_categories = h.join_tables(output_categories, categories)
	table.insert(output_infobox, value)

	table.insert(output_categories, p.lua_get_outdated_fields(args) )

-- sections
	value, categories = design.add_quote(args)
	output_categories = h.join_tables(output_categories, categories)
	table.insert(output, value)

	table.insert( output, design.add_overview_and_toc(args.Overview) )
	
	value = args.HistoryText
	if h.isempty(value)
		then table.insert(output_categories, 'Item History Needed')
		else table.insert( output, design.add_section('History', value, 2) )
	end

	table.insert( output, design.add_section('Properties', args.Properties, 2) )
	table.insert( output, design.add_section('Alternate Reality Versions', args.AlternateVersions, 2) )

	table.insert( output, design.add_section('Notes', args.Notes, 2) )
	table.insert( output, design.add_section('Trivia', args.Trivia, 2) )

	table.insert( output, design.add_header('See Also', 2) )
	--add links to standard sub-pages/categories - "Appearances", "Minor Appearances", Mentions", "Images", "Quotes" and "Gallery" 
	value, categories = design.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, design.add_section('Recommended Reading', args.Recommended, 2) )
	
	table.insert( output, design.add_links_and_references(args, pagename) )
--
	output_infobox = design.create_infobox( table.concat(output_infobox) )
	output_categories = h.add_categories(output_categories)
	output = table.concat(output)
	
	return frame:preprocess(output_infobox..output)..output_categories
end


--------------------------------------------------------------------------------------------------
function p.get_item_type(value)
	local list = {
		['amulet']				= 'Amulets',
		['armor']				= 'Battlesuits',
		['arrow']				= 'Bows and Arrows',
		['arrows']				= 'Bows and Arrows',
		['artifact']			= 'Artifact',
		['axe']					= 'Axes',
		['bag']					= 'Bags',
		['baton']				= 'Batons',
		['batons']				= 'Batons',
		['battlesuit']			= 'Battlesuits',
		['belt']				= 'Belts',
		['blade']				= 'Blades',
		['bomb']				= 'Bombs',
		['bow']					= 'Bows and Arrows',
		['bracelet']			= 'Bracelets',
		['bullet']				= 'Bullets',
		['cape']				= 'Capes',
		['cloak']				= 'Capes',
		['crown']				= 'Headgear',
		['computer program']	= 'Computer Programs',
		['dagger']				= 'Knives and Daggers',
		['daggers']				= 'Knives and Daggers',
		['disease']				= 'Diseases and Virsuses',
		['document']			= 'Documents',
		['drone']				= 'Drones',
		['drug']				= 'Drugs',
		['explosive']			= 'Explosives',
		['explosives']			= 'Explosives',
		['firearm']				= 'Firearms',
		['flail']				= 'Maces and Flails',
		['flight harness']		= 'Flight Harness',		
		['food']				= 'Food',
		['footwear']			= 'Footwear',
		['gauntlet']			= 'Gloves',	
		['gauntlets']			= 'Gloves',	
		['glove']				= 'Gloves',
		['gloves']				= 'Gloves',
		['grenade']				= 'Grenades',
		['grenades']			= 'Grenades',
		['gun']					= 'Firearms',
		['hammer']				= 'Hammers',
		['headgear']			= 'Headgear',	
		['helmet']				= 'Headgear',
		['horn']				= 'Musical Instruments',
		['holography']			= 'Holography',
		['holographic']			= 'Holography',
		['idol']				= 'Artifact',
		['infinity stone']		= 'Infinity Stones',
		['iron man armor']		= 'Iron Man Armor',
		['iron monger armor']	= 'Iron Monger Armor',
		['jewel']				= 'Stones',
		['jewels']				= 'Stones',
		['knife']				= 'Knives and Daggers',
		['knives']				= 'Knives and Daggers',
		['mace']				= 'Maces and Flails',
		['magical armor']		= 'Magical Armors',	
		['magical blades']		= 'Magical Blades',	
		['magical blade']		= 'Magical Blades',	
		['magical book']		= 'Magical Books',	
		['magical books']		= 'Magical Books',	
		['mask']				= 'Headgear',
		['material']			= 'Materials',	
		['mirror']				= 'Mirrors',
		['missile']				= 'Missiles',
		['missiles']			= 'Missiles',
		['morning star']		= 'Maces and Flails',
		['musical instrument']	= 'Musical Instruments',
		['necklace']			= 'Necklaces',
		['plant']				= 'Plants',
		['power source']		= 'Power Sources',
		['ring']				= 'Rings',
		['robot']				= 'Robots',
		['scepter']				= 'Staffs',
		['shield']				= 'Shields',
		['social networks']		= 'Social Networks',
		['spear']				= 'Spears',
		['spell']				= 'Magic Spells',
		['staff']				= 'Staffs',
		['stave']				= 'Batons',
		['stone']				= 'Stones',
		['stones']				= 'Stones',
		['suit']				= 'Suits',
		['sword']				= 'Swords',
		['swords']				= 'Swords',
		['technology']			= 'Technology',	
		['time machine']		= 'Time Machines',
		['translator']			= 'Linguistic Items',
		['torture device']		= 'Torture Device',
		['uniform']				= 'Suits',
		['virus']				= 'Diseases and Virsuses',
		['visor']				= 'Visors',
		['wand']				= 'Wands',
		['war machine armor']	= 'War Machine Armor', 
		['weapon']				= 'Weapons',
		['wings']				= 'Flight Harness',
	}
	local value_lower = string.lower(value)
	local unique = ''
	local category = ''
	local output_categories = {}
	local output = ''
	
	if string.find(value_lower, 'unique ') ~= nil
		then 
			unique = h.LinkToCategory('Unique Items', 'Unique')..' '
			value = string.gsub(value, 'Unique ', '')
			value_lower = string.lower(value)
			table.insert(output_categories, 'Unique Items')
	end
	category = list[value_lower]
	if category ~= nil
		then 
			output = unique..h.LinkToCategory(category, value)
			table.insert(output_categories, category)
		else output = value
	end

	return output, output_categories
end


--------------------------------------------------------------------------------------------------
function p.get_origin(value)
	local list = {
		['alien']				= 'Alien Technology',
		['asgardian']			= 'Asgardian Items',	
		['atlantean']			= 'Atlantean Items',
		['badoon']				= 'Badoon Technology',
		['biblical']			= 'Biblical Items',
		['celestial']			= 'Celestial Technology',
		['centaurian']			= 'Centaurian Technology',
		['chitauri']			= 'Chitauri Technology',
		['cursed']				= 'Cursed Items',
		['demonic']				= 'Demonic Items',
		['deviant skrull']		= 'Deviant Skrull Technology',
		['dire wraith']			= 'Dire Wraith Technology',
		['divine']				= 'Divine Items',
		['ennead']				= 'Ennead Items‎',	
		['eternal']				= 'Eternal Technology',
		['galadorian']			= 'Galadorian Items‎',	
		['inhuman']				= 'Inhuman Technology',
		['inhumans']			= 'Inhuman Technology',
		['kree']				= 'Kree Technology',
		['magic']				= 'Magical Items',
		['magical']				= 'Magical Items',
		['magical weapon']		= 'Magical Items',
		['negative zone']		= 'Negative Zone Items‎',	
		['olympian']			= 'Olympian Items',	
		['rigellian']			= 'Rigellian Technology',	
		['sakaaran']			= 'Sakaaran Technology',
		["shi'ar"]				= "Shi'ar Technology",
		['technology']			= 'technology',
		['vampire']				= 'Vampire Items',	
		['vodu']				= 'Vodū Items',	
		['vodū']				= 'Vodū Items',	
		['wakandan']			= 'Wakandan Technology',	
		['xandarian']			= 'Xandarian Technology',	
	}
	local value_lower = string.lower(value)
	local category = list[value_lower]
	local output = ''

	if category ~= nil
		then output = h.LinkToCategory(category, value)
		elseif h.exists('Category:'..value..' Items') 
			then 
				category = value..' Items'
				output = h.LinkToCategory(category, value)
		elseif h.exists('Category:'..value..' Technology') 
			then 
				category = value..' Technology'
				output = h.LinkToCategory(category, value)
		else
			output = value
	end

	return output, category
end


--------------------------------------------------------------------------------------------------
-- also used in Module:Vehicle_Template
function p.get_owner(value)
	local i
	local list = {}
	local output_categories = {}
	local output = {}
	
	if not h.isempty(value)
		then 
			if string.find(value, ';', 1, true) ~= nil
				then 
					list = mw.text.split(value, ';')
					for i = 1, #list do
						value = list[i]
						if not h.isempty(value)
							then
								value = mw.text.trim(value)
								if h.is_link(value)
									then table.insert(output_categories, h.break_link(value, 1)..'/Items')
								end
								table.insert(output, value)
						end
					end
				else
					value = mw.text.trim(value)
					if h.is_link(value)
						then table.insert(output_categories, h.break_link(value, 1)..'/Items')
					end
					table.insert(output, value)
			end
			output = mw.text.listToText(output, ', ', ', ')
	end
	
	return output, output_categories
end


--------------------------------------------------------------------------------------------------
function p.lua_get_outdated_fields(args)
	local output = ''
	
	if  not h.isempty(args.Custom)
		or not h.isempty(args.CustomLabel)
		or not h.isempty(args.CustomSection1)
		or not h.isempty(args.CustomText1)
		or not h.isempty(args.CustomSection2)
		or not h.isempty(args.CustomText2)
		or not h.isempty(args.NotesHeader)
		or not h.isempty(args.TriviaHeader)
		or not h.isempty(args.HistoryHeader)
		or not h.isempty(args.SeeAlsoHeader)
		or not h.isempty(args.LinksHeader)
		or not h.isempty(args.Gallery)
		or not h.isempty(args.Abilities)
		or not h.isempty(args.Strength)
		or not h.isempty(args.Weaknesses)
		or not h.isempty(args.Powers)
			then output = 'Outdated Fields/Item'
	end
	
	return output	
end


-- *********************		GROUPS		*********************
--------------------------------------------------------------------------------------------------
function p.group_owners(args)
	local value
	local category
	local output_categories = {}
	local output = {}

	value, category = p.get_owner(args.CurrentOwner)
	output_categories = h.join_tables(output_categories, category)
	table.insert(output, design.add_infobox_row('Current owner(s)', value) )
	
	value, category = p.get_owner(args.AlternateOwners)
	output_categories = h.join_tables(output_categories, category)
	table.insert(output, design.add_infobox_row('Notable alernate reality owner(s)', value) )
	
	value, category = p.get_owner(args.PreviousOwners)
	output_categories = h.join_tables(output_categories, category)
	table.insert(output, design.add_infobox_row('Previous owner(s)', value) )

	return design.add_infobox_group(output, 'Owners'), output_categories
end


--------------------------------------------------------------------------------------------------
function p.group_characteristics(args)
	local i
	local value
	local category
	local list = {}
	local s = {}
	local output_categories = {}
	local output = {}
	
	value = args.Type
	if not h.isempty(value)
		then 
			if string.find(value, ';', 1, true) ~= nil
				then 
					list = mw.text.split(value, ';')
					for i = 1, #list do
						value = list[i]
						if not h.isempty(value)
							then
								value = mw.text.trim(value)
								value, category = p.get_item_type(value) 
								output_categories = h.join_tables(output_categories, category)
								table.insert(s, value)
						end
					end
				else
					value = mw.text.trim(value)
					value, category = p.get_item_type(value) 
					output_categories = h.join_tables(output_categories, category)
					table.insert(s, value)
			end
		else
			table.insert(output_categories, 'Item Type Needed')
	end
	table.insert(output, design.add_infobox_row_collapsible('Type(s)', mw.text.listToText(s, ', ', ', ')) )			

	value = args.Material
	s = {}
	if not h.isempty(value)
		then 
			if string.find(value, ';', 1, true) ~= nil
				then 
					list = mw.text.split(value, ';')
					for i = 1, #list do
						value = list[i]
						if not h.isempty(value) 
							then
								value = mw.text.trim(value)
								if h.exists('Category:'..value)
									then table.insert(output_categories, value)
								end
								if h.exists(value)
									then table.insert(s, h.Link(value))
									else table.insert(s, value)
								end
						end
					end
				else
					value = mw.text.trim(value)
					if h.exists('Category:'..value)
						then table.insert(output_categories, value)
					end
					if h.exists(value)
						then table.insert(s, h.Link(value))
						else table.insert(s, value)
					end
			end
	end
	table.insert(output, design.add_infobox_row_collapsible('Main material(s)', mw.text.listToText(s, ', ', ', ')) )	

	table.insert(output, design.add_infobox_row_collapsible('Model', args.Model) )
	table.insert(output, design.add_infobox_row_collapsible('Version', args.Version) )
	table.insert(output, design.add_infobox_row_collapsible('Dimensions', args.Dimensions) )
	table.insert(output, design.add_infobox_row_collapsible('Weight', args.Weight) )
	
	return design.add_infobox_group(output, 'Physical Characteristics'), output_categories
end

--------------------------------------------------------------------------------------------------
function p.group_origin(args, pagename)
	local i
	local value
	local category
	local list = {}
	local s = {}
	local output_categories = {}
	local output = {}

	value = args.Origin
	if not h.isempty(value)
		then 
			if string.find(value, ';', 1, true) ~= nil
				then 
					list = mw.text.split(value, ';')
					for i = 1, #list do
						value = list[i]
						if not h.isempty(value)
							then
								value = mw.text.trim(value)
								value, category = p.get_origin(value) 
								output_categories = h.join_tables(output_categories, category)
								table.insert(s, value)
						end
					end
				else
					value = mw.text.trim(value)
					value, category = p.get_origin(value) 
					output_categories = h.join_tables(output_categories, category)
					table.insert(s, value)
			end
	end
	table.insert(output, design.add_infobox_row_collapsible('Origin', mw.text.listToText(s, ', ', ', ')) )	

	value, categories = design.add_infobox_reality(args, pagename, '/Items')
	output_categories = h.join_tables(output_categories, categories)
	table.insert(output, value)
	
	table.insert(output, design.add_infobox_row('Lead Designer', args.LeadDesigner) )
	table.insert(output, design.add_infobox_row('Additional Designers', args.AdditionalDesigners) )
	table.insert(output, design.add_infobox_row('Place of Creation', args.PlaceOfCreation) )
	table.insert(output, design.add_infobox_row('Place of Destruction', args.PlaceOfDestruction) )

	return design.add_infobox_group(output, 'Origin'), output_categories
end

return p
Community content is available under CC-BY-SA unless otherwise noted.