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 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 args = getArgs (frame) local l = mw.text.split(args["list"],"@@@",true) local parts = {} local above = {} local below = {} local exclude = args["exclude"] local part local a   local b    local s_page local s_image local s_title local i, j, k, f   local v    local s    local t = {} local t2 = {} local cover local textless local info = {} local title_for_sorting = '' local publication_date = '' local link = '' local output = '' local tag = ''

if h.isempty(exclude) == false then exclude = mw.text.split(exclude,";",true) end for i = 1,9 do       table.insert(parts, tonumber(standart.lua_padded_issue(args['part'..i]))) table.insert(above, args['part'..i..'_above'] or '') table.insert(below, args['part'..i..'_below'] or '') end

i = 1 while next(l,i) ~= nil do       v = mw.text.split(l[i],"*",true) i = i + 1 s_page = v[1] s_image = v[2] s_title = v[3] if h.inlist(exclude, s_page) == false then publication_date = m_date.lua_link_to_publication_category(v[4], v[5]) info = standart.lua_get_title_volume_issue(s_page)

s_image = p.lua_cover(s_image, info) s_title = p.lua_storytitle(s_title) link = p.lua_link(s_page)

s = info.padded_issue..'@@@'..s_image..'|'..link..s_title..' ('..publication_date..')\n' table.insert(t,s) end end table.sort(t) --volume_date_first = string.match(t[1],' %((.+)%)\n') --volume_date_last = string.match(t[#t],' %((.+)%)\n')

part = tonumber(parts[1]) i = 1 while i <= #t do       v = mw.text.split(t[i],"@@@",true) i = i + 1 if h.isempty(part) == true or part == 0 then table.insert(t2, v[2]) else table.insert(t2, {v[1], v[2]}) end end

if h.isempty(part) == true or part == 0 then a = above[1] or '' b = below[1] or '' output = a..frame:preprocess('')..b       else t = {} k = tonumber( t2[1][1] ) f = parts[1] i = 1 if parts[#parts] < tonumber( t2[#t2][1] ) then table.insert(parts, tonumber( t2[#t2][1] ) ) end while i <=#parts do               part = tonumber(parts[i]) if h.isempty(part) == true or part == 0 then break else a = above[i] or '' b = below[i] or '' part = {} for j = 1, #t2 do                           if tonumber( t2[j][1] ) >= tonumber (k) and tonumber( t2[j][1] ) <= tonumber (f) then table.insert(part, t2[j][2]) end end i = i + 1 k = f+1 f = parts[i] table.insert(t, a..frame:preprocess('')..b)                       --table.insert(t, a..table.concat(part)..b)                end end output = table.concat(t) end return output end

function p.lua_get_list_from_string(str) local list = {} 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) table.insert(output, { ['pagename'] = s[1],                                                 ['image'] = s[2],                                                 ['storytitle'] = s[3],                                                 ['year'] = s[4],                                                 ['month'] = s[5]                         }) end end end return output end

function p.lua_dpl_list(pagename, category_name) 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.getMinMaxFromList(list) local s_min local s_max if not h.isempty(list) then s_min = list[1] s_max = list[1] for i = 2,#list do               s_min = math.min(list[i], s_min) s_max = math.max(list[i], s_max) end end return s_min, s_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