Module:Volume

-- module to form Marvel Database:Volume Template local p = {} local list_of_series = mw.loadData( 'Module:Volume/Series' ) local h = require("Module:HF") local standart = require("Module:StandardizedName") local m_date = require("Module:Date") local design = require("Module:Design") local getArgs = require('Dev:Arguments').getArgs

-- forms a gallery of comics issues in specified volume based on dpl query from volume category function p.main(frame) local args = getArgs (frame) local exclude = args['exclude'] local pagename = args['category'] or mw.title.getCurrentTitle.text local previous_volume = args['PreviousVol'] local next_volume = args['NextVol'] local volume_logo = args['VolumeLogo'] local publisher = p.lua_publisher(args['Publisher']) local creators = p.lua_creators( args['Creators'] or '' ) local volume_type = args['Type'] or '' local volume_status = args['Status'] or '' local featured = args['Featured'] or '' local storyarcs = args['StoryArcs'] or '' local storylines = args['Storylines'] or '' local crossovers = args['Crossovers'] or '' local notes = args['Notes'] or '' local see_also = args['SeeAlso'] or '' local info = standart.lua_get_title_volume_issue(pagename, 'Vol') local categories = {} local category = '' local dpl_string = '' local parts = {} local above = {} local below = {} local list = {} local first_by_date local last_by_date local i   local s    local gallery = '' local top_message = '' local navigation = '' local total_issues = 0 local infobox = {} local output = {}

table.insert(categories, 'Comic Lists')

-- create list of all issues from category with DPL dpl_string = frame:preprocess( p.lua_dpl_list(pagename)..p.lua_dpl_list(pagename, 500) ) dpl_string = string.gsub(dpl_string, '&#x20;', '') list = p.lua_transform_string_into_list(dpl_string, exclude) table.sort(list, p.lua_sort_by_issue) first_by_date, last_by_date = p.lua_get_first_and_last_by_date(list)

-- create top message previous_volume, next_volume = p.lua_get_previous_and_next_volume(pagename, previous_volume, next_volume) --top_message = p.lua_top_message(pagename, first_by_date, last_by_date, previous_volume, next_volume, volume_logo, publisher) top_message = p.lua_top_message2(pagename, first_by_date, last_by_date, previous_volume, next_volume, volume_logo, publisher) -- create top navigation and infobox table.insert(infobox, { left = 'Publisher', right = h.Link(publisher, publisher) } ) volume_status, category = p.lua_volume_status(volume_status, last_by_date) table.insert(infobox, { left = 'Status', right = volume_status } ) table.insert(categories, category) table.insert(infobox, { left = 'Dates Published', right = p.lua_dates_published(first_by_date, last_by_date) } ) volume_type, category = p.lua_volume_type(volume_type, #list, last_by_date) table.insert(infobox, { left = 'Type', right = volume_type } ) table.insert(categories, category) total_issues = h.Link(':Category:'..pagename, #list) table.insert(infobox, { left = 'Total Issues', right = total_issues } )

table.insert(infobox, creators) table.insert(infobox, p.lua_divide_list(featured, 'Featured') ) table.insert(infobox, p.lua_divide_list(storyarcs, 'Story arcs') ) table.insert(infobox, p.lua_divide_list(storylines, 'Storylines') ) table.insert(infobox, p.lua_divide_list(crossovers, 'Crossovers') ) --navigation, category = p.lua_navigation(pagename, p.lua_create_infobox(infobox)) table.insert(categories, category) -- add publisher category table.insert(categories, publisher) -- add volume debut category table.insert(categories, p.lua_volume_debut(first_by_date)) -- check if Annual if string.find(pagename, 'Annual', 1, true) ~= nil then table.insert(categories, 'Annuals') end -- check if Handbook if string.find(pagename, 'Handbook', 1, true) ~= nil or      string.find(pagename, 'OHOTMU', 1, true) ~= nil or       string.find(pagename, 'OHOTUMU', 1, true) ~= nil then table.insert(categories, 'Handbooks') end -- check if TPB if string.find(pagename, ' TPB ', 1, true) ~= nil or      string.find(pagename, ' HC ', 1, true) ~= nil then table.insert(categories, 'Trade Paperbacks') end -- add comic series (if any) table.insert(categories, p.lua_get_comic_series(pagename))

-- create list of all suitable categories categories = p.lua_create_list_of_categories(categories, info.sortname.noissue) -- create gallery of issues if not h.isempty(exclude) then exclude = mw.text.split(exclude,";",true) end

for i = 1,9 do       s = args['part'..i]        if not h.isempty(s) then table.insert(parts, tonumber(standart.lua_padded_issue(s))) table.insert(above, args['part'..i..'_above'] or '') table.insert(below, args['part'..i..'_below'] or '') end end gallery = p.lua_create_issue_list(list, parts, above, below) -- add everything to page table.insert(output, top_message) --table.insert(output, navigation) table.insert(output, gallery) if not h.isempty(see_also) then table.insert(output, design.lua_header('See Also', 2)..see_also) end if not h.isempty(notes) then table.insert(output, design.lua_header('Notes', 2)..notes..' '

return design.messagebox( { output } ) end

function p.lua_top_message2(pagename, first_by_date, last_by_date, previous_volume, next_volume, volume_logo, publisher) local first_year = first_by_date.year or '' local last_year = last_by_date.year or '' local running_years = '' local publisher_logo = 'Marvel Logo.png' local function tag_div(text) return tostring(mw.html.create( 'td' )               :css('width', '20px')                :wikitext(text)                :done ) end local tag_td_center local images_category = pagename..'/Images' local output = ''

if h.lua_isexists('File:'..publisher..'.png') then publisher_logo = publisher..'.png' end publisher_logo = '' publisher = ' (published by '..publisher..')' if not h.isempty(volume_logo) then volume_logo = '' end if h.lua_PagesInCategory(images_category, 'files') > 0 then images_category = h.Link(':Category:'..images_category, 'List of images') else images_category = '' end

pagename = h.Link(':Category:'..pagename, pagename)

if not h.isempty(first_year) and not h.isempty(last_year) then first_year = h.Link(':Category:'..first_year, first_year) last_year = h.Link(':Category:'..last_year, last_year) if first_year == last_year then running_years = '('..first_year..')' else running_years = '('..first_year..'–'..last_year..')' end running_years = ' '..running_years end previous_volume = '' next_volume = ''

volume_logo = volume_logo or publisher_logo

--tag_td_center = ' '..pagename..running_years..publisher..' ' --output = ' '

--pagename = pagename..running_years..publisher tag_td_center = ''..pagename..' '..images_category..' ' pagename = ' '

return design.show_hide({ title = volume_logo..' '..pagename, body = 'test', clear = 'right', width = '300px', extrastyle = 'float:right; border-radius:10px;' })..' ' end

function p.lua_navigation(pagename, text) local tag_div = mw.html.create('div') :css('display', 'table') :css('margin', '0 auto') :css('width', '95%') :css('border-top', '1px solid lightgrey') :css('border-bottom', '1px solid lightgrey') :css('text-align', 'left') :css('font-size', '14px') :css('padding-top', '5px') :css('padding-bottom', '5px') :done local info = standart.lua_get_title_volume_issue(pagename,'Vol') local link_to_contents = h.Link('Contents', 'Back to title selection') local first_character = string.sub(info.sortname.all, 1, 1) local link_to_first_character = '' local output = '' text = text or '' if string.match(first_character, '%a') == nil then if string.match(first_character, '%d') ~= nil then first_character = '0 9' else first_character = '&' end end

first_character = 'Comics '..first_character link_to_first_character = h.Link(':Category:'..first_character, first_character) output = link_to_contents..' : '..link_to_first_character..' : '..info.noissue..text return tostring( tag_div:wikitext(output) ), first_character end

function p.lua_create_infobox(infobox) local s = '' local output = {}

for i = 1,#infobox do       if not h.isempty(infobox[i]) and not h.isempty(infobox[i].right) then s = design.infobox_line( {left = infobox[i].left, right = infobox[i].right, width_l = '90px', width_r = '150px'} ) table.insert(output, s)       end end output = design.show_hide({               collapsed   = true,                width = '250px',                clear = 'none',                extrastyle  = 'float:right; border-radius:10px;',                title       = 'Volume Information',                 titlestyle = 'text-align: center;',                body        = table.concat(output)            }) return output end function p.lua_volume_status(volume_status, last_by_date) local s = '' local year = last_by_date.year or '9999' local month = last_by_date.month or '01' local current_date = tonumber( m_date.lua_date_converter('now + 4 months', 'Ym') ) -- +4 months because pages for new comics normally created shortly after publication of solicitations -- solicitations appear 2 months before the release date -- publication is 2 months after release local output = '' local category = '' last_by_date = tonumber( m_date.lua_date_converter(month..'-01-'..year, 'Ym') )

if not h.isempty(volume_status) then s = string.lower(volume_status) if s == 'active' or s == 'active series' then output = 'Active' category = 'Active Series' elseif s == 'finished' or s == 'finished series' then output = 'Finished' category = 'Finished Series' elseif s == 'canceled' or s == 'canceled series' then output = 'Canceled' category = 'Canceled Series' else output = volume_status end else if last_by_date >= current_date then output = 'Active' category = 'Active Series' else output = 'Finished' category = 'Finished Series' end end return output, category end

function p.lua_volume_type(volume_type, total_issues, last_by_date) local s = '' local year = last_by_date.year or '9999' local month = last_by_date.month or '01' local current_date = tonumber( m_date.lua_date_converter('now + 5 months', 'Ym') ) local output = '' local category = '' last_by_date = tonumber( m_date.lua_date_converter(month..'-01-'..year, 'Ym') ) total_issues = tonumber(total_issues) if not h.isempty(volume_type) then s = string.lower(volume_type) if s == 'limited' or s == 'limited series' then output = 'Limited Series' category = output elseif s == 'one shot' or s == 'one-shot' then output = 'One Shot' category = 'One Shots' end elseif total_issues == 1 and last_by_date < current_date then output = 'One Shot' category = 'One Shots' end return output, category end

function p.lua_creators(creators) local SC = require("Module:StaffCorrection") local creator = '' local corrected = '' local i   local s    local output = '' if not h.isempty(creators) then s = mw.text.split(creators, ';') output = {} for i = 1,#s do               creator = h.lua_breaklink(s[i], 1) corrected = SC.Correction(creator) table.insert(output, h.Link(creator, corrected)..' ') end output = { left = 'Creators', right = table.concat(output) } end return output end

function p.lua_dates_published(first_by_date, last_by_date) local first = m_date.lua_link_to_publication_category(first_by_date.year, first_by_date.month) local last = m_date.lua_link_to_publication_category(last_by_date.year, last_by_date.month) local output if first == last then output = first else output = first..' – '..last end return output end

function p.lua_divide_list(list, name) local link = '' local text = '' local i   local output = {} if not h.isempty(list) then if string.find(list, ';', 1, true) ~= nil then list = mw.text.split(list, ';') for i = 1,#list do                       link = h.lua_breaklink(list[i], 1) text = h.lua_breaklink(list[i], 2) table.insert(output, h.Link(link, text)..' ') end output = { left = name, right = table.concat(output) } elseif not h.lua_isLink(list) and h.lua_isexists(list) then output = { left = name, right = h.Link(list, list) } else output = { left = name, right = list } end end return output end

function p.lua_create_issue_list(list, parts, above, below) local i   local j    local k    local s = {} local output = {} if h.isempty(parts) then output = { p.lua_create_gallery(list, , ) } else table.insert(parts, tonumber(list[#list].padded_issue) ) k = 1 for i = 1,#parts do               s = {} for j = k,#list do                   if tonumber(list[j].padded_issue) <= parts[i] then table.insert(s, list[j]) else k = j                           break end end table.insert(output, p.lua_create_gallery(s, above[i], below[i]) ) end end return table.concat(output) end

function p.lua_create_gallery(list, above, below) local link = '' local publication_date = '' local output = {} above = above or '' below = below or ''

for i = 1,#list do       publication_date = m_date.lua_link_to_publication_category(list[i].year, list[i].month) publication_date = ' ('..publication_date..')\n' link = p.lua_link(list[i].pagename) table.insert(output, '\n'..list[i].image..'|'..link..list[i].storytitle..publication_date) end output = table.concat(output) output = '' return above..output..below end

function p.lua_transform_string_into_list(str, exclude) local list = {} local info = {} local image = '' local storytitle = '' local year = '' local month = '' local pagename = '' local s = '' local output = {} if not h.isempty(str) then list = mw.text.split(str, '@@@', true) for i = 1, #list do               if not h.isempty(list[i]) then s = mw.text.split(list[i], '~', true) pagename = s[1] if not h.isempty(exclude) and exclude[pagename] ~= nil then s = '' else info = standart.lua_get_title_volume_issue(pagename) image = p.lua_cover(s[2], info) storytitle = p.lua_storytitle(s[3]) year = s[4] month = s[5] if not h.isempty(month) then month = m_date.month({month}) else month = '' end s ={['pagename'] = pagename, ['image'] = image, ['storytitle'] = storytitle, ['year'] = year, ['month'] = month, ['padded_issue'] = info.padded_issue, }                               table.insert(output, s)                        end end end end return output end

function p.lua_dpl_list(pagename, offset) local template = '{Marvel Database:Comic Template}' local image = template..':Image, ' local year = template..':Year, ' local month = template..':Month, ' local storytitle = template..':StoryTitle1, ' local output = {}

table.insert(output, '')

return table.concat(output) end

function p.lua_sort_by_issue(a, b)   local issue1 = a.padded_issue local issue2 = b.padded_issue local output if h.isempty(issue1) or h.isempty(issue2) then output = false else if tonumber(issue1) ~= nil then if tonumber(issue2) ~= nil then output = tonumber(issue1) < tonumber(issue2) else output = true end elseif tonumber(issue2) ~= nil then output = false else output = issue1 < issue2 end end

return output end

function p.lua_date_for_sorting(year, month) year = year or '9999' month = month or '01' return tonumber( m_date.lua_date_converter(month..'-01-'..year, 'Ymd') ) end

function p.lua_get_first_and_last_by_date(list) local first_by_date local last_by_date local i_first = 1 local i_last = 1 local s   if not h.isempty(list) then first_by_date = p.lua_date_for_sorting(list[1].year, list[1].month) last_by_date = first_by_date for i = 2,#list do               s = p.lua_date_for_sorting(list[i].year, list[i].month) if s < first_by_date then i_first = i                       first_by_date = s                end if s > last_by_date then i_last = i                       last_by_date = s                end end end return list[i_first], list[i_last] end

-- checks if volume title is in list of known comics books series (for example, "Wolverine Comics Books", "Spider-Man Comics Books", etc.) function p.lua_get_comic_series(pagename) local series local title local output = '' for title, series in pairs(list_of_series) do       if string.find(pagename, title, 1, true) ~= nil then output = series break end end return output end

-- return "image", if not empty, otherwise check if main cover or textless cover exists, if not, then return 'No Image Cover.jpg' function p.lua_cover(image, info) local cover = '' local textless = '' local output = ''

if not h.isempty(image) then output = image else cover = info.title_for_files..' Vol '..info.volume..' '..info.issue textless = cover..' Textless.jpg' cover = cover..'.jpg' if h.lua_isexists('File:'..cover) then output = cover elseif h.lua_isexists('File:'..textless) then output = textless else output = 'No Image Cover.jpg' end end return output end

function p.lua_storytitle(storytitle) local output = '' local tag = mw.html.create( 'span' ) :css( 'color', 'grey' ) :css( 'font-style', 'oblique' ) if not h.isempty(storytitle) then output = ' '..tostring( tag:wikitext( '"'..storytitle..'"' ):done ) end return output end

function p.lua_link(pagename) local output = '' local tag = mw.html.create( 'span' ) :css( 'font-weight', 'bold' ) if not h.isempty(pagename) then output = tag:wikitext( standart.lua_standardized_link(pagename, 'Comics') ):done output = tostring(output) end return output end

function p.lua_volume_debut(first_by_date) local month = first_by_date.month local year = first_by_date.year local output = '' if not h.isempty(year) then if not h.isempty(month) then month = month..' ' end output = month..year..' Volume Debut' end return output end

function p.lua_create_list_of_categories(categories, sortname) local i   local output = {}

if not h.isempty(categories) then if not h.isempty(sortname) then sortname = '|'..sortname else sortname = '' end for i = 1,#categories do               if not h.isempty(categories[i]) then table.insert(output, '') end end end return table.concat(output) end

return p