Module:Volume

-- module to form Marvel Database:Volume Template local p = {} local h = require("Module:HF") local SC = require("Module:StaffCorrection") 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 vloume category function p.main(frame) local pagename = mw.title.getCurrentTitle.text local args = getArgs (frame) local exclude = args['exclude'] local category = args['category'] or pagename local previous_volume = args['PreviousVol'] local next_volume = args['NextVol'] local volume = standart.lua_get_title_volume_issue(category, 'Vol').volume 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 = ''

previous_volume, next_volume = p.lua_get_previous_and_next_volume(category, previous_volume, next_volume)

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, category)..p.lua_dpl_list(pagename, category, 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) gallery = p.lua_create_issue_list(list, parts, above, below)

top_message = p.lua_top_message(category, first_by_date, last_by_date, previous_volume, next_volume, volume_logo, publisher) return frame:preprocess( top_message ) --return #parts, h.isempty(parts) --return first_by_date.pagename, last_by_date.pagename 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(category, 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 mw.html.create( 'td' ) :css('width', '10%') :wikitext(text) end local tag_td_center local images_category = category..'/Images' local output = '' category = h.Link(':Category:'..category, category)

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) running_years = ' ('..first_year..'–'..last_year..')' end

if not h.isempty(publisher) then publisher = ' (published by '..publisher..')' if h.lua_isexists('File:'..publisher..'.png') then publisher_logo = '' end else publisher = '' end 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 '..category) else images_category = '' end

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

return design.messagebox( { 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] 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, category_name, 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 = {} if not h.isempty(category_name) then pagename = category_name end

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

return p