Module:Comics/Sandbox

local p = {} local h = require("Module:HF") local standart = require("Module:StandardizedName") local m_date = require("Module:Date") local getArgs = require('Dev:Arguments').getArgs local pagetype = require("Module:PageType") local design = require("Module:Design") local SC = require("Module:StaffCorrection") local staff_info = mw.loadData("Module:Comics/Staff") local quote = require("Module:Quote")

local border_color = design.lua_getMainBorderColor local background_color = design.lua_getMainBackgroundColor

function p.main(frame) local args = getArgs (frame) local variant = args['Variant'] or '1' local appearances_and_synopses = {} local previous_issue = '' local next_issue = '' --local publisher = '' local main_image = '' --local headtitle = args['HeadTitle'] or '' local recent = '' local links_and_references = args['Links'] local category = '' local text = '' local header = '' local s = '' local i = 0 local j = 0 local body = {} local output = {} local pagename = '' local sortname = '' local main_cover = '' local main_cover_textless = '' local alternate_covers local link_to_volume_page local links_to_release_publication_dates local cover_artists local issue_details local events local previous_arrow = '' local next_arrow = '' local image_size = args['ImageSize'] or '300px' local categories = {} local infobox = {} local infobox2 = {} local stories = {} local canceled = false local released = true local issue_info = {}

if variant == '1' then table.insert(output, '') end

pagename = mw.title.getCurrentTitle.subpageText--page.text issue_info = standart.lua_get_title_volume_issue(pagename) sortname = issue_info.sortname.all main_cover = issue_info.filename.all..'.jpg' main_cover_textless = issue_info.filename.all..' Textless.jpg'

table.insert(categories, 'Comics')

-- PUBLISHER (Category:Comics by Publisher) ? change to Imprint --[[ probably no needed, because volumes are sorted into these categories.   publisher = args['Publisher']  or 'Marvel Comics' --shouldn't they all be in this category?    if not h.isempty(publisher)        then             table.insert(categories, publisher )            publisher = h.Link(publisher,publisher)    end

if string.find(pagename, ' Annual ') then table.insert(categories, 'Annuals' ) end if string.find(pagename, ' Handbook ') then table.insert(categories, 'Handbooks' ) end if string.find(pagename, ' TPB ') or string.find(pagename, ' HC ') then table.insert(categories, 'Trade Paperbacks' ) end --]] -- VOLUME category table.insert(categories, issue_info.noissue) -- HEADTITLE --headtitle = p.lua_get_headtitle(headtitle)

-- EVENTS, ARCS, STORYLINES events, category = p.lua_get_events_arcs_storylines(args) table.insert(infobox, events) categories = h.lua_concatTables(categories, category)

--MAIN IMAGE main_image, category = p.lua_get_main_cover(args['Image'], image_size, main_cover, main_cover_textless) table.insert(infobox, main_image) table.insert(categories, category)

-- ALTERNATE COVERS alternate_covers = p.lua_get_alternate_covers(args, main_cover_textless, pagename) table.insert(infobox, alternate_covers)

-- VOLUME (link) link_to_volume_page = h.Link(issue_info.noissue, issue_info.noissue)..' #'..issue_info.issue table.insert(infobox, design.infobox_line( {text = link_to_volume_page } ) )

-- CANCELED if h.isempty(args['Canceled']) then canceled = false -- not canceled else canceled = true -- canceled table.insert(categories, 'Canceled Comics') end

-- PUBLICATION AND RELEASE DATES release_info = m_date.lua_get_release_date_info(args['ReleaseDate']) table.insert(categories, release_info.week.text) -- ? shouldn't canceled issues be excluded from category ? released = release_info.released

publication_info, category = m_date.lua_get_publication_date_info(args['Year'], args['Month'], canceled) categories = h.lua_concatTables(categories, category) sortname = publication_info.sortdate..sortname links_to_release_publication_dates = p.links_to_release_publication_dates(release_info, publication_info, canceled) table.insert(infobox, links_to_release_publication_dates) -- solicitation text, category = p.lua_solicitation(release_info, canceled) table.insert(output, text) table.insert(categories, category) -- canceled message table.insert(output, p.lua_canceled_message(release_info, canceled) ) -- SPOILER WARNING --if m_date.isRecent({ releasedate = release_info.date, year = publication_info.year, month = publication_info.month, canceled = canceled }) if not canceled and (release_info.recent or publication_info.recent) then recent = design.messagebox( {Message = 'Spoiler Warning! This comic has a recent publication date, thus the article below may contain spoilers! Read beyond this point at your own risk! ', background = 'rgb(255, 102, 102)', border = 'rgb(255, 20, 20)', extrastyle = 'color: white; font-weight: bold; clear: both;'}) end

-- ISSUE DETAILS issue_details, category = p.lua_get_issue_details(args, released, canceled, variant) table.insert(infobox, issue_details) categories = h.lua_concatTables(categories, category)

-- COVER ARTISTS --cover_artists, category = p.lua_get_cover_artists(args, released, canceled) --table.insert(infobox, cover_artists) --categories = h.lua_concatTables(categories, category) -- STORIES for i = 1,100 do       text, category = p.lua_get_story(args, i, pagename, released, canceled) if not text.empty or i == 1 then table.insert(stories, text) categories = h.lua_concatTables(categories, category) end end if stories[1].empty and #stories > 1 then j = 2 else j = 1 end for i = j,#stories do       stories[i].story_title = p.lua_story_title(i, stories[i].story_title, stories[i].reprint_story_title)

if variant == '1' then text = h.Link(pagename..'#Appearing in '..stories[i].story_title, i..'. '..stories[i].story_title) stories[i].staff = design.lua_story_contributors(stories[i].staff, text, true) header = design.lua_header('Appearing in '..stories[i].story_title, 2) stories[i].appearances = header..stories[i].reprint_message..'\n'..stories[i].appearances header = design.lua_header('Synopsis for '..stories[i].story_title, 2) stories[i].synopsis = header..stories[i].reprint_message..'\n'..stories[i].synopsis table.insert(appearances_and_synopses,stories[i].appearances..stories[i].synopsis) table.insert(infobox, stories[i].staff) elseif variant == '2' then --stories[i].staff = design.lua_story_contributors(stories[i].staff, stories[i].story_title, false) s = {} table.insert(s, design.lua_header(i..'. '..stories[i].story_title, 2) ) table.insert(s, design.lua_create_infobox(stories[i].staff, image_size) ) table.insert(s, stories[i].reprint_message) --table.insert(s, design.lua_header(i..'. List of appearances', 3) ) table.insert(s, '\n '..design.lua_span('List of appearances').bold..'  \n' ) table.insert(s, '\n'..stories[i].appearances) --table.insert(s, design.lua_header(i..'. Synopsis', 3) ) table.insert(s, '\n '..design.lua_span('Synopsis').bold..'  \n' ) table.insert(s, '\n'..stories[i].synopsis) table.insert(appearances_and_synopses, table.concat(s)) end end

-- PREVIOUS AND NEXT ISSUES previous_issue, next_issue = p.lua_get_previous_and_next_issues(issue_info, args['PreviousIssue'], args['NextIssue']) table.insert(infobox, design.infobox_line_horizontal({left_header = 'Previous Issue', left_text = previous_issue, right_header = 'Next Issue', right_text = next_issue}))

table.insert(infobox2, p.lua_links_to_previous_current_and_next_issues(previous_issue, next_issue, link_to_volume_page, image_size)) table.insert(infobox2, design.infobox_line({text = events}) ) table.insert(infobox2, main_image) table.insert(infobox2, alternate_covers) table.insert(infobox2, issue_details) table.insert(infobox2, links_to_release_publication_dates)

-- QUOTE text, category = p.lua_get_quote(args, released, canceled) --table.insert(output, text) --categories = h.lua_concatTables(categories, category) --   if released and not canceled then table.insert(output, table.concat(appearances_and_synopses) ) end -- OTHER SECTIONS table.insert(output, p.lua_add_section(args['Solicit'], 'Solicit Synopsis') ) table.insert(output, p.lua_add_section(args['Notes'], 'Notes') ) table.insert(output, p.lua_add_section(args['Trivia'], 'Trivia') ) -- SEE ALSO text, category = p.lua_get_see_also_section(pagename) table.insert(output, text) categories = h.lua_concatTables(categories, category) -- RECOMMENDED table.insert(output, p.lua_add_section(args['Recommended'], 'Recommended Reading') ) -- LINKS AND REFERENCES table.insert( output, design.lua_header('Links and References', 2)) if not h.isempty(links_and_references) then table.insert(output, '\n'..links_and_references) end table.insert(output, design.lua_header('Footnotes', 3)..'\n') --       table.insert(output, '') table.insert(output, p.lua_get_link_to_reviews(pagename) ) -- --   if variant == '1' then infobox = design.lua_create_infobox(table.concat(infobox)) else infobox = design.lua_create_infobox(table.concat(infobox2), image_size) if not canceled and released then infobox = infobox..' ' else infobox = infobox..'' end end categories = h.lua_create_list_of_categories(categories, sortname)

return recent..infobox..categories..frame:preprocess( table.concat(output) ) end

function p.lua_links_to_previous_current_and_next_issues(previous_issue, next_issue, link_to_volume_page, infobox_width) local previous_arrow = '' local next_arrow = '' local tag_left = mw.html.create( 'div' ) :css( 'width', '18px' ) :css( 'text-align', 'left' ) :css( 'float', 'left' ) :done local tag_right = mw.html.create( 'div' ) :css( 'width', '18px' ) :css( 'text-align', 'right' ) :css( 'float', 'left' ) :done local tag_center local width = '100%' local output = mw.html.create( 'div' ) :css( 'text-align', 'center' ) :css( 'clear', 'left' ) :css( 'font-size', '10px' )

infobox_width = string.gsub(infobox_width, 'px', '') infobox_width = tonumber(infobox_width) - 36 infobox_width = infobox_width..'px'

if previous_issue ~= '—' then previous_issue = h.lua_breaklink(previous_issue, 1) previous_arrow = tag_left:wikitext('') previous_arrow = tostring(previous_arrow) width = infobox_width elseif next_issue ~= '—' then previous_arrow = tostring( tag_left:wikitext('') ) end if next_issue ~= '—' then next_issue = h.lua_breaklink(next_issue, 1) next_arrow = tag_right:wikitext('') next_arrow = tostring(next_arrow) width = infobox_width elseif previous_issue ~= '—' then next_arrow = tostring( tag_left:wikitext('') ) end tag_center = mw.html.create( 'div' ) :css( 'width', width ) :css( 'text-align', 'center' ) :css( 'float', 'left' ) :wikitext(link_to_volume_page) :done output = output:wikitext(previous_arrow..tostring(tag_center)..next_arrow)

return tostring(output) end

function p.lua_get_story(args, i, pagename, released, canceled) local reprint_issue = args['ReprintOf'..i]   local reprint_story = args['ReprintOfStory'..i]    local story_title = args['StoryTitle'..i] or '' local appearances = args['Appearing'..i] or '' local synopsis = args['Synopsis'..i] or '' local reprint_content = '' local reprint_story_title = '' local reprint = false local empty = true local reprint_message = '' local link = '' local bold local small = mw.html.create('span'):css( 'font-size', 'smaller' ) local j   local s    local category local staff = {} local staff_count = 0 local categories = {} local output if not h.isempty(reprint_issue) then reprint = true table.insert(categories, 'Reprints') reprint_issue = standart.lua_standardized_comics_name(reprint_issue) table.insert(categories, reprint_issue..'/Reprints') if h.isempty(reprint_story) then reprint_story = '1' table.insert(categories, 'Reprint Story Number Needed') end reprint_content = h.lua_getContent(reprint_issue) if not h.isempty(reprint_content) then reprint_story_title = h.lua_getFieldValue(reprint_content, 'StoryTitle'..reprint_story) s = h.lua_getFieldValue(reprint_content, 'Appearing'..reprint_story) appearances = p.lua_reprint_appearances(s, pagename) synopsis = h.lua_getFieldValue(reprint_content, 'Synopsis'..reprint_story) else appearances = '' synopsis = '' end if not h.isempty(story_title) and story_title ~= reprint_story_title then if not h.isempty(reprint_story_title) then bold = design.lua_span(reprint_story_title).bold small = tostring( small:wikitext('(originally printed as '..bold..')') ) else small = tostring( small:wikitext('(originally printed without story title)') ) end s = ' '..small else s = '' end link = standart.lua_standardized_link(reprint_issue, 'Comics') reprint_message = 'This story is a reprint of the '..p.lua_ordinal_number(reprint_story)..' story from '..link..s           reprint_message = design.messagebox( { Message = reprint_message, width = '40%' } ) end for j = 1,7 do       s = p.lua_get_list_from_args(args, staff_info[j].field..i..'_') s = p.lua_get_employees_list(j, s, reprint_content, reprint_story) if not h.isempty(s) then staff_count = staff_count + 1 end s, category = design.lua_infobox_line_staff(s, j, released, canceled, reprint) table.insert(staff, s)       categories = h.lua_concatTables(categories, category) end staff = table.concat(staff)

if p.lua_appearances_isempty(appearances) then appearances = '' end

if not h.isempty(appearances) or       not h.isempty(synopsis) or       not h.isempty(story_title) or       not h.isempty(reprint_issue) or       not h.isempty(reprint_story_title) or       staff_count > 0 then empty = false end if not empty then if h.isempty(appearances) then appearances = '* Appearances not yet listed' if not reprint and not canceled and released then table.insert(categories, 'Appearances Needed') end end if h.isempty(synopsis) then synopsis = '* Synopsis not yet written' if not reprint and not canceled and released then table.insert(categories, 'Comic Synopsis Needed') end end end

output = { appearances = appearances, synopsis = synopsis, story_title = story_title, reprint = reprint, reprint_issue = reprint_issue, reprint_story = reprint_story, reprint_story_title = reprint_story_title, staff = staff, empty = empty, reprint_message = reprint_message, }

return output, categories end

function p.lua_get_see_also_section(pagename) local text = '' local category = '' local categories = {} local output = {} table.insert(output, design.lua_header('See Also', 2) ) text, category = p.lua_get_link_to_subcategory(pagename, 'Image', 'from') table.insert(output, text) table.insert(categories, category)

text, category = p.lua_get_link_to_subcategory(pagename, 'Reprint', 'of') table.insert(output, text) table.insert(categories, category)

text, category = p.lua_get_link_to_subcategory(pagename, 'Review', 'of') table.insert(output, text) table.insert(categories, category) table.insert(output, '\n* Write your own review of this comic!') --table.insert(output, '\n* Discuss '..pagename..' on the forums' )

return table.concat(output), categories end

function p.lua_get_quote(args, released, canceled) local quotation = args['Quotation'] or '' local speaker = args['Speaker'] or '' local blockquote = args['BlockQuote'] or '' local reprintquote = args['ReprintQuote'] or '' local categories = {} local output = '' if released and not canceled then if not h.isempty(quotation) or not h.isempty(blockquote) or not h.isempty(reprintquote) then if not h.isempty(reprintquote) then output = quote.reprint_quote(reprintquote) elseif not h.isempty(quotation) then output = quote.quote({quote=quotation, speaker=speaker}) else output = blockquote table.insert(categories, 'BlockQuotes') end else table.insert(categories, 'Comic Quote Needed') end end return output end

function p.lua_add_section(section, header) local output = '' if not h.isempty(section) then output = design.lua_header(header, 2)..'\n'..section end return output end

function p.lua_get_list_from_args(args, field_name) local i   local s    local output = {}

for i = 1,50 do       s = args[field_name..i]        if not h.isempty(s) then table.insert(output, s)       end end return output end

function p.lua_get_list_from_args2(args, field_name) local i   local j    local s    local output = {}

for i = 1,9 do       for j = 1,50 do            s = args[field_name..i..'_'..j]            if not h.isempty(s) then table.insert(output, s)           end s = args[field_name..j]           if not h.isempty(s) then table.insert(output, s)           end end end return output end

function p.lua_get_issue_details(args, released, canceled, variant) local i   local s    local rating local category local issue_details = {} local staff = { {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, } local categories = {} local output = {} --table.insert(issue_details, { publisher, 'Publisher/Imprint' } ) table.insert(issue_details, { p.lua_get_ISBN(args['ISBN']), 'ISBN' }) table.insert(issue_details, { args['ISSN'], 'ISSN' }) table.insert(issue_details, { args['UPC'], 'UPC' } ) table.insert(issue_details, { args['Pages'], 'Pages' } ) rating, category = p.lua_get_rating(args['Rating']) table.insert(categories, category) table.insert(issue_details, { rating, 'Original rating' } ) table.insert(issue_details, { args['OriginalPrice'], 'Original price' } )

--President1_1 - President1_5 staff[9] = p.lua_get_list_from_args(args, staff_info[9].field) staff[10] = {args['CCO']} --Publisher1_1 - Publisher1_5 staff[11] = p.lua_get_list_from_args(args, staff_info[11].field) staff[12] = {args["Editor-in-Chief"]} --Production1_1 - Production1_5 staff[13] = p.lua_get_list_from_args2(args, staff_info[13].field)

for i = 9,13 do       s, category = design.lua_infobox_line_staff(p.lua_get_employees_list(i, staff[i]), i, released, canceled, false) if not h.isempty(s) then table.insert(output, s)       end categories = h.lua_concatTables(categories, category) end --if variant == '2' --   then -- COVER ARTISTS s, category = p.lua_get_cover_artists(args, released, canceled) table.insert(output, s)           categories = h.lua_concatTables(categories, category) --end for i = 1, #issue_details do       if not h.isempty(issue_details[i][1]) then s = design.infobox_line( { left = issue_details[i][2], right = issue_details[i][1] } ) table.insert(output, s)       end end

output = design.show_hide({               collapsed   = true,                extrastyle  = 'margin:0px; text-align:left;',                title       = 'Issue details',                 body        = table.concat(output)                })

return output, categories end

function p.lua_get_ISBN(ISBN) local output = '' if not h.isempty(ISBN) then output = h.Link('Special:BookSources/'..ISBN, ISBN) end return output end

function p.lua_solicitation(release_info, canceled) local category = '' local output = '' if not release_info.released then category = 'Solicitations' if not canceled then output = design.messagebox( {Message = 'This comic will be released on '.. release_info.week.link, width = '50%'}) end end return output, category end function p.lua_canceled_message(release_info, canceled) local output = '' if canceled then output = design.messagebox( {Message = 'This comic will not be released. It was canceled prior to its release date, '..release_info.week.link, background = 'rgb(255, 102, 102)', border = 'rgb(255, 20, 20)', width = '50%', extrastyle = 'color:white;'}) end return output end

function p.lua_get_link_to_subcategory(pagename, subcategory, text) local n = 0 local page = pagename..'/'..subcategory..'s'   local s = '' local category = '' local output = ''

if subcategory == 'image' then n = h.lua_PagesInCategory(page, 'files') else n = h.lua_PagesInCategory(page) end if n > 0 then if n == 1 then s = ' '..string.lower(subcategory)..' ' else s = ' '..string.lower(subcategory)..'s ' end output = '\n* '..h.lua_link_to_category(page, i..s..text..' '..pagename) if not h.lua_isexists('Category:'..page) then category = subcategory..'s Category Needed' end end return output, category end

function p.lua_get_link_to_reviews(pagename) local n = h.lua_PagesInCategory(pagename..'/Reviews') local output = '' if n > 0 --number of reviews then output = '' end return output end

function p.lua_get_employees_list(occupation, list, reprint_content, reprint_story) local i   local s = '' local link local category local output = {} if not h.isempty(reprint_story) then reprint_story = reprint_story..'_' else reprint_story = '' end

if not h.isempty(reprint_content) then for i = 1,50 do               s = h.lua_getFieldValue(reprint_content, staff_info[occupation].field..reprint_story..i)                if not h.isempty(s) then link = SC.lua_get_staff_link_and_category(s) table.insert(output, { link = design.lua_span(link).italic, category = '' } ) end end end if not h.isempty(list) then for i = 1, #list do               s = list[i] if not h.isempty(s) then link, category = SC.lua_get_staff_link_and_category(s, staff_info[occupation].category) table.insert(output, {link = link, category = category}) end end end

return output end

function p.lua_get_cover_artists(args, released, canceled) local namespace = '' local content = '' local i   local s = '' local link local category local cover_artists = p.lua_get_list_from_args(args, 'CoverArtist') local reprint_cover = args['Reprint_CoverArtists'] local list = {} local categories = {} local output = {}

cover_artists = p.lua_get_employees_list('CoverArtist', cover_artists) if not h.isempty(reprint_cover) then namespace = pagetype.lua_getNamespace(reprint_cover) if namespace == 'Main' or string.find(reprint_cover, '^'..namespace..':', 1, false) ~= nil then content = h.lua_getContent(reprint_cover) else content = h.lua_getContent(namespace..':'..reprint_cover) end list = p.lua_get_employees_list('CoverArtist', _, content) table.insert(categories, 'Reprinted Cover') --? maybe create a new category for comics issues with cover reprinted from another comics end list = h.lua_concatTables(list, cover_artists) if not h.isempty(list) then output, categories = design.lua_infobox_line_staff(list, 'CoverArtist', released, canceled, false) end return output, categories end

-- function p.lua_get_previous_and_next_issues(issue_info, previous_issue, next_issue) local issue = tonumber(issue_info.issue) local list = {'-', '--', '---', '—', '&mdash;'} local s = ''

if h.isempty(previous_issue) then if issue ~= nil and issue > 1 then s = issue_info.noissue..' '..tostring(issue-1) previous_issue = standart.lua_standardized_link(s, 'Comics') else previous_issue = '—' end elseif h.inlist(list, previous_issue) then previous_issue = '—' else s = h.lua_breaklink(previous_issue, 1) if h.lua_isexists(s) then previous_issue = standart.lua_standardized_link(s, 'Comics') end end if h.isempty(next_issue) then if issue ~= nil then s = issue_info.noissue..' '..tostring(issue+1) next_issue = standart.lua_standardized_link(s, 'Comics') else next_issue = '—' end elseif h.inlist(list, next_issue) then next_issue = '—' else s = h.lua_breaklink(next_issue, 1) if h.lua_isexists(s) then next_issue = standart.lua_standardized_link(s, 'Comics') end end return previous_issue, next_issue end

-- function p.links_to_release_publication_dates(release_info, publication_info, canceled) local release = release_info.week.link local publication = publication_info.link local s1 = '' local s2 = '' local output = ''

if canceled then s1 = 'Intended Publication Date' s2 = 'Intended Release Date' else s1 = 'Published' s2 = 'Released' end

if not h.isempty(publication) then if not h.isempty(release) then output = design.infobox_line_horizontal({left_header = s1, left_text = publication, right_header = s2, right_text = release,  font_size_text = '12px'}) else output = design.infobox_line_horizontal({left_header=s1, left_text=publication, font_size_text = '12px'}) end elseif not h.isempty(release) then output = design.infobox_line_horizontal({left_header=s2, left_text=release, font_size_text = '12px'}) end return output end

-- function p.lua_get_main_cover(main_image, image_size, main_cover, main_cover_textless) local category = '' local output = main_image

image_size = image_size or '300px'

if h.isempty(main_image) then if h.lua_isexists('File:'..main_cover) then output = main_cover elseif h.lua_isexists('File:'..main_cover_textless) then output = main_cover_textless else output = 'No Image Cover.jpg' category = 'Cover Image Needed' end else if h.inlist( {'No Image Cover.jpg', 'Needed.png', 'Needed.jpg'}, main_image) then category = 'Cover Image Needed' elseif not h.inlist( {main_cover, main_cover_textless}, main_image) then category = 'Cover Image Correction Needed' end end output = '' return output, category end

-- function p.lua_get_headtitle(headtitle) local output = '' if not h.isempty(headtitle) then output = mw.html.create( 'div' ) :css( 'text-align', 'center' ) :css( 'font-size', '12px' ) :css( 'font-weight', 'bold' ) :css( 'line-height', '1.5em' ) :css( 'border-bottom', '2px solid '..border_color) :wikitext(headtitle) :done output = tostring(output) end return headtitle end

-- -- check if appearances section is filled only with subheaders (Featured Characters, etc.) without any actual appearances function p.lua_appearances_isempty(appearances) local s   local subheaders = { "Featured Characters:", "Supporting Characters:", "Antagonists:", "Other Characters:", "Races and Species:", "Locations:", "Items:", "Vehicles:", } local count = 0 local output = true --empty if not h.isempty(appearances) then s = mw.text.split(appearances, '\n', true) for i = 1,#s do               if h.inlist(subheaders, s[i]) or string.match(s[i], "^%*%s*$") ~= nil or string.match(s[i], "^%*%s*%s-$") ~= nil or string.match(s[i], "^%s*$") ~= nil then count = count + 1 end end if count ~= #s then output = false --not empty end end

return output end

-- --events, arcs, storylines function p.lua_get_events_arcs_storylines(args) local function part(table_links, table_names, name) local function tag_div(text) return tostring(mw.html.create( 'div' )               :css( 'text-align', 'center' )                :css( 'padding', '0.5em 0pt 0.5em 0pt' )                :css( 'font-size', '10px' )                :css( 'font-weight', 'bold' )                :css( 'line-height', '1em' )                :wikitext(text)                :done ) end local i       local t = {} local categories = {} local output = '' if not h.isempty(table_links) then for i = 1,#table_links do               if not h.isempty(table_links[i]) then table.insert(t, '"'..h.Link(table_links[i], table_names[i] or table_links[i])..'"' ) table.insert(categories, table_links[i]) end end if #t > 0 then if #t > 1 then name = name..'s'                   end output = tag_div('\nPart of the '..mw.text.listToText( t )..' '..name) end end return output, categories end local i   local events = {} local events_names = {} local arcs = {} local arcs_names = {} local storylines = {} local storylines_names = {} local text local category local categories = {} local output = {} table.insert(events, args['Event'] or '') table.insert(events_names, args['EventName'] or '') table.insert(arcs, args['StoryArc'] or '') table.insert(arcs_names, args['StoryArcName'] or '') table.insert(storylines, args['Storyline'] or '') table.insert(storylines_names, args['StorylineName'] or '') for i = 2, 9 do       table.insert(events, args['Event'..i] or '') table.insert(events_names, args['EventName'..i] or '') table.insert(arcs, args['StoryArc'..i] or '') table.insert(arcs_names, args['StoryArcName'..i] or '') table.insert(storylines, args['Storyline'..i] or '') table.insert(storylines_names, args['StorylineName'..i] or '') end text, category = part(events, events_names, 'event') table.insert(output, text) categories = h.lua_concatTables(categories, category) text, category = part(arcs, arcs_names, 'arc') table.insert(output, text) categories = h.lua_concatTables(categories, category) text, category = part(storylines, storylines_names, 'storyline') table.insert(output, text) categories = h.lua_concatTables(categories, category) return table.concat(output), categories end

-- --returns story title, story title from reprint or story number if none of them exists function p.lua_story_title(number,story_title,reprint_story_title) local ordinal_number = p.lua_ordinal_number(number) local output = '' if h.isempty(story_title) then output = reprint_story_title else output = story_title end if not h.isempty(output) then output = '"'..string.gsub(output,'"','')..'"'       else output = ordinal_number..' story'    end

return output end

-- -- return gallery of alternate covers function p.lua_get_alternate_covers(args, main_cover_textless, pagename) local i = 1 local j = 1 local s = '' local covers = {} local captions = {} local output = {} for i = 2,200 do       s = args['Image'..i]        if not h.isempty(s) then table.insert(covers, s)               table.insert(captions, args['Image'..i..'Text'] or '') end end

if (#covers == 0 or covers[1] ~= main_cover_textless) and h.lua_isexists('File:'..main_cover_textless) then table.insert(covers, 1, main_cover_textless) table.insert(captions, 1, 'Textless') end if #covers > 0 and covers[1] == main_cover_textless and ( h.isempty(captions[1]) or captions[1] ~= 'Textless' ) then captions[1] = 'Textless' end

for j = 1,#covers do       s = tostring(mw.html.create( 'div' )                :css( 'float', 'left' )                :css( 'width', '85px' )                :css( 'text-align', 'center' )                :css( 'font-size', '10px' )                :css( 'font-weight', 'bold' )                :css( 'line-height', '1.5em' )                :css( 'margin', '2px 8px' )                :wikitext(''..captions[j])                :done ) if i == 3 then s = s..' ' i = 1 else i = i + 1 end table.insert(output, s)   end if #output > 0 then output = design.show_hide({           collapsed   = true,            extrastyle  = 'text-align:left;',            title       = 'Alternate covers',--h.lua_link_to_category(pagename..'/Images', 'Alternate Covers:'),             body        = table.concat(output)        }) else output = '' end return output end

-- -- get the list of appearances formed by dpl query from a comics issue and replace/move all tags to suppress all categoriztion. function p.lua_reprint_appearances(l, pagename) local j   local k    local s1    local s2    local s3    local n    list = mw.text.unstrip(l) list = mw.text.split(l,'\n') n = #list for i = 1,n do       l = list[i] l = mw.ustring.gsub(l, '', '%1' ) l = mw.ustring.gsub(l, '', '%1' ) l = mw.ustring.gsub(l, '', '%1' ) l = mw.ustring.gsub(l, ,  ) l = mw.ustring.gsub(l, '', '%1 ' ) l = mw.ustring.gsub(l, '', '%1 ' ) l = mw.ustring.gsub(l, '', '%1 ' ) l = mw.ustring.gsub(l, '', '%1 ' ) l = mw.ustring.gsub(l, ,  ) l = mw.ustring.gsub(l, ,  ) j, k = mw.ustring.find(string.lower(l), '') s2 = mw.ustring.sub( l, k+1, i-1 ) s3 = mw.ustring.sub( l, i+2, #l ) j = mw.ustring.find(s2, ,1,true)               k = mw.ustring.find(s2, ,1,true) if j ~= nil then s2 = ..mw.ustring.sub(s2, j+2, k-1 ).. else s2 = mw.text.split( s2,"|",true ) if #s2 == 3 then s2 = ''..s2[2]..' ' elseif #s2 == 2 then s2 = s2[1]..' ' else s2 = s2[1] end end l = s1..s2..s3       end l = mw.ustring.gsub(l, '', '%1 ' ) l = mw.ustring.gsub(l, '', '%1' ) l = mw.ustring.gsub(l, '', '%1 ' ) l = mw.ustring.gsub(l, '', '%1' ) l = mw.ustring.gsub(l, '(', '%2 %1}}' )       l = mw.ustring.gsub(l, ,  )        l = mw.ustring.gsub(l, ,  )        --l = mw.ustring.gsub(l, ,  )        j, k = mw.ustring.find(string.lower(l), ,1,true)        if j ~= nil             then                s1 = string.sub( l, 1, j-1 )                s2 =                 s3 = string.sub( l, k+1, #l )                l = s1..s2..s3        end           l = mw.ustring.gsub(l, '%[%[Category:.-%]%]', '' )        l = mw.ustring.gsub(l, '&lt;', '<' )        l = mw.ustring.gsub(l, '&gt;', '>' )        list[i] = '\n'..l    end    return table.concat(list) end

-- function p.lua_get_rating(rating) local category = '' local output = '' local ratings = { ['all ages'] = { 'All Ages (for all ages)', 'All Ages (for all ages)' }, ['a'] = { 'A (9 and up)', 'A (9 and up)' }, ['psr'] = { 'PSR (9 and up)', 'PSR (9 and up)' }, ['pg'] = { 'PG (9 and up)', 'PG (9 and up)' }, ['a-'] = { 'A- (9 and up)', 'A- (9 and up)' }, ['a+'] = { 'A+ (9 and up)', 'A+ (9 and up)' }, ['t'] = { 'T (13 and up)', 'T (13 and up)' }, ['teen'] = { 'Teen (13 and up)', 'T (13 and up)' }, ['psr+'] = { 'PSR+ (13 and up)', 'PSR+ (13 and up)' }, ['pg+'] = { 'PG+ (13 and up)', 'PG+ (13 and up)' }, ['t-'] = { 'T- (13 and up)', 'T- (13 and up)' }, ['t+'] = { 'T+ (13 and up)', 'T+ (13 and up)' }, ['pa'] = { 'Parental Advisory (15 and up)', 'Parental Advisory (15 and up)' }, ['parental advisory'] = { 'Parental Advisory (15 and up)', 'Parental Advisory (15 and up)' }, ['pa/ec'] = { 'Parental Advisory (15 and up)', 'PA/EC (15 and up)' }, ['explicit content'] = { 'Parental Advisory (15 and up)', 'Explicit Content (15 and up)' }, ['parental advisory/explicit content'] = { 'Parental Advisory (15 and up)', 'Parental Advisory/Explicit Content (15 and up)' }, ['mature'] = { 'MAX: Explicit Content (18 and up)', 'Mature' }, ['max'] = { 'MAX: Explicit Content (18 and up)', 'MAX: Explicit Content (18 and up)' }, ['maxx'] = { 'MAXX: Explicit Content (18 and up)', 'MAXX: Explicit Content (18 and up)' } }   if not h.isempty(rating) then output = ratings[string.lower(rating)] --or {rating, rating} if output ~= nil then category = output[1] else output = {rating, rating} end output = h.lua_link_to_category(output[1], output[2]) end return output, category end

-- --counts how many times "text" is found in the "list" function p.lua_count_inlist(list, text) local output = 0 if not h.isempty(list) and not h.isempty(text) then for i, v in ipairs( list ) do               if v == text then output = output + 1 end end end return output end

-- --returns number of "text" element in the "list" function p.lua_find_inlist(list, text) local output = 0 if not h.isempty(list) and not h.isempty(text) then for i, v in ipairs( list ) do               if v == text then output = i                       break end end end return output end

-- --transform 'number' into ordinal number, for example '1' into '1st' function p.lua_ordinal_number(number) local output = '' number = tonumber(number) if not h.isempty(number) then if number % 10 == 1 and number ~= 11 -- in (1,21,31,41,51,61,71) then output = number..'st' elseif number % 10 == 2 and number ~= 12 -- in (2,22,32,42,52,62,72) then output = number..'nd' elseif number % 10 == 3 and number ~= 13 --in (3,23,33,43,53,63,73) then output = number..'rd' else output = number..'th' end end return output end

return p