Module:Navigation

local Nav = {} local getArgs = require('Dev:Arguments').getArgs local HF = mw.InfoboxBuilderHF

-- The following function can be removed upon migration to UCP, as it is part of the native stack -- Adds an internal link -- `label` is optional function HF.Link( link, text ) if not HF.isempty( text ) then return string.format('%s'..'%s|%s]]', '[[', link, text) else return string.format('%s'..'%s]]', '[[', link) end end

function Nav.CharacterPageLinks (frame) local args = getArgs(frame) -- This allows for a manual declaration of the page, for testing purposes. -- Otherwise, it uses the current page to derive the basepage title local page = args[1] or mw.title.getCurrentTitle.baseText return Nav._CharacterPageLinks(page, args) end function Nav._CharacterPageLinks (page, args) -- Make a list of links, allowing for manual declaration of page titles local links = {} local book = args['book'] or page .. '/Book' local film = args['film'] or page .. '/Film' local tv = args['tv'] or page .. '/TV' local media = args['media'] or page .. '/Media' if mw.title.new(page).exists then table.insert(links, HF.Link(page, 'General')) end if mw.title.new(book).exists then table.insert(links, HF.Link(book, 'Book')) end if mw.title.new(film).exists then table.insert(links, HF.Link(film, 'Film')) end if mw.title.new(tv).exists then table.insert(links, HF.Link(tv, 'TV')) end if mw.title.new(media).exists then table.insert(links, HF.Link(media, 'Media')) end -- Beautify the HTML output local wrapper = mw.html.create("center") :wikitext(table.concat(links, ' · ')) :done -- if there's only one link, and that's the current page, then return nothing if (#links <= 1 and page == mw.title.getCurrentTitle.text) then return nil end -- if there are links, return them beautified. Otherwise return nothing. return wrapper and tostring(wrapper) or nil end

return Nav