Module:HF/Infobox/Volume

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 -- Generates lists local L = require('Dev:List') -- MediaNav Functions local MN = require('Module:HF/MediaNav')._MediaNav -- Parses Yes/No/yes/no/1/0, etc. as consistent true/false local yesno = require( 'Dev:Yesno' )

-- The page title of whatever page is calling the function local pageTitle = mw.title.getCurrentTitle.text local stripLinkToTarget = '^%[*([^%[|]*)|?' local stripPageTitleToBase = "[^(]*"

-- 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

local function firstChapter ( volume, boruto ) local manga = yesno(boruto) == true and 'Boruto' or 'Naruto' local query = mw.smw.ask { HF.Link('Concept:Chapter'), HF.Link('Volume number::%s'):format( volume or 0 ), HF.Link('Manga::%s'):format( manga ), '?Chapter number', 'headers=hide', 'mainlabel=-', 'limit=1', 'sort=Chapter number', 'order=asc', 'searchlabel=', 'default=0' }	if type( query ) == 'table' then return query[1]['Chapter number'] else return '' end end

local function lastChapter ( volume, boruto ) local manga = yesno(boruto) == true and 'Boruto' or 'Naruto' local query = mw.smw.ask { HF.Link('Concept:Chapter'), HF.Link('Volume number::%s'):format( volume or 0 ), HF.Link('Manga::%s'):format( manga ), '?Chapter number', 'headers=hide', 'mainlabel=-', 'limit=1', 'sort=Chapter number', 'order=desc', 'searchlabel=', 'default=0' }	if type( query ) == 'table' then return query[1]['Chapter number'] else return '' end end

-- -- Public functions (called from a Template or article) -- --

function Infobox.titleVolume(frame) local args = getArgs(frame) local out = {} if mw.title.getCurrentTitle.isContentPage == true then table.insert( out, HF.Category('Volumes') ) mw.smw.set { ['Name'] = pageTitle:gsub('&#39;',"'") } 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/Volume/' .. 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 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.volumePrevious ( frame ) local args = getArgs(frame) local previous = MN { 'Volume', args['volume'], '-1', ['boruto'] = args['boruto'] } return previous and ("%s"):format( previous ) or nil end

function Infobox.volumeVolume( frame ) local args = getArgs(frame) local manga = yesno(args['boruto'] or nil) == true and 'Boruto' or 'Naruto' mw.smw.set { ['Volume number'] = args['volume'], ['Manga'] = ( manga ), ['VizManga'] = args['readonline'] }	return args['volume'] .. ( args['readonline']			and ('(Read Online)'):format( args['readonline'] )			or '' ) end

function Infobox.volumeNext( frame ) local args = getArgs(frame) local nextvolume = MN { 'Volume', args['volume'], '1', ['boruto'] = args['boruto'] } return nextvolume and ("%s"):format( nextvolume ) or nil end

function Infobox.volumeCharacters( frame ) local args = getArgs(frame) local manga = yesno(boruto) == true and 'Boruto' or 'Naruto' local out = {} local query = mw.smw.ask { HF.Link('Concept:Characters/Manga'), HF.Link('Debut manga::>%s') :format( firstChapter( args['volume'], args['boruto'] ) ), HF.Link('Debut manga::<%s') :format( lastChapter( args['volume'], args['boruto'] ) ), HF.Link('Debut manga type::Chapter'), HF.Link('Manga::%s'):format( manga ), '?Maintenance', 'mainlabel=main', 'limit=200','named args=yes', 'sort=Debut manga', 'order=asc' } if type( query ) == 'table' and mw.title.getCurrentTitle.isContentPage == true then for _,v in ipairs( query ) do		if v['Maintenance'] == 'Name' then table.insert( out, ("%s"):format( HF.Link(					v['main']:match(stripLinkToTarget):match('([^:]*)$'),					v['main']:match('%[%[:?([^|]*)|?')						:match(stripPageTitleToBase)):match('([^:]*)$') )			)		else table.insert( out,				HF.Link( v['main']:match(stripLinkToTarget):match('([^:]*)$'), v['main']:match('%[%[:?([^|]*)|?') :match(stripPageTitleToBase):match('([^:]*)$') )			)		end end return L.makeList( 'bulleted', out ) else return nil end --[==[

--]==] -- TODO end

function Infobox.volumeJutsu( frame ) local args = getArgs(frame) local manga = yesno(args['boruto'] or nil) == true and 'Boruto' or 'Naruto' local out = {} local query = mw.smw.ask { HF.Link('Concept:Jutsu/Manga'), HF.Link('Debut manga::>%s') :format( firstChapter( args['volume'], args['boruto'] ) ), HF.Link('Debut manga::<%s') :format( lastChapter( args['volume'], args['boruto'] ) ), HF.Link('Debut manga type::Chapter'), HF.Link('Manga::%s'):format( manga ), '?Maintenance', 'mainlabel=main', 'limit=200', 'sort=Debut manga', 'order=asc' }	if type( query ) == 'table' and mw.title.getCurrentTitle.isContentPage == true then for _,v in ipairs( query ) do			if v['Maintenance'] == 'Name' then table.insert( out, ("%s"):format( HF.Link(						v['main']:match(stripLinkToTarget),						v['main']:match('%[%[:?([^|]*)|?')							:match(stripPageTitleToBase) ) )				)			else table.insert( out,					HF.Link( v['main']:match(stripLinkToTarget), v['main']:match('%[%[:?([^|]*)|?') :match(stripPageTitleToBase) )				)			end end return L.makeList( 'bulleted', out ) else return nil end end

function Infobox.volumeTools( frame ) local args = getArgs(frame) local manga = yesno(args['boruto'] or nil) == true and 'Boruto' or 'Naruto' local out = {} local query = mw.smw.ask { HF.Link('Concept:Tools/Manga'), HF.Link('Debut manga::>%s') :format( firstChapter( args['volume'], args['boruto'] ) ), HF.Link('Debut manga::<%s') :format( lastChapter( args['volume'], args['boruto'] ) ), HF.Link('Debut manga type::Chapter'), HF.Link('Manga::%s'):format( manga ), '?Maintenance', 'mainlabel=main', 'limit=200', 'sort=Debut manga', 'order=asc' }	if type( query ) == 'table' and mw.title.getCurrentTitle.isContentPage == true then for _,v in ipairs( query ) do			if v['Maintenance'] == 'Name' then table.insert( out, ("%s"):format( HF.Link(						v['main']:match(stripLinkToTarget),						v['main']:match('%[%[:?([^|]*)|?')							:match(stripPageTitleToBase) ) )				)			else table.insert(					out,					HF.Link( v['main']:match(stripLinkToTarget), v['main']:match('%[%[:?([^|]*)|?') :match(stripPageTitleToBase) )				)			end end return L.makeList( 'bulleted', out ) else return nil end end

function Infobox.volumeChapterSummaries ( frame ) local args = getArgs(frame) local manga = yesno(args['boruto']) == true and 'Boruto' or 'Naruto' local out = {} local query = mw.smw.ask { HF.Link('Concept:Chapter'), HF.Link('Volume number::%s'):format( args['volume'] or 0 ), HF.Link('Manga::%s'):format( manga ), 'mainlabel=main', 'named args=yes', '?Chapter number', '?Kanji name', '?Romaji name', 'sort=Chapter number', 'order=asc' } --[==[ Chapter

--]==]   --TODO if type( query ) == 'table' and mw.title.getCurrentTitle.isContentPage == true then for _,v in ipairs( query ) do			local summaries = frame:newParserValue(				(' Chapter %s \n:\n')				:format( chapterFix( v['Chapter number'] ), '"'..""..HF.Link(							v['main']:match('^%[*([^%[|]*)|?'),							v['main']:match('%[%[:?([^|]*)|?'):match('[^%(]*')					)..""..'"',					v['Kanji name'] or ,					v['Romaji name'] or ,					v['main'],					v['main']				) )			table.insert( out, summaries:expand )		end		return table.concat( out, '\n' )	else		return nil	end end

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