Documentation for this module may be created at Module:C/doc
local p = {}
local getArgs = require('Dev:Arguments').getArgs
local h = require("Module:HF")
local standard = require("Module:StandardizedName")
--------------------------------------------------------------------------------
function p.reference(frame)
local args = getArgs(frame)
local arg = args[1]
local arg2 = args[2]
local pagename = ''
local pagetype = ''
local info = ''
local info2 = ''
local link = ''
local category = ''
local output_categories = {}
local output = ''
if not h.isempty(arg)
then
pagename, category = standard.lua_replace_number_sign(arg)
table.insert(output_categories, category)
if string.find(pagename, ' Vol ') ~= nil
then pagetype = 'Vol'
elseif string.find(pagename, ' Season ') ~= nil
then pagetype = 'Season'
end
if pagetype == 'Vol' or pagetype == 'Season'
then
info = standard.lua_get_title_volume_issue(pagename, pagetype)
link = info.link.all
if not h.isempty(arg2)
then
if string.match(arg2, '^%d+$') ~= nil
then
info2 = standard.lua_get_title_volume_issue(info.noissue..' '..arg2, pagetype)
output = link..'–'..h.Link(info2.link.part1, arg2)
else
output = link..' '..arg2
end
else
output = link
end
else
link = string.lower(arg)
if string.find(link, '{{cite', 1, true)
then table.insert(output_categories, 'References With Cite Template')
elseif string.find(link, '{{vl', 1, true)
then table.insert(output_categories, 'References With Vl Template')
elseif string.find(link, '{{ml', 1, true)
then table.insert(output_categories, 'References With Ml Template')
elseif string.find(link, '{{', 1, true)
then table.insert(output_categories, 'References With Other Templates')
elseif string.find(link, '[[', 1, true)
then table.insert(output_categories, 'References With Internal Links')
elseif string.find(link, '[', 1, true)
then table.insert(output_categories, 'References With External Links')
else
table.insert(output_categories, 'References With Plain Text')
end
output = standard.lua_standardized_link(arg, 'Film')
if not h.isempty(arg2)
then output = output..' '..arg2
end
end
else
output = 'Reference Needed'
end
return output..h.add_categories(output_categories)
end
--------------------------------------------------------------------------------
function p.referenceName(frame)
local args = getArgs(frame)
local arg = args[1]
local arg2 = args[2]
local output = ""
if h.isempty(arg)
then
output = "Reference Needed"
else
output = string.gsub(arg, ":", "")
output = string.gsub(output, "%.", "")
output = string.gsub(output, "%[", "")
output = string.gsub(output, "%]", "")
output = string.gsub(output, '%{', '')
output = string.gsub(output, '%}', '')
output = string.gsub(output, '%&', '')
output = string.gsub(output, '%$', '')
output = string.gsub(output, '%%', '')
output = string.gsub(output, '%<', '')
output = string.gsub(output, '%>', '')
output = string.gsub(output, '%#', '')
end
if not h.isempty(arg2)
then output = output .. "-" .. arg2
end
return output
end
--------------------------------------------------------------------------------
function p.lua_cite(args)
local url = args.url
local title = args.title
local archiveurl = args.archiveurl
local archivedate = args.archivedate
local author = args.author or args.host or ''
local first = args.first
local last = args.last
local coauthors = args.coauthors
local date = args.date
local year = args.year
local month = args.month
local language = args.language
local format = args.format
local page = args.page
local pages = args.pages
local chapter = args.chapter
local time = args.time
local work = args.work
local website = args.website
local publisher = args.publisher
local accessdate = args.accessdate
local accessyear = args.accessyear
local accessmonthday = args.accessmonthday
local originaldate_text = " Retrieved on "
local quote = args.quote
local quotespeaker = args.quotespeaker
local isbn = args.isbn or args.ISBN
local output = ""
if h.isempty(title)
then
output = 'Error on call to "Template:Cite": Parameter '.."''title''' must be specified"..h.Category('Pages with script errors')
elseif ( not h.isempty(archiveurl) and h.isempty(archivedate) ) or ( h.isempty(archiveurl) and not h.isempty(archivedate) )
then output = 'Error on call to "Template:Cite": Parameters '.."'''archiveurl''' and '''archivedate''' must be both specified or both omitted"..h.Category('Pages with script errors')
else
if not h.isempty(author) or not h.isempty(last)
then
if not h.isempty(last) -- author's last name
then
output = output .. last
if not h.isempty(first) -- author's first name
then output = output .. ', ' .. first
end
else
output = output .. author
end
if not h.isempty(coauthors)
then output = output .. '; ' .. coauthors
end
end
if not h.isempty(date)
then output = output .. ' (' .. date .. ')'
elseif not h.isempty(year)
then
if not h.isempty(month)
then output = output .. ' (' .. month .. ' ' .. year .. ')'
else output = output .. ' (' .. year .. ')'
end
end
if not h.isempty(archiveurl)
then output = output .. ' [' .. archiveurl .. ' ' .. title .. ']'
elseif not h.isempty(url)
then output = output .. ' [' .. url .. ' ' .. title .. ']'
else output = output .. ' ' .. title
end
if not h.isempty(isbn)
then output = output ..' (ISBN: ' .. h.Link('Special:BookSources/'..isbn, isbn) .. ')'
end
if not h.isempty(language)
then output = output .. ' (in ' .. language .. ')'
end
if not h.isempty(format)
then output = output .. ' ' .. format
end
if not h.isempty(work)
then output = output .. " ''" .. work .. "''"
end
if not h.isempty(website)
then output = output .. " ''" .. website .. "'' (Podcast)"
end
if not h.isempty(chapter)
then output = output .. ' chapter "' .. chapter .. '"'
end
if not h.isempty(page)
then output = output .. " page " .. page
end
if not h.isempty(pages)
then output = output .. " pages " .. pages
end
if not h.isempty(time)
then output = output .. '. Event occurs at ' .. time
end
if not h.isempty(publisher)
then output = output .. " published by " .. publisher
end
output = output .. "."
if not h.isempty(archivedate)
then
output = output .. " Archived from " .. "[" .. url .. " the original] on " .. archivedate .. "."
originaldate_text = " Originally retrieved on "
end
if not h.isempty(accessdate)
then output = output .. originaldate_text .. accessdate .. "."
elseif not h.isempty(accessyear)
then
if not h.isempty(accessmonthday)
then output = output .. originaldate_text .. accessmonthday .. ", " .. accessyear .. "."
else output = output .. originaldate_text .. accessyear .. "."
end
end
if not h.isempty(quote)
then
quote = '"' .. quote .. '"'
if not h.isempty(quotespeaker)
then quote = quotespeaker .. ': ' .. quote
end
output = output .. '<div class="md-cite"><blockquote>' .. quote .. '</blockquote></div>'
end
end
return output
end
--------------------------------------------------------------------------------
function p.cite(frame)
local args = getArgs(frame)
local title = args.title
local is_ref = args.ref
local refname = args.refname
local cite = p.lua_cite(args)
local output = ""
if not h.isempty(is_ref) and is_ref == 'true'
then
refname = p.referenceName({refname or title})
output = frame:extensionTag{name = 'ref', content = cite, args = {name = refname}}
elseif not h.isempty(refname)
then
refname = p.referenceName({refname})
output = frame:extensionTag{name = 'ref', args = {name = refname}}
else
output = cite
end
return output
end
--------------------------------------------------------------------------------
function p.lua_external(site_link, site_name, link, text, show_site, is_wiki)
local output = ''
if not h.isempty(show_site) and (show_site == true or show_site == 'true')
then show_site = true
else show_site = false
end
if is_wiki
then
if not h.isempty(link)
then
text = text or link
text = string.gsub(text, '_', ' ')
output = h.Link(site_link..link, text)
if show_site
then output = output..' on '..site_name
end
else
output = h.Link(site_link, site_name)
end
else
if not h.isempty(link)
then
text = text or link
text = string.gsub(text, '_', ' ')
output = '['..site_link..link..' '..text..']'
if show_site
then output = output..' on '..site_name
end
else
output = '['..site_link..' '..site_name..']'
end
end
return output
end
--------------------------------------------------------------------------------
--used in Template:Appendix
function p.appendix(frame)
local args = getArgs(frame)
local arg1 = args[1] or ''
local arg2 = args[2] or arg1
local site_link = 'http://www.marvunapp.com/'
local site_name = 'The Appendix to the Handbook of the Marvel Universe'
local is_ref = args.ref
local refname = args.refname
local output = p.lua_external(site_link, site_name, arg1, arg2, args.show_site, false)
if not h.isempty(is_ref) and is_ref == 'true'
then
refname = p.referenceName({refname or site_link..arg1})
return frame:extensionTag{name = 'ref', content = output..' on '..site_name, args = {name = refname}}
elseif not h.isempty(refname)
then
refname = p.referenceName({refname})
return frame:extensionTag{name = 'ref', args = {name = refname}}
else
return output
end
end
--------------------------------------------------------------------------------
--used in:
---- Template:Battlestar Galactica
---- Template:Dark Horse
---- Template:DC
---- Template:Disney
---- Template:Doctor Who
---- Template:Fortnite
---- Template:Image Wiki
---- Template:Lovecraft
---- Template:MCU
---- Template:Star Trek
---- Template:Star Wars
function p.interwiki(frame)
local list = {
['darkhorse'] = 'Dark Horse wiki',
['dc'] = 'DC Database',
['disney'] = 'Disney wiki',
['fortnite'] = 'Fortnite wiki',
['galactica'] = 'Battlestar Galactica wiki',
['image'] = 'Image Comics wiki',
['lovecraft'] = 'H.P. Lovecraft wiki',
['marvelmovies']= 'Marvel Movies wiki',
['mcu'] = 'Marvel Cinematic Universe wiki',
['startrek'] = 'Memory Alpha (Star Trek wiki)',
['starwars'] = 'Wookieepedia (Star Wars wiki)',
['tardis'] = 'Tardis (Doctor Who wiki)',
}
local args = getArgs(frame)
local arg1 = args[1] or ''
local arg2 = args[2] or arg1
local site_link = args.site_link
local site_name = list[site_link]
local is_ref = args.ref
local refname = args.refname
local output = p.lua_external('w:c:'..site_link..':', site_name, arg1, arg2, args.show_site, true)
if not h.isempty(is_ref) and is_ref == 'true'
then
refname = p.referenceName({refname or site_link..arg1})
return frame:extensionTag{name = 'ref', content = output..' on '..site_name, args = {name = refname}}
elseif not h.isempty(refname)
then
refname = p.referenceName({refname})
return frame:extensionTag{name = 'ref', args = {name = refname}}
else
return output
end
end
--------------------------------------------------------------------------------
--used in Template:Wikipedia
function p.wikipedia(frame)
local args = getArgs(frame)
local arg1 = args[1] or ''
local arg2 = args[2] or arg1
local site_link = 'wikipedia:'
local site_name = 'Wikipedia.org'
local is_ref = args.ref
local refname = args.refname
local output = p.lua_external(site_link, site_name, arg1, arg2, args.show_site, true)
if not h.isempty(is_ref) and is_ref == 'true'
then
refname = p.referenceName({refname or site_link..arg1})
return frame:extensionTag{name = 'ref', content = output..' on '..site_name, args = {name = refname}}
elseif not h.isempty(refname)
then
refname = p.referenceName({refname})
return frame:extensionTag{name = 'ref', args = {name = refname}}
else
return output
end
end
return p