FANDOM


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) --
------------------------------------------------
local function chapterFix (chapter)
	if tonumber(chapter) > 700 then
		return '700+' .. ( tonumber(chapter) - 700 )
	else
		return chapter or ''
	end
end
 
----------------------------------------------------------
-- Public functions (called from a Template or article) --
----------------------------------------------------------
function Infobox.titleChapter(frame)
	local args = getArgs(frame)
	local out = {}
	if mw.title.getCurrentTitle().isContentPage == true then
		table.insert( out, HF.Category('Chapters') )
		if args['name'] then
			table.insert( out, args['name']:match("[^(]*") )
		else
			table.insert( out, pageTitle:match("[^(]*") )
		end
		local _editFormURL = mw.html.create('span')
			:css('float','right'):css('font-size','x-small')
            :wikitext( HF.Link('Special:FormEdit/Chapter/' .. pageTitle, 'edit') ):allDone()			
		local editFormURL = tostring(_editFormURL)
		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['volume'] 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.chapterVolume (frame)
	local args = getArgs(frame)
	local volume = MN { 'Volume', args['volume'], ['boruto'] = args['boruto'] }
	mw.smw.set { ['Volume number'] = args['volume'] }
	if volume then
		return ( "''%s'' (#%s)" ):format( volume, args['volume'] )
	else
		return nil
	end
end
 
function Infobox.chapterPrevious (frame)
	local args = getArgs(frame)
	local previous = MN { 'Chapter', args['chapter'], '-1', ['boruto'] = args['boruto'] }
	if previous then
		return ('"%s"'):format(previous)
	else
		return nil
	end
end
 
function Infobox.chapterChapter (frame)
	local args = getArgs(frame)
	mw.smw.set {
		['Chapter number'] = args['chapter']
	}
	if args['boruto'] == 'Yes' then
		mw.smw.set { ['Manga'] = 'Boruto' }
		return ("''Boruto'' #%s")
			:format( chapterFix( args['chapter'] ) )
	else
		mw.smw.set { ['Manga'] = 'Naruto' }
		return ("''Naruto'' #%s")
			:format( chapterFix( args['chapter'] ) )
	end
end
 
function Infobox.chapterNext (frame)
	local args = getArgs(frame)
	local nextchapter =
		MN {
			'Chapter', args['chapter'], '1',
			['boruto'] = args['boruto']
		}
	if nextchapter then
		return ('"%s"'):format( nextchapter )
	else
		return nil
	end
end
 
function Infobox.chapterAnime( frame )
	local args = getArgs(frame)
	local out = {}
	local query =
		mw.smw.ask {
			HF.Link('Concept:Episodes'),
			( HF.Link('Manga Chapter::%s') )
				:format( args['chapter'] or 0 ),
			( HF.Link('Manga::%s') )
				:format( args['boruto'] == 'Yes' and 'Boruto' or 'Naruto' ),
			'?Anime',
			'?Episode number',
			'sort=Episode number',
			'mainlabel=main'
		}
	local Animes =
		{
			['Boruto'] = 'Boruto',
			['Naruto: Shippuden'] = 'Naruto Shippūden',
		}
 
	if type( query ) == 'table' then
		for _,v in ipairs( query ) do
			table.insert(
				out,
				HF.Link(
					v['main']:match('%[%[([^|]*)|?'),
					( "''%s'' #%s" ):format(
						Animes[v['Anime']] or 'Naruto',
						v['Episode number']
					)
				)
			)
		end
		return table.concat( out, ', ' )
	else
		return nil
	end
end
 
function Infobox.chapterCharacters( frame )
		local args = getArgs(frame)
		local query =
			mw.smw.ask {
				HF.Link('Concept:Characters/Manga'),
				( HF.Link('Debut manga::%s') )
					:format( args['chapter'] or 0 ),
				'Debut manga type::Chapter',
				( HF.Link('Manga::%s') )
					:format( args['boruto'] == 'Yes' and 'Boruto' or 'Naruto' ),
				'?Maintenance',
				'mainlabel=main'
			}
		return mediaDebutList ( query )
end
 
function Infobox.chapterJutsu( frame )
	local args = getArgs(frame)
	local query =
		mw.smw.ask {
			HF.Link('Concept:Jutsu/Manga'),
			( HF.Link('Debut manga::%s') )
				:format( args['chapter'] or 0 ),
			HF.Link('Debut manga type::Chapter'),
			( HF.Link('Manga::%s') )
				:format( args['boruto'] == 'Yes' and 'Boruto' or 'Naruto' ),
			'?Maintenance',
			'mainlabel=main'
		}
	return mediaDebutList ( query )
end
 
function Infobox.chapterTools( frame )
	local args = getArgs(frame)
	local query =
		mw.smw.ask {
			HF.Link('Concept:Tools/Manga'),
			( HF.Link('Debut manga::%s') )
				:format( args['chapter'] or 0 ),
			HF.Link('Debut manga type::Chapter'),
			( HF.Link('Manga::%s') )
				:format( args['boruto'] == 'Yes' and 'Boruto' or 'Naruto' ),
			'?Maintenance',
			'mainlabel=main'
		}
	return mediaDebutList ( query )
end
 
function Infobox.chapterTeams( frame )
	local args = getArgs(frame)
	local query = mw.smw.ask {
		HF.Link('Concept:Teams'),
		HF.Link('Appears in::Manga'),
		( HF.Link('Debut manga::%s') )
			:format( args['chapter'] or 0 ),
		HF.Link('Debut manga type::Chapter'),
		( HF.Link('Manga::%s') )
			:format( args['boruto'] == 'Yes' and 'Boruto' or 'Naruto' ),
		'?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
Community content is available under CC-BY-SA unless otherwise noted.