Module:Category pair

From 2021pedia

Template loop detected: Template:Module other

<templatestyles src="Module:Message box/ombox.css"></templatestyles>

Lua error in Module:Lua_banner at line 113: attempt to index field 'edit' (a nil value).

Implements {{Category pair}}, {{Preceding category}}, and {{Succeeding category}}


{{#invoke:Category pair|_pair|title object for first page|title object for second page}}

local getArgs = require('Module:Arguments').getArgs
local hatnote = require('Module:Hatnote')._hatnote
local formatLink = require('Module:Format link')._formatLink

local p = {}

local catNS = -- category namespace number

-- Lua implementation of [[Template:CategoryPair]]
-- Arguments:
--   prevTitle -- mw.title.Title object for preceding category
--   nextTitle -- mw.title.Title object for succeeding category
-- Returns:
--   hatnote that says "see also" for one or both of prev/next (depending on whether they exist)
function p._pair(prevTitle, nextTitle)
	prevTitle = prevTitle and prevTitle.exists and formatLink{link = prevTitle.fullText}
	nextTitle = nextTitle and nextTitle.exists and formatLink{link = nextTitle.fullText}
	local note = ''
	if prevTitle and nextTitle then -- if both
		note = mw.ustring.format('See also the preceding %s and the succeeding %s',prevTitle, nextTitle)
	elseif prevTitle then -- if only prevTitle
		note = mw.ustring.format('See also the preceding %s', prevTitle)
	elseif nextTitle then -- if only nextTitle
		note = mw.ustring.format('See also the succeeding %s', nextTitle)
	else                  -- otherwise neither
		return mw.title.getCurrentTitle().namespace == catNS and '[[Category:Pages using category pair with no output]]' or ''
	return hatnote(note, {extraclasses = 'seealso'})

function p.catPair(frame)
	local args = getArgs(frame, {wrappers={'Template:Category pair'}})
	local prevTitle = args[1] and[1],catNS)
	local nextTitle = args[2] and[2],catNS)
	return p._pair(prevTitle, nextTitle)

function p.prevCat(frame)
	local args = getArgs(frame, {wrappers={'Template:Preceding category'}})
	local prevTitle = args[1] and[1], catNS)
	return p._pair(prevTitle, nil)

function p.nextCat(frame)
	local args = getArgs(frame, {wrappers={'Template:Succeeding category'}})
	local nextTitle = args[1] and[1], catNS)
	return p._pair(nil, nextTitle)

return p