Module:Category pair
Appearance
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This Lua module is used on approximately 6,900 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
![]() | This module depends on the following other modules: |
Implements {{Category pair}}, {{Preceding category}}, and {{Succeeding category}}
Usage
{{#invoke:Category pair|_pair|title object for first page|title object for second page}}
require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs
local hatnoteModule = require('Module:Hatnote')
local hatnote = hatnoteModule._hatnote
local formatLink = hatnoteModule._formatLink
local p = {}
-- 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 prevTitle
nextTitle = nextTitle and nextTitle.exists and nextTitle
if not (prevTitle or nextTitle) then
if mw.title.getCurrentTitle().nsText == "Template" then
return ""
end
return "[[Category:Pages using category pair with no output]]"
end
local note = "See also the"
if prevTitle then
note = note.." preceding "..formatLink{link=prevTitle.fullText}
end
if prevTitle and nextTitle then
note = note.." and the"
end
if nextTitle then
note = note.." succeeding "..formatLink{link=nextTitle.fullText}
end
return hatnote(note,{extraclasses="seealso"})
end
function p.catPair(frame)
local args = getArgs(frame, {wrappers={'Template:Category pair'}})
local prevTitle = args[1] and mw.title.makeTitle(args[1],'Category')
local nextTitle = args[2] and mw.title.makeTitle(args[2],'Category')
return p._pair(prevTitle, nextTitle)
end
function p.prevCat(frame)
local args = getArgs(frame, {wrappers={'Template:Preceding category'}})
local prevTitle = args[1] and mw.title.makeTitle(args[1],'Category')
return p._pair(prevTitle, nil)
end
function p.nextCat(frame)
local args = getArgs(frame, {wrappers={'Template:Succeeding category'}})
local nextTitle = args[1] and mw.title.makeTitle(args[1],'Category')
return p._pair(nil, nextTitle)
end
return p