My Little Pony Friendship is Magic Wiki
Register
Advertisement

Documentation for this module may be created at Module:Episode/doc

--Please see [[Template:Episode]] for documentation. Do not use #invoke directly.
--Template must pass calculated #titleparts call as named param "tp".
local p = {}
local convert = require('Module:Nameconvert').call

function p.main(frame)
	return p.call(frame:getParent().args, frame.args.tp)
end

function p.call(args, tp)
	if not tp then
		return '<span class="error">missing title part</span>'
	end
	local prefix = args.pre or ''
	local suffix = args.suf or ''
	local linkText = args[3] or mw.ustring.gsub(prefix .. suffix, '/', '')
	local offset = 0
	if args[2] == 'prev' then
		offset = -1
	elseif args[2] == 'next' then
		offset = 1
	end
	--Prevent accidentally mixing episodes and non-episodes
	if mw.text.trim(args.ismisc or '') == '' and convert({tp, checkmisc='x'}) == '1' then
		return '<span class="error">missing ismisc</span>'
	end
	local overall = convert({tp, r='oa', PonyLife=args.PonyLife, Gen5=args.Gen5})
	if overall == '0' then
		return 'N/A'
	end
	local title = convert({overall + offset, PonyLife=args.PonyLife, Gen5=args.Gen5, getmisc=args.ismisc})
	if title == 'N/A' or title == 'TBA' or mw.ustring.find(title, 'class="error"', 1, true) then
		return title
	end
	if linkText == 'TITLE' then
		linkText = title
	end
	if mw.text.trim(args.ismisc or '') ~= '' and (not args[3] or args[3] == 'TITLE') then
		if linkText == '' then linkText = title end
		linkText, found = mw.ustring.gsub(linkText, '/Animated shorts', ' animated shorts')
		if found > 0 then
			linkText = mw.ustring.gsub(linkText, 'My Little Pony Equestria Girls: ', '')
		end
	end
	local link = prefix .. title .. suffix
	if linkText == '' or linkText == link then
		return '[' .. '[' .. link .. ']]'
	else
		return '[' .. '[' .. link .. '|' .. linkText .. ']]'
	end
end

return p
Advertisement