FANDOM


local MN = {}
 
-- The page title of whatever page is calling the function
_G.pageTitle = mw.title.getCurrentTitle().text
 
----------------------------
-- Libraries of functions --
----------------------------
-- Modules and functions used inside this Module
 
-- stands for High Frequency
local HF = require('Module:HF')
-- Parses invocation and template parameters, trims whitespace, and removes blanks.
local getArgs = require('Dev:Arguments').getArgs
-- Language functions
local language = mw.language.new('en')
 
local function chapterFix (chapter)
    if chapter and tonumber(chapter) > 700 then 
        return '700+' .. (tonumber(chapter) - 700) 
    else
        return chapter or ''
    end
end
 
----------------------------------------------------------
-- Public functions (called from a Template or article) --
----------------------------------------------------------
-- Provides cross-media navigation
function MN.MediaNav(frame)
    local iargs = getArgs(frame)
    return MN._MediaNav(iargs)
end
 
---------------------------------------------------------
-- Internal functions (used in this and other Modules) --
---------------------------------------------------------
-- Provides cross-media navigation
function MN._MediaNav ( args )
    -- {{tlx|1=MediaNav|2=Media Category|3=Release Number|4=Direction|5=shippuden=Value|6=boruto=Value}}
    local Category = args[1] or args['Category'] or nil
    assert(Category, 'No MediaNav category given')
    local Release = args[2] or args['Release'] or 0
    assert(Release, 'No MediaNav release given')
    local Direction = args[3] or args['Direction'] or 0
    local Shippuden = args[4] or args['shippuden'] or 'No'
    if Shippuden == 'Yes' then Shippuden = true else Shippuden = false end
    local Boruto = args[5] or args['boruto'] or 'No'
    if Boruto == 'Yes' then Boruto = true else Boruto = false end
    local DisplayType = args['DisplayType'] or nil
 
    local querystring = { 'mainlabel=main' }
    local list1 = { Episode = true, Movie = true, Arc = true }
    local list2 = { Volume = true, Databook = true, Fanbook = true, Artbook = true }
 
    if list1[Category] then
        table.insert( querystring,
            HF.Link( ('Concept:%ss of %s'):format(
            Category,
                (Boruto == true and 'Boruto' or
                    (Shippuden == true and 'Naruto Shippuden'
                        or 'Naruto Original')
                )
            ) )
        )
    elseif list2[Category] then
        table.insert( querystring, ('[[Concept:%s]]'):format( Category ) )
        table.insert( querystring, 
            Boruto == true and '[[Manga::Boruto]]' or '[[Manga::!Boruto]]' 
        )
    elseif Category == 'Chapter' then
        table.insert( querystring,
            Boruto == true and
            HF.Link('Concept:Chapter of Boruto Manga') or
            HF.Link('Concept:Chapter of Naruto Manga') )
    else
        return nil
    end
    table.insert( querystring, 
        HF.Link( ("%s number::%s")
            :format( Category, 
                (tonumber(Release or nil) or 0) + (tonumber(Direction or nil) or 0) ) )
    )
    if Category == 'Episode' then
        querystring['default'] =
            (Boruto == true and
                "''Boruto'' Episode" or
                (Shippuden == true and
                    "''Naruto Shippūden'' Episode" or
                    "''Naruto'' Episode")) .. ' #' .. Release
        if args['DisplayType'] == 'Number' then
          querystring['userparam'] =
                (Boruto == true and
                    "''Boruto'' Episode" or
                    (Shippuden == true and
                        "''Naruto Shippūden'' Episode" or
                        "''Naruto'' Episode")) .. ' #' .. chapterFix( Release )
        end
    elseif Category == 'Chapter' then
        querystring['default'] =
            (Boruto == true and
                "''Boruto'' Chapter" or
                "''Naruto'' Chapter") .. ' #' .. Release
        if args['DisplayType'] == 'Number' then
          querystring['userparam'] =
            (Boruto == true and
                "''Boruto'' Chapter" or
                "''Naruto'' Chapter") .. ' #' .. chapterFix( Release )
        end
  else
    querystring['default'] = Category .. ' #' .. Release
    if args['DisplayType'] == 'Number' then
        querystring['userparam'] = Category .. ' #' .. chapterFix( Release )
    end
  end
 
  local query = mw.smw.ask( querystring )
  -- for each result is a record, and the first property should be the bare page name, the second the type
  if query then
    local o = {}
    for _,item in ipairs( query ) do
      -- MediaNav/link
      table.insert(o, 
          HF.Link( 
              item['main']:match('%[%[([^|]*)|?'), 
              querystring['userparam'] or mw.text.trim(item['main']:match('%[%[:?([^|]*)|?'):match("[^(]*")) )
      )
    end
    return table.concat(o, '\n')
  else
    return nil
  end
end
 
-------------------------------------------------
-- Output (send it back to whatever called it) --
-------------------------------------------------
return MN
Community content is available under CC-BY-SA unless otherwise noted.