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

local p = {}
local h = require("Module:HF")
local getArgs = require('Dev:Arguments').getArgs

--------------------------------------------------------------------------------------------------
function p.main(quotation, speaker, source, categorize_speaker)
	local tag_div = mw.html.create( 'div' ):attr( 'class', 'quote' )
	local tag_span = mw.html.create( 'span' ):css( 'font-style', 'italic' )
	local category = ''
	local value = ''
	local output_categories = {}
	local output = ''

	source, category = p.get_source(source)
	table.insert(output_categories, category)
	
	speaker, category = p.get_speaker(speaker, categorize_speaker)
	table.insert(output_categories, category)
	
	output = p.get_quotation(quotation)
	if output ~= ''
		then
			if speaker ~= ''
				then output = output..'\n::—'..speaker
			end
			output = output..source
			output = tostring( tag_div:wikitext(output) )
	end
	
	return output, output_categories
end


--------------------------------------------------------------------------------------------------
function p.quote_with_category(frame)
	local args = getArgs (frame)
	local quote = args[1] or args['Quote']
	local speaker = args[2] or args['Speaker'] or ''
	local source = args[3] or args['Source'] or ''
	local categorize_speaker = true
	local output_categories = ''
	local output = ''
	
	output, output_categories = p.main(quote, speaker, source, categorize_speaker)

	return output..h.add_categories(output_categories)
end


--------------------------------------------------------------------------------------------------
function p.quote_without_category(frame)
	local args = getArgs (frame)
	local quote = args[1] or args['Quote']
	local speaker = args[2] or args['Speaker'] or ''
	local source = args[3] or args['Source'] or ''
	local categorize_speaker = false
	local output = ''

	return p.main(quote, speaker, source, categorize_speaker)
end


--------------------------------------------------------------------------------------------------
function p.blockquote(frame)
	local args = getArgs (frame)
	local i
	local quotes = {}
	local speakers = {}
	local images = {}
	local value = ''
	local category = ''
	local output_categories = {}
	local output = {}
	local categorize = args['categorize'] or true
	local function blockquote_part(quotation, speaker, image)
		local image_size = '60px'
		local speakers_categories = {}
		local tag_div_image = ''
		
		if not h.isempty(image)
			then tag_div_image = tostring(mw.html.create( 'div' )
				:css( 'height', image_size )
				:css( 'overflow', 'hidden' )
				:wikitext('[[File:'..image..'|'..image_size..']]')
				:done() )
		end
		local tag_td_image = mw.html.create( 'td' )
				:attr( 'valign', 'top' )
				:css( 'width', image_size )
				:css( 'text-align', 'center' )
				:wikitext(tag_div_image..speaker)
				:done()
		local tag_td_quote = mw.html.create( 'td' )
				:attr( 'valign', 'top' )
				:wikitext( quotation )
				:done()
		local tag_tr = mw.html.create( 'tr' )
				:wikitext( tostring(tag_td_image)..tostring(tag_td_quote) )
				:done()  
				
		return tostring(tag_tr)
	end

	for i = 1,20 do
		if not h.isempty(args[i])
			then
				if i % 2 == 1 
					then table.insert( quotes, p.get_quotation(args[i]) )
					else 
						value, category = p.get_speaker(args[i], true)
						table.insert(speakers, value)
						table.insert(output_categories, category)
				end
		end
		table.insert( images, args['Image'..i] or '' )
	end

	if not h.isempty(quotes)
		then
			for i = 1,#quotes do
				table.insert(output, blockquote_part(quotes[i],speakers[i],images[i]) )
			end
	end
	
	local tag_table = mw.html.create( 'table' )
				:css( 'width', '50%' )
				:css( 'border', '1px solid grey' )
				:css( 'text-align', 'left' )
				:wikitext( table.concat(output) )
				:done()  
	
	if categorize == true
		then output_categories = h.add_categories(output_categories)
		else output_categories = ''
	end
	
	return tostring(tag_table)..output_categories
end

--------------------------------------------------------------------------------------------------
function p.blockquote2(frame)
	local args

	local i = 1
	local j = 1
	local k = 1
	local s = ''
	local quotes = {}
	local speakers = {}
	local images = {}
	local output = {}
	local categorize = true

	local function quote_part(qu, sp, im)
		local im2 = ''
		local content = ''
		local link = ''
		local image_size = '60px'
		local speakers_categories = {}

		if not h.isempty(im)
			then im2 = im
			elseif h.lua_isLink(sp)
				then
					link = h.lua_breaklink(sp,1)
					if categorize
						then table.insert(speakers_categories, '[[Category:'..link..'/Quotes]]')
					end
					if h.lua_isexists(link) and not pagetype.lua_isRedirect(link)
						then
							content = h.lua_getContent( h.lua_breaklink(sp,1) )
							im2 = h.lua_getFieldValue(content, 'Image')
						else
							im2 = ''
					end
		end

		local tag_div_arrow = mw.html.create( 'div' )
			:css( 'z-index', '2' )
			:css( 'position', 'relative' )
			:css( 'left', '47%' )
			:css( 'bottom', '22px' )
			:css( 'height', '0px' )
			:wikitext('[[File:Conversation Tail.png|15px]]')
			:done()
		
		local tag_div_image = ''
		if not h.isempty(im2)
			then tag_div_image = tostring(mw.html.create( 'div' )
				:css( 'height', image_size )
				:css( 'overflow', 'hidden' )
				:wikitext('[[File:'..im2..'|'..image_size..']]')
				:done() )
		end
		
		local tag_div_text = mw.html.create( 'div' )
				:css( 'width', image_size )
				:wikitext(tag_div_image..sp..tostring(tag_div_arrow))
				:done()
		local tag_td_image = mw.html.create( 'td' )
				:attr( 'valign', 'top' )
				:css( 'text-align', 'center' )
				:wikitext(tostring(tag_div_text))
				:done()
		local tag_div_quote = mw.html.create( 'div' )
				:css( 'height', 'auto' )
				:css( 'border', '1px solid grey' )
				:css( '-moz-border-radius', '10px 10px 10px 10px' )
				:wikitext( qu )
				:done()		
		local tag_td_quote = mw.html.create( 'td' )
				:attr( 'valign', 'bottom' )
				:wikitext( tostring(tag_div_quote) )
				:done()
		local tag_tr = mw.html.create( 'tr' )
				:wikitext( tostring(tag_td_image)..tostring(tag_td_quote) )
				:done()  
				
		return tostring(tag_tr)..table.concat(speakers_categories)
	end

	if type(frame) == 'table'
		then 
			args = getArgs (frame)
			categorize = args['categorize'] or true
			for i = 1,20 do
				if not h.isempty(args[i])
					then
						if i % 2 == 1 
							then table.insert( quotes, args[i] )
							else table.insert( speakers, args[i] )
						end
				end
				table.insert( images, args['Image'..i] or '' )
			end
		else
			j = string.find(frame, '{{Conversation', 1, true)
			k = string.find(frame, '}}', 1, true)
		
			if j ~= nil and k ~= nil
				then
					frame = string.sub(frame, j+14, k-1)..'|'
					for i = 1,20 do
						j, k, s = string.find(frame, '|%s-Image'..i..'%s-=%s-(.-)|', 1, false)
						if j ~= nil and k ~= nil
							then 
								table.insert(images, s or '')
								frame = string.gsub(frame, string.sub(frame, j, k-1), '')
						end
					end
				
					j = 1
					i = 1
					while i<#frame do
						if j % 2 == 1
							then
								k = string.find(frame, '|', i+1, true)
								table.insert( quotes, string.sub(frame, i+1, k-1) )
								i = k
							elseif string.find(frame, '[[', i, true) ~= nil
								then
									k = string.find(frame, ']]', i, true)
									table.insert( speakers, string.sub(frame, i+1, k+1) )
									i = k+2
								else
									k = string.find(frame, '|', i+1, true)
									table.insert( speakers, string.sub(frame, i+1, k-1) )
									i = k
						end
						j = j + 1
					end
				else return blockquote
			end
	end

	if not h.isempty(quotes)
		then
			for i = 1,#quotes do
				table.insert(output, quote_part(quotes[i],speakers[i],images[i]) )
			end
	end
	
	local tag_table = mw.html.create( 'table' )
				:css( 'width', '50%' )
				:css( 'text-align', 'left' )
				:wikitext( table.concat(output) )
				:done()  
	
	return tostring(tag_table)
	--return mw.text.listToText( images, '\n', '\n' ), mw.text.listToText( quotes, '\n', '\n' ), mw.text.listToText( speakers, '\n', '\n' )
end


--------------------------------------------------------------------------------------------------
--[[
--display a quote from the original comics without autocategorization 
function p.reprint_quote(source)
	local standart = require("Module:StandardizedName")
	local quotation = ''
	local speaker = ''
	local blockquote = ''
	local content = ''
	
	local output = ''
	
	if not h.isempty(source)
		then
			source = standart.lua_standardized_comics_name(source)
			content = h.lua_getContent(source)
			if not h.isempty(content)
				then 
					quotation = h.lua_getFieldValue(content, 'Quotation')
					speaker = h.lua_getFieldValue(content, 'Speaker')
					blockquote = h.lua_getFieldValue(content, 'BlockQuote')
					if not h.isempty(quotation)
						then output = p.main(quotation, speaker, _, false)
						else output = p.blockquote(blockquote)
					end
			end
	end
	
	return output
end
--]]
--------------------------------------------------------------------------------------------------
function p.get_quotation(value)
	local output = ''

	if not h.isempty(value)
		then 
			output = tostring(mw.html.create('span'):css('font-style', 'italic'):wikitext( value ))
			output = p.left_quotation_mark()..output..p.right_quotation_mark()
	end

	return output
end


--------------------------------------------------------------------------------------------------
function p.get_source(value)
	local category = ''
	local output = ''
	
	if not h.isempty(value)
		then 
			output = h.break_link(value, 1)
			output = h.Link(output, '[src]')
			output = tostring(mw.html.create('sup'):attr('class', 'noprint'):wikitext( output ))
		else category = 'Quote Source Needed'
	end

	return output, category
end


--------------------------------------------------------------------------------------------------
function p.get_speaker(value, categorize_speaker)
	local category = ''
	local output = ''

	if not h.isempty(value)
		then
			output = value
			if h.is_link(value)
				then category = h.break_link(value, 1)..'/Quotes'
				elseif h.exists(value)
					then 
						category = value..'/Quotes'
						output = h.Link(value, value)
			end
	end
	
	if categorize_speaker == false
		then category = ''
	end
	
	return output, category
end


--------------------------------------------------------------------------------------------------
--[[
function p.quotation_mark(text)
	local output = mw.html.create( 'span' )
				:css( 'font-family', 'serif' )
				:css( 'font-size', '200%' )
				:css( 'font-weight', 'bold' )
				:css( 'color', '#7C80D9' ) --'#B5B7CF' )
				:wikitext(text)
				:done()
	return tostring(output)
end
--]]

function p.left_quotation_mark()
	return '[[File:Quote1.png]]&nbsp;' --p.quotation_mark('“&nbsp;')  
end


function p.right_quotation_mark()
	return '&nbsp;[[File:Quote2.png]]' --p.quotation_mark('&nbsp;„')  
end

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