FANDOM


local p = {}
local h = require("Module:HF")
 
function p.lua_pagetype(pagename)
    local s = ''
    local pagetype = ''
 
    if h.isempty(pagename) == false
        then
            s = mw.title.new(pagename):getContent()
            if h.isempty(s) == false
                then pagetype = string.match(s, '{{Marvel Database:(.-)\n')
            end
    end
 
    return pagetype
end
 
 
function p.lua_get_episode_title()--pagename)
    local pagename = 'Legion (TV series) Season 1 1'
    local s = ''
 
    if h.isempty(pagename) == false
        then 
            s = mw.title.new(pagename):getContent()
            if h.isempty(s) == false
                then s = string.match(s, "|%s+EpisodeTitle%s+=%s+(.-)\n")
            end
    end
 
    return s
end
 
 
function p.lua_releasedate()--pagename,pagetype)
    local s = ''
    local releasedate = ''
    local year = ''
    local month = ''
    local day = ''
    local pagename = 'Legion (TV series) Season 1 1'
    --local pagename = 'FF Vol 1 1'
    --local pagename = 'X-Men: Mutant Academy'
    --local pagename = 'Captain Marvel (film)'
    local pagetype = 'Episode'
    --local pagetype = 'Comics'
    --local pagetype = 'Game'
    --local pagetype = 'Film'
 
    if h.isempty(pagename) == false and h.isempty(pagetype) == false
        then
            s = mw.title.new(pagename):getContent()
            if h.isempty(s) == false
                then 
                    if pagetype == 'Comics'
                        then
                            year = string.match(s, "|%s+Year%s+=%s+(.-)\n")
                            month = string.match(s, "|%s+Month%s+=%s+(.-)\n")
                            if h.isempty(year) == false and h.isempty(month) == false
                                then releasedate = month..', '..year
                            end
                        elseif pagetype == 'Episode'
                            then 
                                year = string.match(s, "|%s+Year%s+=%s+(.-)\n")
                                month = string.match(s, "|%s+Month%s+=%s+(.-)\n")
                                day = string.match(s, "|%s+Day%s+=%s+(.-)\n")
                                if h.isempty(year) == false and h.isempty(month) == false and h.isempty(day) == false
                                    then releasedate = day..' '..month..', '..year
                                end
                            elseif pagetype == 'Film' or pagetype == 'Game'
                                then releasedate = string.match(s, "|%s+Release Date%s+=%s+(.-)\n")
                    end
            end
    end
 
    return releasedate
end
 
------------------------------------------------------------------------------------------------
---- //*** Functions for transforming pagenames of comics into desirable format ***// ----
 
--checks if pagename is comics or not
function p.lua_isComics(pagename)
    local s = false
    local i = ''
    local j = ''
    i = string.find(pagename, ' Vol %d+ ')
    j = string.find(pagename, ' #%d+')
    if h.isempty(i) == false or h.isempty(j) == false 
        then s = true
    end
 
    return s
end
 
---- returns transformed issue/episode number that can be used for sorting in categories as numbers, instead of text, including "point one" issues and "-1"/"negative" issues
function p.lua_padded_issue(issue)
    local minus = '5'
    local point_one = '00'
    local i = ''
    local j = ''
    local output = ''
 
    if h.isempty(issue) == false
        then
            -- -1 issues
            j = string.find(issue,"-",1,true)
            if h.isempty(j) == false 
                then
                    i = string.sub(issue,2,#issue)
                    j = string.find(i,".",1,true)
                    if h.isempty(j) == false 
                        then minus = 5 - #string.sub(i,1,j-1)
                        else minus = 5 - #i
                    end
                else
                    i = issue
            end
 
            -- point one issues
            j = string.find(i,".",1,true) 
            if h.isempty(j) == false 
                then
                    point_one = string.sub(i,j+1,#i)
                    point_one = string.rep("0", 2-#point_one)..point_one
                    i = string.sub(i,1,j-1)
            end
 
            output = minus..string.rep("0", 4-#i)..i..point_one
    end
 
    return output
end
 
--Returns transformed volume/season number that can be used for sorting in categories as numbers, instead of text
function p.lua_padded_volume(volume)
    local output = ''
 
    if h.isempty(volume) == false
        then 
            if #volume == 1
                then output = '0'..volume
                else output = volume
            end
    end
 
    return output
end
 
-- break down pagename of comics/episodes into parts - title, volume/season, issue/episode. 
---- Also returns transformed volume/season number and issue/episode number that can be used for sorting in categories as numbers, instead of text, including "point one" issues and "-1"/"negative" issues
---- Also returns transformed title, with replaced characters like ":" or "/" that can be used for names of files (for example, covers)
function p.lua_get_title_volume_issue(pagename,pagetype)
    local title = ''
    local volume = ''
    local issue = ''
    local padded_issue = ''
    local padded_volume = ''
    local title_for_files = ''
 
    local i
    local j
    local k
 
    if h.isempty(pagetype) == true
        then pagetype = 'Vol'
    end
 
    j,k = string.find(pagename, ' '..pagetype..' %d+ ')
    if h.isempty(j) == false
        then
            title = string.sub(pagename,1,j-1)
            issue = string.gsub(string.sub(pagename,k+1,#pagename), '#', '')
            i = issue
            j,k,volume = string.find(pagename,' '..pagetype..' (%d+) ')
        else
            j,k = string.find(pagename, ' #')
            if h.isempty(j) == true
                then
                    j,k = string.find(pagename, ' '..pagetype..' %d+')
                    if h.isempty(j) == false
                        then
                            title = string.sub(pagename,1,j-1)
                            volume = string.sub(pagename,j+5,k)
                        else return ''
                    end
                else
                    title = string.sub(pagename,1,j-1)
                    issue = string.sub(pagename,k+1,#pagename)
                    i = issue
                    volume = '1'
            end
    end
 
    padded_volume = p.lua_padded_volume(volume)
    padded_issue = p.lua_padded_issue(issue)
 
    -- replaces certain characters in 'title' - used for file names
    title_for_files = title
    title_for_files = string.gsub(title_for_files,'/',' ')
    title_for_files = string.gsub(title_for_files,':','')
    title_for_files = string.gsub(title_for_files,'&','&')
    title_for_files = string.gsub(title_for_files,''',"'")
 
    return title, volume, issue, padded_issue, padded_volume, title_for_files
end
 
 
-- removes "The " from the start of pagename
function p.lua_remove_the(pagename)
    if h.isempty(pagename) == false and string.lower( string.sub(pagename, 1, 4) ) == 'the '
        then pagename = string.sub(pagename, 5, #pagename)
    end
    return pagename
end
function p.remove_the(frame)
    return p.lua_remove_the(frame.args[1])
end
 
 
-- automatic standardization of comics names
function p.lua_standardized_comics_name(pagename)
    local title = ''
    local volume = ''
    local issue = ''
    local output = pagename
 
 
    if h.isempty(pagename) == false
        then 
            title, volume, issue = p.lua_get_title_volume_issue(pagename, 'Vol')
            if h.isempty(title) == false
                then
                    volume = ' Vol '..volume..' '
                    output = title..volume..issue
            end
    end
 
    return output
end
function p.standardized_comics_name(frame)
    return p.lua_standardized_comics_name(frame.args[1])
end
 
 
-- automatic standardization of episodes names
function p.lua_standardized_episode_name(pagename)
    local title = ''
    local season = ''
    local episode = ''
    local output = pagename
 
 
    if h.isempty(pagename) == false
        then 
            title, season, episode = p.lua_get_title_volume_issue(pagename, 'Season')
            if h.isempty(title) == false
                then
                    season = ' Season '..season..' '
                    output = title..season..episode
            end
    end
 
    return output
end
function p.standardized_episode_name(frame)
    return p.lua_standardized_comics_name(frame.args[1])
end
 
 
-- returns link after standardization of its name
function p.lua_standardized_link(pagename, pagetype)
    local title = ''
    local volume = ''
    local issue = ''
    local link = ''
    local text = ''
    local output = '[['..pagename..']]'
 
    if h.isempty(pagename) == false
        then
            if h.isempty(pagetype) == false
                then
                    if pagetype == 'Comics' or pagetype == 'Episode'
                        then
                            if pagetype == 'Comics'
                                then pagetype = 'Vol'
                                else pagetype = 'Season'
                            end
 
                            title, volume, issue = p.lua_get_title_volume_issue(pagename,pagetype)
                            if h.isempty(title) == false
                                then
                                    link = title..' '..pagetype..' '..volume..' '..issue
                                    if volume == '1'
                                        then text = title..' #'..issue
                                        else text = title..' '..pagetype..' '..volume..' #'..issue
                                    end
                                    output = h.Link(link, text)
                            end
                        elseif pagetype == 'Film' or pagetype == 'Game'
                            then
                                link = pagename
                                text = string.gsub(pagename, ' %(.+%)', '')
                                output = h.Link(link, text)
                    end
            end
    end
 
    return output
end
function p.comics_link(frame)
    return p.lua_standardized_link(frame.args[1],'Comics')
end
 
 
-- returns name transformed into format for sorting 
---- removes "The" from the begining
---- for comics/episodes changes volume/season and issue/episode into numbers, instead of text
function p.lua_standardized_name_for_sorting(pagename,pagetype)
    local title = ''
    local volume = ''
    local issue = ''
    local padded_issue = ''
    local padded_volume = ''
    local output = ''
 
 
    if h.isempty(pagename) == false and h.isempty(pagetype) == false
        then
            if pagetype == 'Comics' or pagetype == 'Episode'
                then
                    if pagetype == 'Comics'
                        then pagetype = 'Vol'
                        else pagetype = 'Season'
                    end
                    title, volume, issue, padded_issue, padded_volume = p.lua_get_title_volume_issue(pagename,pagetype)
                    if h.isempty(title) == false
                        then output = p.lua_remove_the(title)..' '..pagetype..' '..padded_volume..' '..padded_issue
                    end
                elseif pagetype == 'Film' or pagetype == 'Game'
                    then output = p.lua_remove_the(pagename)
            end
    end
 
    return output
end
function p.comics_name_for_sorting(frame)
    return p.lua_standardized_name_for_sorting(frame.args[1],'Comics')
end
 
function p.lua_get_part(pagename,pagetype,part)
    local output = ''
    local title = ''
    local volume = ''
    local issue = ''
 
    if h.isempty(pagename) == false and h.isempty(pagetype) == false
        then 
            if pagetype == 'Comics' or pagetype == 'Episode'
                then
                    if pagetype == 'Comics'
                        then pagetype = 'Vol'
                        else pagetype = 'Season'
                    end
                    title, volume, issue = p.lua_get_title_volume_issue(pagename,pagetype)
                    if h.isempty(title) == false
                        then 
                            if part == 'Title'
                                then output = title
                                elseif part == 'Volume'
                                    then output = volume
                                    elseif part == 'Issue'
                                        then output = issue
                            end
                    end
            end
    end
 
    return output
end
 
function p.get_part(frame)
    return p.lua_get_part(frame.args[1],frame.args[2],frame.args[3])
end
 
function p.get_title_and_volume(frame)
    local title = ''
    local volume = ''
    local output = ''
 
    title = p.lua_get_part(frame.args[1],'Comics','Title')
    volume = p.lua_get_part(frame.args[1],'Comics','Volume')
 
    if h.isempty(title) == false and h.isempty(volume) == false
        then output = title..' Vol '..volume
    end
 
    return output
end
 
 
return p
Community content is available under CC-BY-SA unless otherwise noted.

Bring Your Marvel Movies Together