FANDOM


local p = {}
 
local relativeEpisode = require('Module:TabSwitch')._relativeEpisode
local title = mw.title.getCurrentTitle()
local basetitle = mw.title.new(title.baseText)
local searchTerm = ' (episode)'
local pageType
local episode
 
-- Creates the actual link for p.nextLink and p.prevLink methods
 
local function createLink(episode)
    if pageType == 'Episode' then
        if mw.title.new(episode .. searchTerm).exists then
            return '"[[' .. episode .. searchTerm .. '|' .. episode .. ']]"'
        else
            return '"[[' .. episode .. ']]"'
        end
    else
        if mw.title.new(episode .. searchTerm .. '/' .. pageType).exists then
            return '"[[' .. episode .. searchTerm .. '/' .. pageType .. '|' .. episode .. ']]"'
        else
            return '"[[' .. episode .. '/' .. pageType .. '|' .. episode .. ']]"'
        end
    end
end
 
-- Creates a link to the previous episode/gallery/transcript page
-- Returns empty string if wrong pagetype
-- Returns "N/A" if the previous episode is not known
 
local function prevLink()
    if not pageType then return '' end
    local prevEpisode = relativeEpisode(episode, -1)
    if prevEpisode == 'N/A' then
        return 'N/A'
    else
        return createLink(prevEpisode)
    end
end
 
-- Creates a link to the next episode/gallery/transcript page
-- Returns empty string if wrong pagetype
-- Returns "N/A" if the next episode is not known
 
local function nextLink()
    if not pageType then return '' end
    local nextEpisode = relativeEpisode(episode, 1)
    if nextEpisode == 'N/A' then
        return 'N/A'
    else
        return createLink(nextEpisode)
    end
end
 
function p.main()
    -- Check if it is an episode (sub)page
    -- by checking if the base page has the Episode template
    --
    -- pageType =
    -- "Episode" on episode pages,
    -- "Gallery" on gallery pages,
    -- "Transcript" on transcript pages
    if basetitle.exists then
        local basecontent = string.lower(basetitle:getContent())
            if title.text == basetitle.text then
                pageType = 'Episode'
            else
                pageType = title.subpageText
            end
        end
    end
    -- Get the current episode name based on the pagename
    -- Returns empty string if wrong pagetype
    if pageType then
        local endpos = title.text:find(searchTerm, 1, true)
        if endpos then
            episode = title.text:sub(1, endpos - 1)
        else
            episode = title.baseText
        end
    else
        episode = ''
    end
    return episode .. ';' .. prevLink() .. ';' .. nextLink()

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.