Module:Dialogue

From the Tesseract Wiki, the wiki for all things Marvel Cinematic Universe
Jump to navigation Jump to search

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

local p = {}

function p.invoke_main(frame)
	local args = frame:getParent().args
	return p.main(args)
end

function p.main(args)
	local dtype = string.lower( args[1] or '' )
	local pagetitle = mw.title.getCurrentTitle()
	local pagename = pagetitle.text
	local basepagename = pagetitle.baseText
	local ns120 = pagetitle.namespace == 120  -- Transcript namespace
	local linkarg = args.link
	local link = '[[' .. ( linkarg or pagename ) .. ']]'
	local linkb = args.linkb
	local linkband = linkb and ( '[[' .. linkb .. ']] and ' ) or ''
	local title = args.title or pagename
	local displaynumber = string.gsub(pagename,'[^%d]', '') or ''
	
	local sentences = {
		['irl'] = 'a transcript related to ' .. linkband .. link,
	}
	local defaultText = 'dialogue related to ' .. linkband .. link
	local source = 'The content below is copied verbatim from the Marvel Cinematic Universe and thus copyrighted by [[Marvel Studios]].'
	if dtype == 'irl' then
		source = 'The content below has been transcribed from a real-life act by [[Marvel Studios]].'
	end
	
	local startTable = '{| class="messagebox standard-talk plainlinks" style="border-left:none; text-align:center;"\n|-\n| '
	local line = 'This page contains ' .. ( sentences[dtype] or defaultText ) .. '.'
	local endTable = '<br clear="all" /><div style="font-size:0.85em; line-height:1.4em;">' .. source .. '</div>\n|-\n|}'
	
	local header = startTable .. line .. endTable
	
	local cats = {
		['irl'] = {'Real-life transcripts'},
		['music'] = {'Music transcript', 'Nonspoken Transcripts'},
		['character'] = {'Character dialog'},
		['web'] = {'Web series transcript'},
		['film'] = {'Film transcript'},
		['oneshot'] = {'One-Shot transcript'},
		['episode'] = {'Episode transcript'}
	}
	
	local setcat = ''
	local displayTitle = ''
	if ns120 then
		local cat = cats[dtype] or {'Miscellaneous transcript'}
		setcat = '[[Category:' .. table.concat(cat, ']][[Category:') .. ']]'
		
		local titleTypeIds = {
			['character'] = 1,
			['film'] = 2,
			['oneshot'] = 2,
			['episode'] = 2,
			['web'] = 2,
		}
		local titleTypes = {
			'Dialog for ' .. title,
			'Transcript of ' .. title,
		}
		local newTitle = titleTypes[ titleTypeIds[dtype] or 2 ]
		displayTitle = mw.getCurrentFrame():callParserFunction{ name = 'DISPLAYTITLE', args = { newTitle } }
		-- set Transcript authors SMW
		if string.match(args.author or '', '%S') then
			local authors = {}
			for auth in string.gmatch(args.author, "[^;]+") do
				table.insert(authors, auth)
			end
			mw.smw.set( { ['Transcript authors'] = authors } )
		end
	end
	
	return header .. setcat .. displayTitle
end

return p