Module:Volume

-- module to form Marvel Database:Volume Template local p = {} 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 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 contents = '' local total_issues local infobox = {} local output = {}

table.insert(categories, 'Comic Lists') if h.isempty(exclude) == false 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 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_min_max_by_date(list) total_issues = h.Link(':Category:'..pagename, #list) table.insert(infobox, { left = 'Publisher', right = h.Link(publisher, publisher) } ) table.insert(infobox, { left = 'Total Issues', right = total_issues } ) table.insert(infobox, creators)

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) contents, category = p.lua_content(pagename, p.lua_create_infobox(infobox)) gallery = p.lua_create_issue_list(list, parts, above, below) table.insert(categories, category) table.insert(categories, publisher) table.insert(categories, p.lua_volume_debut(first_by_date)) categories = p.lua_create_list_of_categories(categories, info.sortname.noissue) table.insert(output, top_message) table.insert(output, contents) table.insert(output, gallery) table.insert(output, categories)

return frame:preprocess( table.concat(output) ) --return #parts, h.isempty(parts) --return first_by_date.pagename, last_by_date.pagename end

function p.lua_publisher(publisher) local output = 'Marvel Comics' if not h.isempty(publisher) then output = h.lua_breaklink(publisher, 1) end return output end

function p.lua_get_previous_and_next_volume(pagename, previous_volume, next_volume) local s1 = '' local s2 = '' local previous_arrow = ' '..h.Link(s1, 'Previous Volume') else previous_volume = '' end if not h.isempty(next_volume) then next_volume = h.lua_breaklink(next_volume, 1) next_volume = h.Link(next_volume, 'Next Volume')..next_arrow..next_volume..']]' elseif not h.isempty(s2) then next_volume = h.Link(s2, 'Next Volume')..next_arrow..s2..']]' else next_volume = '' end

return previous_volume, next_volume end

function p.lua_top_message(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 message = 'This page contains a list of all the comics included in ' local publisher_logo = 'Marvel Logo.png' local function tag_td(text) return tostring(mw.html.create( 'td' )               :css('width', '18%')                :css('font-size', '80%')                :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, 'Images from '..pagename) 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 end

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

return design.messagebox( { output } ) end

function p.lua_content(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 tonumber(first_character) ~= nil then first_character = '0 9' 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]) 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,                extrastyle  = 'width:250px; float:right; clear:none; border:1px solid'..design.lua_getMainBorderColor..'; background:'..design.lua_getMainBackgroundColor..'; border-radius:10px;',                title       = 'More Information',                 titlestyle = 'text-align: center;',                body        = table.concat(output)            }) return output 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 = s[i] 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_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 reprint = template..':ReprintOf1, ' --local reprint_story = template..':ReprintOfStory1' 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_min_max_by_date(list) local s_min local s_max local i_min = 1 local i_max = 1 local s   if not h.isempty(list) then s_min = p.lua_date_for_sorting(list[1].year, list[1].month) s_max = s_min for i = 2,#list do               s = p.lua_date_for_sorting(list[i].year, list[i].month) if s < s_min then i_min = i                       s_min = s                end if s > s_max then i_max = i                       s_max = s                end end end return list[i_min], list[i_max] 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.checkSeries local s = 'Spider-Man / Fantastic Four' local titles = { 'Fantastic Four', 'Wolverine' } local output = '' for i = 1, #titles do       mw.log(titles[i]) output = string.find(s, '.-'..titles[i]..'.-', 1, false) mw.log(output) if not h.isempty(output) then return true end end return false 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_date) local month = first_date.month local year = first_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               table.insert(output, '') end end return table.concat(output) end

return p