Marvel Database
Advertisement

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

-- module for Marvel Database:Series List
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 = 'Series'
	local dpl_string
	local gallery = ''
	local value
	local categories = {}
	local output_categories = {}
	local output = {}
	
	table.insert(output_categories, p.lua_get_outdated_fields(args) )

-- sections
	table.insert( output, design.add_overview_and_toc(args.Overview) )
	
	value = args.Mode
	if not h.isempty(value) and string.lower(value) == 'gallery'
		then
			dpl_string = frame:preprocess( p.lua_dpl_list(pagename) )
			gallery = p.lua_add_gallery(dpl_string)
			table.insert( output, design.add_section('Episodes', gallery) )
		else
			table.insert( output, design.add_section('Episodes', p.lua_get_episodes(args, pagename), 2) )
	end
	table.insert( output, design.add_section('History', args.HistoryText, 2) )
	table.insert( output, design.add_section('Synopsis', args.Synopsis, 2) )
	table.insert( output, design.add_section('Full Cast', args.FullCast, 2) )
	table.insert( output, design.add_section('Crew', args.Crew, 2) )
	
	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 i
	local output = ''

	if not h.isempty(args.Universe)
	or not h.isempty(args.Format)
		then output = 'Outdated Fields/Series'
	end

	for i = 1, 10 do
		if not h.isempty(args['Distinguish'..i])
			then output = 'Outdated Fields/Series'
		end
	end

	return output	
end


--------------------------------------------------------------------------------------------------
function p.lua_get_episodes(args, pagename)
	local i
	local j
	local episodes = args.Episodes
	local seasons = {}
	local season = {}
	local output = ''
	
	for i = 2, 10 do
		season = {}
		for j = 1, 100 do
			value = args['Season'..i..'_'..j]
			if not h.isempty(value)
				then 
					value = '\n#'..h.Link(pagename..' Season '..i..' '..j, value)
					table.insert(season, value)
			end
		end
		season = design.add_section('Season '..i, table.concat(season), 3)
		table.insert(seasons, season)
	end
	i = 1
	season = {}
	for j = 1, 100 do
		value = args['Season'..i..'_'..j]
		if not h.isempty(value)
			then 
				value = '\n#'..h.Link(pagename..' Season '..i..' '..j, value)
				table.insert(season, value)
		end
	end
	if not h.isempty( table.concat(seasons) )
		then season = design.add_section('Season '..i, table.concat(season), 3)
		else season = table.concat(season)
	end
	seasons = season..table.concat(seasons)

	if not h.isempty(seasons) or not h.isempty(episodes) 
		then 
			if h.isempty(episodes)
				then episodes = ''
			end
			output = episodes..seasons
	end
	
	return output
end


--------------------------------------------------------------------------------------------------
function p.lua_dpl_list(pagename)
	local template = '{Marvel Database:Episode Template}'
	local series = pagename..' %'
	local image = template..':Image, '
	local year = template..':Year, '
	local month = template..':Month, '
	local day = template..':Day, '
	local title = template..':EpisodeTitle'
	local output = {}
--[[
	if string.find(pagename, '&', 1, true) ~= nil
		then 
			pagename = string.gsub(pagename, '%(', '\\(')
			pagename = string.gsub(pagename, '%)', '\\)')
			pagename = string.gsub(pagename, '%?', '\\?')	
			series = '^'..pagename..'$'
		else series = pagename
	end
]]--
	table.insert(output, '{{#dpl:')
	table.insert(output, '|category = Episodes')
	table.insert(output, '|titlematch = '..series)
	table.insert(output, '|include = '..year..month..day..image..title)
	table.insert(output, '|mode = userformat')
	table.insert(output, '|secseparators = %PAGE%~,~,,~,,~,,~,,@@@')
	table.insert(output, '|noresultsheader = no_results')
	table.insert(output, '|allowcachedresults = true')
	table.insert(output, '}}')

	return table.concat(output)
end


--------------------------------------------------------------------------------------------------
function p.lua_add_gallery(dpl_string)
	local m_date = require("Module:Date")
	local function get_release_date(year, month, day)
		local output = ''

		if not h.isempty(day)
			then 
				month = m_date.get_month_name({month})
				output = '<br>('..month..' '..day..', '..year..')'
			elseif not h.isempty(month)
				then 
					month = m_date.get_month_name({month})
					output = '<br>('..month..', '..year..')'
			elseif not h.isempty(year)
				then 
					output = '<br>('..year..')'
		end

		return output
	end
	local function get_image(image)
		local output = ''
		if not h.isempty(image)
			then output = image
			else output = 'No Image Available.png'
		end
		return output
	end
	local function get_title(title)
		local output = ''
		if not h.isempty(title)
			then output = '<br>"'..title..'"'
		end
		return output
	end
	local list = {}
	local info = {}
	local s = ''
	local seasons = {}
	local season = ''
	local max_season = 1
	local i
	local j
	local k
	local output = ''
	
	if not h.isempty(dpl_string) and dpl_string ~= 'no_results'
		then
			-- transforming result of DPL into table
			dpl_string = mw.text.split(dpl_string, '@@@', true)
			for i = 1, #dpl_string do
				if not h.isempty(dpl_string[i])
					then
						s = mw.text.split(dpl_string[i], '~', true)
						info = standard.lua_get_title_volume_issue(s[1], 'Season')
						season = tonumber(info.volume)
						if season > max_season 
							then max_season = season
						end
						s = {
								['season'] = season,
								['episode'] = get_image(s[5])..'{{!}}'..info.link.all..get_title(s[6])..get_release_date(s[2], s[3], s[4]),
								['sortname'] = info.sortname.all..info.remainder_issue,
							}
						table.insert(list, s)
				end
			end
			table.sort(list, p.lua_sort_by_issue)
			-- creating gallery for each season
			output = {}
			if max_season == 1
				then 
					for i = 1, #list do
						table.insert(output, '\n'..list[i].episode)
					end
					output = table.concat(output)
					output = '{{#tag:gallery|'..output..'|position=center|captionalign=center|widths=200px}}'
				else
					season = {}
					table.insert(season, '\n'..list[1].episode)
					for i = 2, #list do
						if list[i].season == list[i - 1].season
							then 
								table.insert(season, '\n'..list[i].episode)
							else
								table.insert(seasons, season)
								season = {}
								table.insert(season, '\n'..list[i].episode)
						end
					end
					table.insert(seasons, season)
					for i = 1, #seasons do
						season = table.concat(seasons[i])
						season = '{{#tag:gallery|'..season..'|position=center|captionalign=center|widths=230px}}'
						season = design.add_section('Season '..i, season, 3)
						table.insert(output, season)
					end
					output = table.concat(output)
			end
	end
	
	return output
end


--------------------------------------------------------------------------------------------------
function p.lua_sort_by_issue(a, b)
	return a.sortname < b.sortname
end


--------------------------------------------------------------------------------------------------
function p.get_series_type(frame)
	local args = getArgs(frame)
	local series_type = args.SeriesType
	local function add_link_and_category(value)
		local category = ''
		local output = ''
		if value == 'TV'
			then 
				category = 'Television Series'
				output = h.LinkToCategory(category, value)
			elseif value == 'Live Action'
				then 
					category = 'Live Action Series'
					output = h.LinkToCategory(category, value)
			elseif value == 'Animated' 
				then 
					category = 'Animated Series'
					output = h.LinkToCategory(category, value)
			elseif value == 'Non Fiction' 
				then 
					category = 'Non Fiction Series'
					output = h.LinkToCategory(category, value)
			elseif value == 'Web' 
				then 
					category = 'Web Series'
					output = h.LinkToCategory(category, value)
			elseif value == 'Podcast'
				then 
					category = 'Podcasts'
					output = h.LinkToCategory(category, value)
			elseif value == 'Video' 
				then 
					category = 'Video Series'
					output = h.LinkToCategory(category, value)
			elseif value == 'Audio Book' 
				then 
					category = 'Audio Books'	
					output = h.LinkToCategory(category, value)
			elseif value == 'Motion Comic' 
				then 
					category = 'Motion Comics'	
					output = h.LinkToCategory(category, value)
		end
		return output, category
	end
	local i
	local list
	local category = ''
	local value = ''
	local output_categories = {}
	local output = ''
	
	table.insert(output_categories, 'Series')
	
	if not h.isempty(series_type)
		then
			list = h.explode(";", series_type)
			output = {}
			for i = 1, #list do
				value = h.trim(list[i])
				value, category = add_link_and_category(value)
				table.insert(output, value)
				table.insert(output_categories, category)
			end
			output = mw.text.listToText(output, ', ', ', ')
	end
	
	return output..h.add_categories(output_categories)
end



return p
Advertisement