Kingdom Hearts Wiki
Advertisement
This page contains Lua code for Template:Cite.

-- This module implements cite templates.
-- See {{cite}} for the base template and a documentation.
local cite = {}
local getArgs = require('Dev:Arguments').getArgs
local data = mw.loadData('Module:Codename')
 
-- Helper functions
local function titlelink(data, version)
    local name = "\'\'" .. data['title'] .. "\'\'"
    local link = data['link']
    local shortname = data['shortname']
    
    local appendix = ''
    if data['appendix'] then appendix = ' ' .. data['appendix'] end
    
    if version and data['versions'][version] then
        appendix = appendix .. ' ' .. data['versions'][version]['name']
    end

    return string.format("[" .. "[" .. "%s|\'\'%s\'\'%s]]", link, shortname, appendix)
end
 
local function gamefile(file)
    return string.format(', file: <code>%s</code>', file)
end
 
local function script(game, scriptsection, display)
    game = string.lower(game)
    local gamename = data[game]['shortname']
    if display then
        return string.format(' [' .. '[' .. '%s script#%s|script &sect; \"%s\"]]', gamename, scriptsection, display)
    else
        return string.format(' [' .. '[' .. '%s script#%s|script &sect; \"%s\"]]', gamename, scriptsection, scriptsection)
    end
end

local function tcrf(data, tcrfsection, tcrfpagelink, tcrfpagedesc)
    local name = data['name']
    local pagelink
    local desc
    if tcrfpagelink then
        pagelink = string.gsub(tcrfpagelink, '%s+', '_')
        desc = tcrfpagedesc
    else
        pagelink = string.gsub(data['title'], '%s+', '_')
        desc = tcrfsection
    end
    local title = data['title']
    return string.format(', [' .. 'https://tcrf.net/%s#%s %s on The Cutting Room Floor]', pagelink, string.gsub(tcrfsection, '%s+', '_'), desc)
end

-- Produces the cite template.
function cite.main(frame)
	local args = getArgs(frame)
	
	local entry = args[1]
    local data = assert(data[entry], 'Could not find an entry in Module:Codename matching this input')
    
	local version
	if args['version'] then version = string.lower(args['version']) end
	local linksec = titlelink(data, version)
  	
  	local contentsec = ''
 
    if args['file']
        then contentsec = gamefile(args['file'])
    elseif args['script']
        then contentsec = script(game, args['script'], args['display'])
	elseif args['tcrf']
	    then contentsec = tcrf(data, args['tcrf'], args['pagelink'], args['pagedesc'])
	elseif args['guide']
	    then contentsec = ", ''" .. data[game]['guide']['title'] .. "'', p. " .. args['guide']
    elseif args['manual']
        then contentsec = ', ' .. data[game]['manual'][args['version']] .. ', p. ' .. args['manual']
    elseif args[2] or args['other']
        then contentsec = ', ' .. (args[2] or args['other'])
	end
 
	local refname = ''
	if args['name'] then refname = ' name="' .. args['name'] .. '"' end
 
	local citeoutput = '<ref' .. refname ..'>' .. linksec .. contentsec .. '</ref>'
 
	return frame:preprocess(citeoutput)
end
 
return cite
Advertisement