FANDOM


local p = {}
local episodesManga = mw.loadData( 'Module:Episodes/mangaData' )
local infoboxCreateDataItem = function (label, data)
    return '<data><label>' .. label .. '</label><default>' .. data .. '</default></data>'
end
 
function p.infoboxEpisodeManga(frame)
    local args = frame:getParent().args
    local argEp = args['episode'] or '0A'
    local epData = episodesManga[argEp]
    local months = {[1] = 'January', [2] = 'February', [3] = 'March', [4] = 'April', [5] = 'May', [6] = 'June', [7] = 'July', [8] = 'August', [9] = 'September', [10] = 'October', [11] = 'November', [12] = 'December'}
 
    --[[
        Handle installation info (e.g. vol, ep, arc, chapter)
    ]]--
    local epVol, epArc = epData['volume'], args['arc'] 
    if epVol and tonumber(epVol) then
        epVol = '[[Releases (Manga)#vol' .. epVol .. '|Volume ' .. epVol ..']]'
    elseif epVol then
        epVol = 'Volume ' .. epVol
    end
    if epArc then
        epArc = '[[' .. epArc .. ']][[Category:' .. epArc .. ' Episodes]]'
    else
        epArc = ''
    end
 
    local epInstall = '<i>[[Berserk (Manga)|Berserk]]</i>' .. ( epVol and ', ' .. epVol or '' ) .. ( argEp and ', Episode ' .. argEp or '' ) .. ( args['pages'] and ' (' .. args['pages'] .. ' pp.)' or '')
 
    --[[
        Handle episode publication date and magazine
    ]]--
    local epFullPub = ''
    if epData['full pub'] == nil then
        local dateY, dateM, dateD = epData['pub date']:match('([0-9]*)-([0-9]*)-([0-9]*)')
        local epRelDate = months[ tonumber(dateM) ] .. ' ' .. tonumber(dateD) .. ', ' .. dateY
 
        local epMagName, epMagIssue, epMagYear = epData['magazine']:match('([AHY]*) #([^,]*), (.*)')
        epMagName = ({['AH'] = '<i>Animal House</i>', ['YA'] = '<i>Young Animal</i>'})[epMagName]
        local epMagInfo = epMagName .. ' #' .. epMagIssue .. ' (' .. epMagYear .. ')'
 
        epFullPub = epMagInfo .. '<br>' .. epRelDate
    else
        epFullPub = epData['full pub']
    end
 
    --[[
        Handle English, Japanese, and romanized names
    ]]--
    local epEngName, epJaName, epRomName = '', '', '' 
    if epData['ename'] then
        epEngName = '&ldquo;' .. epData['ename'] .. '&rdquo;'
        epEngName = epEngName .. '{{DISPLAYTITLE:' .. epEngName .. '}}'
    else epEngName = '{{PAGENAME}}' end
    if epData['jname'] then epJaName = epData['jname'] end
    if epData['rname'] then epRomName = '<i>' .. epData['rname'] .. '</i>' end
    local epJaRom =
        epJaName and epRomName and
        '<navigation><center><span style="font-weight: normal;"><span style="font-size: 1.2em;">' .. epJaName .. '</span><br>(' .. epRomName ..')</span></center></navigation>'
 
    --[[
        Search for prev and next episodes
    ]]--
 
    -- Find appropriate prev and next episode keys
    local epCurr = argEp:match('0([A-P])') or argEp
    local epPrevKey, epNextKey = '', ''
    local epKeys = {
        ['prevUnnumbered'] = '0' .. string.char( string.byte(epCurr) - 1 ),
        ['prevNumbered'] = tostring( (tonumber(argEp) or 1) - 1 ),
        ['nextUnnumbered'] = '0' .. string.char( string.byte(epCurr) + 1 ),
        ['nextNumbered'] = tostring( (tonumber(argEp) or -1) + 1 )
    }
 
    -- Test for key episode's existence in episodesManga (Module:Episodes/mangaData)
    if episodesManga[ epKeys['prevUnnumbered'] ] then epPrevKey = epKeys['prevUnnumbered']
    elseif episodesManga[ epKeys['prevNumbered'] ] then epPrevKey = epKeys['prevNumbered']
    end
    if episodesManga[ epKeys['nextUnnumbered'] ] then epNextKey = epKeys['nextUnnumbered']
    elseif episodesManga[ epKeys['nextNumbered'] ] then epNextKey = epKeys['nextNumbered']
    end
 
    -- Set prev and next episode variables
    local epPrev =
        episodesManga[epPrevKey] or
        episodesManga[epPrevKey] or
        '' -- No match found; empty string returned
    local epNext =
        episodesManga[epNextKey] or
        episodesManga[epNextKey] or
        '' -- No match found; empty string returned
    if epPrev ~= '' then epPrev = '"[[Episode ' .. epPrevKey .. " (Manga)|" .. epPrev['ename'] .. ']]"' end
    if epNext ~= '' then epNext = '"[[Episode ' .. epNextKey .. " (Manga)|" .. epNext['ename'] .. ']]"' end
 
    --[[
        Generate infobox
    ]]--
    local infobox = {
        '<infobox>',
        '<title><default>' .. epEngName .. '</default></title>',
        '<image><default>' .. ( args['image'] or '' ) .. '</default></image>',
        epJaRom,
        infoboxCreateDataItem( 'Installment', epInstall),
        infoboxCreateDataItem( 'Story arc', epArc ),
        infoboxCreateDataItem( 'Chapter', ( args['chapter'] or '' ) ),
        infoboxCreateDataItem( 'Publication', epFullPub ),
        infoboxCreateDataItem( 'Previous', args['prev'] or epPrev ),
        infoboxCreateDataItem( 'Next', args['next'] or epNext ),
        '</infobox>',
        -- Lead paragraph
        '"<b>' .. epData['ename'] .. '</b>"' .. ' is episode ' .. argEp .. ' of the [[Berserk (Manga)|<i>Berserk</i>]] manga.'
    }
 
    --[[
        SubstInfobox stuff
    ]]--
    --[[
    local epTlPub = ''
    if epData['full pub'] == nil then
        epTlPub = '|magazine=' .. ( epData['magazine'] or '' ) .. '\n|pub date=' .. ( epData['pub date'] or '' )
    else
        epTlPub = '|full pub=' .. epData['full pub']
    end
 
    local epTlPrev, epTlNext = '', ''
    if args['prev'] == nil then
        epTlPrev = ''
    else
        epTlPrev = '|prev=' .. args['prev']
    end
    if args['next'] == nil then
        epTlNext = ''
    else
        epTlNext = '|next=' .. args['next']
    end
 
    local substInfobox = {
        '{{Infobox/Episode/Manga',
        '|image=' .. ( args['image'] or '' ),
        '|episode=' .. argEp,
        '|pages=' .. ( args['pages'] or '' ),
        '|arc=' .. ( args['arc'] or '' ),
        '|chapter=' .. ( args['chapter'] or '' ),
        epTlPub .. epTlPrev .. epTlNext,
        '}}'
    }
    ]]--
 
    return frame:preprocess( table.concat(infobox, '\n') )
end
 
return p
Community content is available under CC-BY-SA unless otherwise noted.