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 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, source_needed)
table.insert(output_categories, category)
speaker, category = p.get_speaker(speaker, speaker_needed)
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 output_categories = ''
local output = ''
output, output_categories = p.main(quote, speaker, source, true, true)
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 output = ''
return p.main(quote, speaker, source, false, true)
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, source_needed)
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 ))
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 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 speaker_needed == 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]] ' --p.quotation_mark('“ ')
end
function p.right_quotation_mark()
return ' [[File:Quote2.png]]' --p.quotation_mark(' „')
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'}
local categories = {'Comics', 'Characters', 'Episodes', 'Teams', 'Locations', 'Items', 'Races'}
local i
local list = {}
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
source = h.Link(source, source)
value = p.get_quotation(value)..'\n::—'..source
value = tostring( mw.html.create( 'div' ):attr( 'class', 'quote' ):wikitext(value) )
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 = value..'\n::—'..source
--value = tostring( mw.html.create( 'div' ):attr( 'class', 'quote' ):wikitext(value) )
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