FANDOM


(I'll figure out why we need those checkups instead of just checking the namespace later. But so far it should be fine)
(just to check if it works like this)
Line 85: Line 85:
 
-- "Gallery" on gallery pages,
 
-- "Gallery" on gallery pages,
 
-- "Transcript" on transcript pages
 
-- "Transcript" on transcript pages
if basetitle.exists then
+
if basetitle.exists and namespace == 0 then
 
local basecontent = string.lower(basetitle:getContent())
 
local basecontent = string.lower(basetitle:getContent())
if basecontent:find('{{episode') or
+
if basecontent:find('season -= -shorts') then
basecontent:find('{{transcriptbox') or
+
episodeTerm = ' (short)'
basecontent:find('{{template: ?transcriptbox') or
+
end
basecontent:find('{{template: ?episode') then
+
if title.text == basetitle.baseText then
if basecontent:find('season -= -shorts') then
+
pageType = 'Episode'
episodeTerm = ' (short)'
+
else
end
+
pageType = title.subpageText
if title.text == basetitle.baseText then
 
pageType = 'Episode'
 
else
 
pageType = title.subpageText
 
end
 
 
end
 
end
 
end
 
end

Revision as of 13:32, November 12, 2017

--<nowiki>
local p = {}
 
local relativeEpisode = require('Module:TabSwitch')._relativeEpisode
local title = mw.title.getCurrentTitle()
local basetitle = mw.title.new(title.fullText)
local episodeTerm = ' (episode)'
local shortTerm = ' (short)'
local pageType
local episode
 
 
-- Checks if page has the postfix (short) in the title
-- Returns a boolean
local function isShort(ep)
    return ep:find('%(short%)') ~= nil
end
 
-- Checks if page has a postfix (episode) in the title
-- Returns a boolean
local function isEpisode(ep) 
    return ep:find('%(episode%)') ~= nil
end
 
local function readableTitle(_title) 
    return _title:gsub(' %b()', '')
end
 
-- Creates the actual link for p.nextLink and p.prevLink methods
 
local function createLink(_episode)
    if pageType == 'Episode' then
        if isEpisode(_episode) then
            return '"[[' .. _episode .. '|' .. readableTitle(_episode) .. ']]"'
        elseif isShort(_episode) then
            return '"[[' .. _episode .. '|' .. readableTitle(_episode) .. ']]"'
        else
            return '"[[' .. readableTitle(_episode) .. ']]"'
        end
    else
        if isEpisode(_episode) then
            return '"[[' .. _episode .. '/' .. pageType .. '|' .. readableTitle(_episode) .. ']]"'
        elseif isShort(_episode) then
            return '"[[' .. _episode .. '/' .. pageType .. '|' .. readableTitle(_episode) .. ']]"'
        else
            return '"[[' .. _episode .. '/' .. pageType .. '|' .. readableTitle(_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(episodeTitle)
    if not pageType then return '' end
    local prevEpisode = relativeEpisode(episodeTitle, -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(episodeTitle)
    if not pageType then return '' end
    local nextEpisode = relativeEpisode(episodeTitle, 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 and namespace == 0 then
        local basecontent = string.lower(basetitle:getContent())
        if basecontent:find('season -= -shorts') then
            episodeTerm = ' (short)'
        end
        if title.text == basetitle.baseText then
            pageType = 'Episode'
        else
            pageType = title.subpageText
        end
    end
    -- Get the current episode name based on the pagename
    -- Returns empty string if wrong pagetype
    if pageType then
        episode = readableTitle(title.baseText)
    else
        episode = ''
    end
    return episode .. ';' .. prevLink(title.baseText) .. ';' .. nextLink(title.baseText)
end
 
return p
Community content is available under CC-BY-SA unless otherwise noted.