Marvel Database
Marvel Database

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')

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 = {}

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

-- sections
	-- adds 'Quote', 'Overview' section, 'TOC' and 'History' section
	value, categories = design.add_quote_overview_toc_history(args, page_type)
	output_categories = h.join_tables(output_categories, categories)
	output = h.join_tables(output, value)

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

	-- adds 'Notes', 'Trivia', 'See Also', 'Recommended Reading' and 'Links and References' sections
	---- links to standard sub-pages/categories - "Appearances", "Minor Appearances", Mentions", "Images", "Quotes" and "Gallery" 
	value, categories = design.add_notes_trivia_see_also_recommended_links_references(args, page_type, pagename)
	output_categories = h.join_tables(output_categories, categories)
	output = h.join_tables(output, value)
--
	output_categories = h.add_categories(output_categories)
	output = table.concat(output)
	
	return frame:preprocess(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


--------------------------------------------------------------------------------------------------
-- also used in Module:Vehicle_Template
function p.get_owner(frame)
	local args = getArgs(frame)
	local value = args[1]
	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..h.add_categories(output_categories)
end


--------------------------------------------------------------------------------------------------
function p.get_type(frame)
	local list_of_items = {
		['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 function get_link_and_category(value)
		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_of_items[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
	local args = getArgs(frame)
	local value = args.Type
	local i
	local category
	local list = {}
	local output_categories = {}
	local output = {}

	if not h.isempty(value)
		then 
			list = h.explode(';', value)
			for i = 1, #list do
				value = list[i]
				if not h.isempty(value)
					then
						value, category = get_link_and_category( mw.text.trim(value) ) 
						output_categories = h.join_tables(output_categories, category)
						table.insert(output, value)
					end
			end
		else
			table.insert(output_categories, 'Item Type Needed')
	end

	return mw.text.listToText(output, ', ', ', ')..h.add_categories(output_categories)
end


--------------------------------------------------------------------------------------------------
function p.get_material(frame)
	local args = getArgs(frame)
	local list = h.explode(';', args.Material)
	local i
	local value 
	local output_categories = {}
	local output = {}

	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(output, h.Link(value))
					elseif h.exists('Category:'..value)
						then table.insert(output, h.LinkToCategory(value, value) )
					else table.insert(output, value)
				end
		end
	end
	
	return mw.text.listToText(output, ', ', ', ')..h.add_categories(output_categories)
end


--------------------------------------------------------------------------------------------------
function p.get_origin(frame)
	local function get_link_and_category(value)
		local list_of_origin = {
		['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_of_origin[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
	local args = getArgs(frame)
	local list = h.explode(';', args.Origin)
	local i
	local value 
	local category
	local output_categories = {}
	local output = {}

	for i = 1, #list do
		value = list[i]
		if not h.isempty(value)
			then
				value, category = get_link_and_category( mw.text.trim(value) ) 
				output_categories = h.join_tables(output_categories, category)
				table.insert(output, value)
		end
	end

	return mw.text.listToText(output, ', ', ', ')..h.add_categories(output_categories)
end

return p