Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Quote

From Datacron Continuity Database, the Star Wars Legends Wiki
Revision as of 16:51, 21 January 2026 by DatacronKeeper (talk | contribs) (Created page with "local p = {} local h = require("Module:HF") local getArgs = require('Dev:Arguments').getArgs -------------------------------------------------------------------------------------------------- function p.main(quotation, speaker, source, speaker_needed, source_needed) local category = '' local value = '' local output_categories = {} local cite = '' local output = '' output = p.get_quotation(quotation, source) source, category = p.get_source(source, source_needed...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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, speaker_needed, source_needed)
	local category = ''
	local value = ''
	local output_categories = {}
	local cite = ''
	local output = ''
	
	output = p.get_quotation(quotation, source)

	source, category = p.get_source(source, source_needed)
	table.insert(output_categories, category)
	
	speaker, category = p.get_speaker(speaker, speaker_needed)
	table.insert(output_categories, category)

	if output ~= ''
		then
			if speaker ~= ''
				then cite = tostring( mw.html.create('span'):addClass('md-quote__speaker'):wikitext('—'..speaker) )..source
				else cite = source
			end
			output = output .. tostring( mw.html.create('cite'):addClass('md-quote__cite'):wikitext(cite) )
			output = tostring( mw.html.create('div'):addClass('md-quote'):wikitext(output) )
	end
	
	return output, output_categories
end


--------------------------------------------------------------------------------------------------
-- Template:QuoteWithCat
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 output_categories = ''
	local output = ''
	
	output, output_categories = p.main(quote, speaker, source, true, true)

	return output..h.add_categories(output_categories)
end


--------------------------------------------------------------------------------------------------
-- Template:Quote
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 output = p.main(quote, speaker, source, false, true)

	return output
end


--------------------------------------------------------------------------------------------------
-- Template:Conversation
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(speaker, image)
		local image_size = '60px'
		local tag_div_image = ''
		local cite = mw.html.create('cite'):addClass('md-quote__cite')
		
		if image ~= ''
			then tag_div_image = tostring(mw.html.create('div'):addClass('md-quote__image'):wikitext('[[File:'..image..'|'..image_size..']]') )
		end
		cite:wikitext(tag_div_image..speaker)
		return tostring(cite)
	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)
						value = tostring( mw.html.create('div'):addClass('md-quote__speaker'):wikitext(value) )
						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(speakers[i],images[i])..quotes[i] )
			end
	end
	
	if categorize == true
		then output_categories = h.add_categories(output_categories)
		else output_categories = ''
	end
	
	output = table.concat(output)
	output = mw.html.create('div'):addClass('md-quote md-quote--conversation'):wikitext(output)

	return tostring(output)..output_categories
end


--------------------------------------------------------------------------------------------------
function p.get_quotation(value, source)
	local blockquote = mw.html.create('blockquote'):addClass('md-quote__text')
	local output = ''

	if value
		then
			if source
				then blockquote:attr('cite', tostring( mw.uri.fullUrl(source) ) )
			end
			value = tostring( mw.html.create('p'):wikitext(value) )
			output = tostring(blockquote:wikitext(value))
	end

	return output
end


--------------------------------------------------------------------------------------------------
function p.get_source(value, source_needed)
	local category = ''
	local output = ''
	
	if not h.isempty(value)
		then 
			output = h.break_link(value, 1)
			output = h.Link(output, '[source]')
			output = tostring( mw.html.create('span'):addClass('md-quote__source'):wikitext(output) )
		elseif source_needed
			then category = 'Quote Source Needed'
	end

	return output, category
end


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

	if value
		then
			output = value
			if h.is_link(value)
				then 
					category = h.break_link(value, 1)..'/Quotes'
					if string.find(string.lower(category), 'w:c:', 1, true) ~= nil
						then category = ''
					end
				elseif value == 'Narrator'
					then 
						category = value..'/Quotes'
						output = h.Link(value, value)
				else
					category = 'Quote Speaker Without Link'
			end
	end
	
	if speaker_needed == false
		then category = ''
	end
	
	return output, category
end


-- *****************************************************************************************************************
-- used for /'Quotes' categories to form list of all quotes
--------------------------------------------------------------------------------------------------
function p.add_list_of_quotes(frame)
	local pagename = mw.title.getCurrentTitle().text
	local templates = {'Comic', 'Character', 'Episode', 'Team', 'Location', 'Item', 'Race', 'Reality'}
	local categories = {'Comics', 'Characters', 'Episodes', 'Teams', 'Locations', 'Items', 'Races', 'Realities'}
	local i
	local list = {}
	local cite = ''
	local value = ''
	local source = ''
	local output = {}

-- quotes
	for i = 1, #templates do
		value = p.lua_dpl_list('Quote', pagename, templates[i], categories[i])..p.lua_dpl_list('Quote', pagename, templates[i], categories[i], 500)
		table.insert(list, value)
	end

	list = table.concat(list)
	list = frame:preprocess(list)
	list = string.gsub(list, 'no_results', '')
	list = mw.text.split(list, '@@@', true)

	for i = 1, #list-1 do
		source, value = string.match(list[i], '(.+)~(.+)')
		if not h.isempty(source)
			then
				value = p.get_quotation(value, source)
				source = h.Link(source, source) -- require("Module:StandardizedName").lua_standardized_link is not used, because it uses expensive function to get page's type for every quote's source 
				source = tostring( mw.html.create('span'):addClass('md-quote__speaker'):wikitext('—'..source) )
				cite = tostring( mw.html.create('cite'):addClass('md-quote__cite'):wikitext(source) )
				value = tostring( mw.html.create('div'):addClass('md-quote'):wikitext(value..cite) )
				table.insert(output, value)
		end
	end

-- conversation
	list = p.lua_dpl_list('Conversation', pagename, templates[i], categories[i])..p.lua_dpl_list('Conversation', pagename, templates[i], categories[i], 500)
	list = frame:preprocess(list)
	list = string.gsub(list, 'no_results', '')
	list = mw.text.split(list, '@@@', true)
	for i = 1, #list-1 do
		source, value = string.match(list[i], '(.+)~(.+)')
		source = h.Link(source, source)
		value = string.gsub(value, '%[%[Category:.-%/Quotes%]%]', '')
		value = value..tostring( mw.html.create('div'):addClass('md-quote__speaker'):wikitext('—'..source) )
		table.insert(output, value)
	end

	return mw.text.listToText(output, '\n', '\n')
end

--------------------------------------------------------------------------------------------------
function p.lua_dpl_list(s_type, pagename, template, category, offset)
	local output = {}
	
	table.insert(output, '{{#dpl:')
	table.insert(output, '|category = '..pagename)
	if s_type == 'Quote'
		then
			table.insert(output, '|category = '..category)
			table.insert(output, '|notuses = Template:Conversation')
			table.insert(output, '|include = {Marvel Database:'..template..' Template}:Quotation')
		else 
			table.insert(output, '|category = BlockQuotes')
			table.insert(output, '|uses = Template:Conversation')
			table.insert(output, '|notnamespace = Category')
			table.insert(output, '|include = {Conversation}')
	end
	table.insert(output, '|ordermethod = sortkey')
	table.insert(output, '|mode = userformat')
	table.insert(output, '|secseparators = %PAGE%~,@@@')
	table.insert(output, '|noresultsheader = no_results')
	table.insert(output, '|allowcachedresults = true')
	if not h.isempty(offset)
		then table.insert(output, '|offset ='..offset)
	end
	table.insert(output, '}}')

	return table.concat(output)
end


return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.