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 reprint_title = {} local reprint_story = {} local storytitles = {} local appearances = {} local synopses = {} local appearances_and_synopses = {} local contributors = {} local staff = {} local editor_in_chief = '' local cover_artists = {} local reprint = '' --local reprints_content = {} local reprint_storytitles = {} local previous_issue = '' local next_issue = '' local issue_details = {} local publisher = '' local main_image = '' local cco = '' local headtitle = args['HeadTitle'] or '' local quotation = args['Quotation'] or '' local speaker = args['Speaker'] or '' local blockquote = args['BlockQuote'] or '' local reprintquote = args['ReprintQuote'] or '' local recent = '' --local custom_section1 = args['CustomSection1'] --local custom_text1 = args['CustomText1'] --local custom_section2 = args['CustomSection2'] --local custom_text2 = args['CustomText2'] local links_and_references = args['Links'] local category = '' local text = '' local content = '' local namespace = '' local header = '' local s = '' local i = 0 local j = 0 local j = 0 local body = {} local output = {} local pagename = '' local sortname = '' local title_volume = '' local main_cover = '' local main_cover_textless = '' local categories = {} local infobox = {} --local stories = {} local stories_n = 0 local canceled = false local released = true local year = '' local month = '' local season = '' local releasedate = '' local events = {} local events_names = {} local arcs = {} local arcs_names = {} local storylines = {} local storylines_names = {} local issue_info = {}

table.insert(output, '')

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 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 = p.events_arcs_storylines(events, events_names, 'event') table.insert(infobox, text) categories = h.lua_concatTables(categories, category) text, category = p.events_arcs_storylines(arcs, arcs_names, 'arc') table.insert(infobox, text) categories = h.lua_concatTables(categories, category) text, category = p.events_arcs_storylines(storylines, storylines_names, 'storyline') table.insert(infobox, text) categories = h.lua_concatTables(categories, category)

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

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

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

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

release_info = m_date.lua_get_release_date_info(args['ReleaseDate']) table.insert(categories, release_info.week.text) released = release_info.released

publication_info, category = m_date.lua_get_publication_date_info(args['Year'], args['Month'], args['Season'], canceled) categories = h.lua_concatTables(categories, category) sortname = publication_info.sortdate..sortname

table.insert(infobox, p.links_to_release_publication_dates(release_info, publication_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 s, category = p.lua_solicitation(release_info, canceled) table.insert(output, s)   table.insert(categories, category) table.insert( output, p.lua_canceled_message(release_info, canceled) )

for i = 1,15 do       table.insert( staff, {} ) end

-- ISSUE DETAILS --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_args2(args, staff_info[9].field) staff[10] = {args['CCO']} --Publisher1_1 - Publisher1_5 staff[11] = p.lua_get_list_from_args2(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       staff[i], category = design.infobox_line_staff2( {list = p.lua_get_employees_list(i, staff[i]), n = i, released = released, canceled = canceled } ) categories = h.lua_concatTables(categories, category) end

issue_details = p.lua_get_issue_details(issue_details, {staff[9], staff[10], staff[11], staff[12], staff[13]}) table.insert(infobox, issue_details) -- COVER ARTISTS cover_artists = p.lua_get_list_from_args(args, 'CoverArtist') cover_artists, category = p.lua_get_cover_artists(cover_artists, args['Reprint_CoverArtists']) table.insert(infobox, cover_artists) categories = h.lua_concatTables(categories, category) -- STORIES for i = 1,100 do       table.insert(reprint_title, args['ReprintOf'..i] or '') if not h.isempty(args['ReprintOfStory'..i]) then table.insert(reprint_story, args['ReprintOfStory'..i]) else table.insert( reprint_story, '1' ) table.insert(categories, 'Reprint Story Number Needed') end table.insert(storytitles, args['StoryTitle'..i] or '')

if not h.isempty(reprint_title[i]) then if p.lua_count_inlist(categories, 'Reprints') == 0 then table.insert(categories, 'Reprints' ) end s = standart.lua_standardized_comics_name(reprint_title[i]) reprint = h.lua_getContent(s) table.insert(categories, s..'/Reprints')

if not h.isempty(reprint) then reprint_storytitles[i] = h.lua_getFieldValue(reprint, 'StoryTitle'..reprint_story[i]) for j = 1,7 do                           for k = 1,50 do                                staff[j][k] = h.lua_getFieldValue(reprint, staff_info[j].field..reprint_story[i]..'_'..k)                            end end appearances[i] = p.lua_reprint_appearances( h.lua_getFieldValue(reprint, 'Appearing'..reprint_story[i]), pagename ) synopses[i] = h.lua_getFieldValue( reprint, 'Synopsis'..reprint_story[i] ) else appearances[i] = '' synopses[i] = '' end else table.insert( appearances, args['Appearing'..i] or '' ) table.insert( synopses, args['Synopsis'..i] or '' ) for j = 1,7 do                   staff[j] = p.lua_get_list_from_args(args, staff_info[j].field..i..'_') end end

if not h.isempty(storytitles[i]) or           not h.isempty(reprint_storytitles[i]) or           not h.isempty(reprint_title[i]) or           not h.isempty(appearances[i]) or           not h.isempty(synopses[i]) or           i == 1 then stories_n = stories_n + 1 storytitles[i] = p.lua_story_title( i, storytitles[i], reprint_storytitles[i] )

body = {} for j = 1,7 do                   text, cat = design.infobox_line_staff( { list = staff[j], n = j, released = released, canceled = canceled } ) table.insert(body, text) categories = h.lua_concatTables(categories, cat) end body = table.concat(body) contributors[i] = design.story_contributors( {pagename = pagename, storytitle = storytitles[i], stories_n = stories_n, body = body } ) if not h.isempty(reprint_title[i]) then s = design.messagebox( {                       Message = 'This story is a reprint of the '..p.lua_ordinal_number(reprint_story[i])..' story from the '..standart.lua_standardized_link(reprint_title[i], 'Comics'),                         width = '50%' } ) else s = '' end header = design.lua_header('Appearing in '..storytitles[i], 2) if h.isempty(appearances[i])-- or (h.isempty(reprint_title[i]) -- and p.lua_appearances_isempty(appearances[i])) then appearances[i] = header..s..'\n* Appearances not yet listed' if not canceled then table.insert(categories, 'Appearances Needed') end else appearances[i] = header..s..'\n'..appearances[i] end header = design.lua_header('Synopsis for '..storytitles[i], 2) if h.isempty(synopses[i]) then synopses[i] = header..s..'\n* Synopsis not yet written' if not canceled and h.isempty(reprint_title[i]) then table.insert(categories, 'Comic Synopsis Needed') end else synopses[i] = header..s..'\n'..synopses[i] end table.insert(appearances_and_synopses,appearances[i]..synopses[i]) table.insert(infobox, contributors[i]) end end

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}))

infobox = design.lua_createInfobox(table.concat(infobox))

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 table.insert( output, quote.reprint_quote(reprintquote)) elseif not h.isempty(quotation) then table.insert( output, quote.quote({quote=quotation, speaker=speaker}) ) else table.insert( output, blockquote ) table.insert( categories, 'BlockQuotes' ) end else table.insert(categories, 'Comic Quote Needed') end

table.insert( output, table.concat(appearances_and_synopses) ) end

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') ) --   if not h.isempty(custom_section1) and not h.isempty(custom_text1)        then table.insert( output, design.lua_header(custom_section1, 2)..'\n'..custom_text1)    end    if not h.isempty(custom_section2) and not h.isempty(custom_text2)        then table.insert( output, design.lua_header(custom_section2, 2)..'\n'..custom_text2)    end -- -- see also section table.insert( output, design.lua_header('See Also', 2) ) s, category = p.lua_get_link_to_subcategory(pagename, 'Image', 'from') table.insert(output, s)   table.insert(categories, category) s, category = p.lua_get_link_to_subcategory(pagename, 'Reprint', 'of') table.insert(output, s)   table.insert(categories, category) s, category = p.lua_get_link_to_subcategory(pagename, 'Review', 'of') table.insert(output, s)   table.insert(categories, category) table.insert( output, '\n* Write your own review of this comic!') --table.insert( output, '\n* Discuss '..pagename..' on the forums' ) table.insert(output, p.lua_add_section(args['Recommended'], 'Recommended Reading') )

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) )

for i = 1,#categories do       categories[i] = h.CategoryLink(categories[i], sortname) end

return recent..infobox..table.concat(categories)..frame:preprocess( table.concat(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 table.insert(output, args[field_name..j]) end end return output end

function p.lua_get_issue_details(details, staff) local i   local s    local output = {}

for i = 1, #details do       if not h.isempty(details[i][1]) then s = design.infobox_line( { left = details[i][2], right = details[i][1] } ) table.insert(output, s)       end end for i = 9,13 do       if not h.isempty(staff[i-8]) then table.insert(output, staff[i-8]) end end output = design.show_hide({               collapsed   = true,                extrastyle  = 'width:100%; margin:0px; border:none; border-top:2px solid '..border_color..'; text-align:left; font-size: 10px;',                title       = 'Production and publication details',                 body        = table.concat(output)                })

return output 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.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.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* '..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) local i   local s = '' local link local category local output = {}

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 elseif not h.isempty(reprint_content) then for i = 1,50 do                   s = h.lua_getFieldValue(reprint_content, staff_info[occupation].field..i)                     if not h.isempty(s) then link = SC.lua_get_staff_link_and_category(s) table.insert(output, { link = design.lua_italic(link), category = '' } ) end end end

return output end

function p.lua_get_cover_artists(cover_artists, reprint_cover, released, canceled) local namespace = '' local content = '' local i   local s = '' local link local category local list1 = {} local list2 = {} local categories = {} local output = {}

list1 = 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 list2 = 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 list2 = h.lua_concatTables(list2, list1) if not h.isempty(list2) then output, categories = design.infobox_line_staff2( {list = list2, n = 'CoverArtist', released = released, canceled = canceled } ) 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 = '&mdash;' end elseif h.inlist(list, previous_issue) then previous_issue = '&mdash;' 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 = '&mdash;' end elseif h.inlist(list, next_issue) then next_issue = '&mdash;' 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 = appearances or '' s = mw.text.split(s, '\n', true) local output local output1 = 0 local output2 = 0 local empty1 = { "Featured Characters:", "*", "Supporting Characters:", "*", "Antagonists:", "*", "Other Characters:", "*", "Locations:", "*", "Items:", "*", "Vehicles:", "*" }   local empty2 = { "Featured Characters:", "* ", "Supporting Characters:", "* ", "Antagonists:", "* ", "Other Characters:", "* ", "Locations:", "* ", "Items:", "* ", "Vehicles:", "* " }   if #s == 14 then for i = 1, #s do               if s[i] == empty1[i] then output1 = output1 + 1 end if s[i] == empty2[i] then output2 = output2 + 1 end end end if output1== 14 or output2 == 14 then output = true --empty else output = false --not empty end return output end

-- --events, arcs, storylines function p.events_arcs_storylines(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('Part of the '..mw.text.listToText( t )..' '..name) end end return 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', '65px' )                :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  = 'width:100%; border:none; text-align:left; font-size: 10px;',            title       = h.Link(':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.Link(':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