FANDOM


-- This module implements [[Template:TORcite]].
 
local p = {}
 
local function makeCategoryLink(cat)
	-- "Category" is split out here so that the module isn't put into the
	-- category "%s" when the page is saved.
	return string.format('[[%s:%s]]', 'Category', cat)
end
 
local function makeWikitextError(msg)
	local ret = ''
	ret = ret .. string.format(
		'<strong class="error">[[Template:TORcite]] error: %s.</strong>',
		msg
	)
	if mw.title.getCurrentTitle().namespace == 0 then
		ret = ret .. makeCategoryLink('Articles with template errors')
	end
	return ret
end
 
local function check(str)
	if str == nil then
		str = ""
	end
	return str
end
 
function p.citation(args, data)
	local image = "[[File:SWTOR mini.png|x14px|link=Star Wars: The Old Republic]] "
 
	local game = "''[[Star Wars: The Old Republic]]''&mdash;"
	if args.exp then
		game = data.expansions[args.exp]
	end
 
	local src = ''
	if args.chapter then
		local chap = tonumber(args.chapter)
		if not chap then
			src = args[1] or '{{{1}}}'
		else
			if args.exp then
				src = data.chapters[args.exp][chap]
			else
				src = data.chapters.kotfe[chap]
			end
		end
	else		
		local mode = data.modes[args.type]
		if not mode then
			src = args[1] or '{{{1}}}'
		else
			src = check(mode.a) .. check(args[1]) .. check(mode.b) .. check(args[2]) .. check(mode.c) .. check(args[3])
		end
	end
 
	local result = image .. game .. src
	return result
end
 
function p.main(frame)
	local data = mw.loadData('Module:TORcite/data')
	local args = {}
	for k, v in pairs(frame:getParent().args) do 
		v = v:match('^%s*(.-)%s*$') -- trim whitespace
		if v ~= '' then
			args[k] = v
		end
	end
	return p.citation(args, data) or '{{{1}}}'
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.