Module:HF/Infobox/Episode

local Infobox = {}

-- Libraries and Global functions --

-- stands for High Frequency local HF = require('Module:HF') -- Parses invocation and template parameters, trims whitespace, and removes blanks. local getArgs = require('Dev:Arguments').getArgs -- MediaNav Functions local MN = require('Module:HF/MediaNav')._MediaNav -- Helper functions (local to not have to worry about namespaces) local mediaDebutList = require('Module:HF/Infobox').mediaDebutList

-- The page title of whatever page is calling the function local pageTitle = mw.title.getCurrentTitle.text

-- Local functions (used only in this Module) --

-- None -- -- Public functions (called from a Template or article) -- -- function Infobox.titleEpisode(frame) local args = getArgs(frame) if mw.title.getCurrentTitle.isContentPage == true then local out = {} table.insert( out, HF.Category('Episodes') ) local _editFormURL = mw.html.create('span') :css('float','right'):css('font-size','x-small') :wikitext( HF.Link('Special:FormEdit/Episode/' .. pageTitle, 'edit') ):allDone local editFormURL = tostring(_editFormURL) if args['name'] then mw.smw.set{ ['Name'] = args['name'], ['Names'] = args['name'] } table.insert( out, ('"%s"'):format(mw.text.trim(args['name']:match('[^(]*'))) )		else			mw.smw.set {				['Name'] = tostring(pageTitle:match("[^(]*"):gsub('&#39;',"'")), ['Names'] = pageTitle:match("[^(]*")			}			table.insert( out, ('"%s"'):format(mw.text.trim(pageTitle:match('[^(]*'))) ) end if args['english'] then mw.smw.set { ['English name'] = args['english'], ['Names'] = args['english'] }		end if args['kanji'] then mw.smw.set { ['Kanji name'] = args['kanji'], ['Names'] = args['kanji'] }		else mw.smw.set{ ['Maintenance'] = 'Kanji' } end if args['romaji'] then mw.smw.set { ['Romaji name'] = args['romaji'], ['Names'] = args['romaji'] }		end if not args['arc'] then mw.smw.set{ ['Uncollected'] = 'Yes' } end return table.concat( out ) .. ( args['ref'] or '' ) .. editFormURL elseif mw.title.getCurrentTitle.namespace == 10 and not pageTitle:match('/testcases') then return nil else return ( args['name'] and args['name']:match('[^(]*') ) or args['english'] or pageTitle:match("[^(]*") end end

function Infobox.episodePrevious (frame) local args = getArgs(frame) local previous = MN { 'Episode', args['episode'], '-1', ['boruto'] = args['boruto anime'], ['shippuden'] = args['shippuden'] }	return previous and ('"%s"'):format( previous ) or nil end

function Infobox.episodeEpisode (frame) local args = getArgs(frame) mw.smw.set { ['Episode number'] = args['episode'] } if args['boruto anime'] == 'Yes' then mw.smw.set { ['Anime'] = 'Boruto' } return ("Boruto #%s"):format( args['episode'] ) elseif args['shippuden'] == 'Yes' then mw.smw.set { ['Anime'] = 'Naruto: Shippuden' } return ("Naruto: Shippūden #%s"):format( args['episode'] ) else mw.smw.set { ['Anime'] = 'Naruto: Original' } return ("Naruto #%s"):format( args['episode'] ) end end

function Infobox.episodeNext (frame) local args = getArgs(frame) local nextepisode = MN { 'Episode', args['episode'], '1', ['boruto'] = args['boruto anime'], ['shippuden'] = args['shippuden'] }	return nextepisode and ('"%s"'):format( nextepisode ) or nil end

function Infobox.episodeManga (frame) local args = getArgs(frame) local out = {} local chapters = mw.text.split( args['chapters'], ',%s*' ) if args['boruto'] == 'Yes' then mw.smw.set { ['Manga'] = 'Boruto' } else mw.smw.set { ['Manga'] = 'Naruto' } end for _,v in ipairs( chapters ) do		mw.smw.set { ['Manga Chapter'] = mw.text.trim(v) } local chapter = tonumber(mw.text.trim(v)) and MN { 'Chapter', mw.text.trim(v), ['DisplayType'] = 'Number', ['boruto'] = args['boruto'] }		if chapter then table.insert( out, chapter ) end end return table.concat( out, ', ' ) end

function Infobox.episodeCharacters( frame ) local args = getArgs(frame) local Boruto = args['boruto anime'] == 'Yes' and true or nil local Shippuden = args['shippuden'] == 'Yes' and true or nil local number = tonumber( args['episode'] or 0 ) + ( Boruto and 720 or ( Shippuden and 220 or 0 ) ) local query = mw.smw.ask { HF.Link('Concept:Characters/Anime'), ( HF.Link('Debut anime::%s') ):format( number ), '?Maintenance', 'mainlabel=main' }	return mediaDebutList ( query ) end

function Infobox.episodeJutsu( frame ) local args = getArgs(frame) local Boruto = args['boruto anime'] == 'Yes' and true or nil local Shippuden = args['shippuden'] == 'Yes' and true or nil local number = tonumber( args['episode'] or 0 ) + ( Boruto and 720 or ( Shippuden and 220 or 0 ) ) local query = mw.smw.ask { HF.Link('Concept:Jutsu/Anime'), ( HF.Link('Debut anime::%s') ):format( number ), '?Maintenance', 'mainlabel=main' }	return mediaDebutList ( query ) end

function Infobox.episodeTools( frame ) local args = getArgs(frame) local Boruto = args['boruto anime'] == 'Yes' and true or nil local Shippuden = args['shippuden'] == 'Yes' and true or nil local number = tonumber( args['episode'] or 0 ) + ( Boruto and 720 or ( Shippuden and 220 or 0 ) ) local query = mw.smw.ask { HF.Link('Concept:Tools/Anime'), ( HF.Link('Debut anime::%s') ):format( number ), '?Maintenance', 'mainlabel=main' }	return mediaDebutList ( query ) end

function Infobox.episodeTeams( frame ) local args = getArgs(frame) local Boruto = args['boruto anime'] == 'Yes' and true or nil local Shippuden = args['shippuden'] == 'Yes' and true or nil local number = tonumber( args['episode'] or 0 ) + ( Boruto and 720 or ( Shippuden and 220 or 0 ) ) local query = mw.smw.ask { HF.Link('Concept:Teams'), HF.Link('Appears in::Anime'), ( HF.Link('Debut anime::%s') ):format( number ), '?Maintenance', 'mainlabel=main' }	return mediaDebutList ( query ) end

- -- Exported functions (used in this and other Modules) -- - -- None. - -- Output (send it back to whatever called it) -- - return Infobox