Module:Category pair: Difference between revisions
Appearance
Content deleted Content added
MusikBot II (talk | contribs) m Protected "Module:Category pair": High-risk template or module: 5631 transclusions (more info) ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite)) |
Updated from sandbox |
||
Line 1: | Line 1: | ||
require('Module:No globals') |
require('Module:No globals') |
||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local |
local hatnote = require('Module:Hatnote')._hatnote |
||
⚫ | |||
local hatnote = hatnoteModule._hatnote |
|||
⚫ | |||
local p = {} |
local p = {} |
||
Line 14: | Line 13: | ||
-- hatnote that says "see also" for one or both of prev/next (depending on whether they exist) |
-- hatnote that says "see also" for one or both of prev/next (depending on whether they exist) |
||
function p._pair(prevTitle, nextTitle) |
function p._pair(prevTitle, nextTitle) |
||
prevTitle = |
prevTitle = |
||
prevTitle and prevTitle.exists and |
|||
⚫ | |||
⚫ | |||
nextTitle = |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
return |
return '[[Category:Pages using category pair with no output]]' |
||
elseif prevTitle and (not nextTitle) then |
|||
note = mw.ustring.format('See also the preceding %s', prevTitle) |
|||
elseif (not prevTitle) and nextTitle then |
|||
note = mw.ustring.format('See also the succeeding %s', nextTitle) |
|||
⚫ | |||
note = mw.ustring.format( |
|||
'See also the preceding %s and the succeeding %s', |
|||
prevTitle, nextTitle |
|||
) |
|||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
⚫ | |||
note = note.." and the" |
|||
end |
|||
if nextTitle then |
|||
⚫ | |||
end |
|||
⚫ | |||
end |
end |
||
Line 44: | Line 47: | ||
function p.prevCat(frame) |
function p.prevCat(frame) |
||
local args = getArgs(frame, {wrappers={'Template:Preceding category'}}) |
local args = getArgs(frame, {wrappers={'Template:Preceding category'}}) |
||
local prevTitle = args[1] and mw.title.new(args[1], |
local prevTitle = args[1] and mw.title.new(args[1], 14) |
||
return p._pair(prevTitle, nil) |
return p._pair(prevTitle, nil) |
||
end |
end |
||
Line 50: | Line 53: | ||
function p.nextCat(frame) |
function p.nextCat(frame) |
||
local args = getArgs(frame, {wrappers={'Template:Succeeding category'}}) |
local args = getArgs(frame, {wrappers={'Template:Succeeding category'}}) |
||
local nextTitle = args[1] and mw.title.new(args[1], |
local nextTitle = args[1] and mw.title.new(args[1], 14) |
||
return p._pair(nil, nextTitle) |
return p._pair(nil, nextTitle) |
||
end |
end |
Revision as of 04:05, 24 December 2021
![]() | 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,800 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 hatnote = require('Module:Hatnote')._hatnote
local formatLink = require('Module:Format link')._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
formatLink{link = prevTitle.fullText}
nextTitle =
nextTitle and nextTitle.exists and
formatLink{link = nextTitle.fullText}
local note = ''
if not prevTitle and not nextTitle then
if mw.title.getCurrentTitle().namespace ~= 14 then -- 14 <-> Category
return ''
end
return '[[Category:Pages using category pair with no output]]'
elseif prevTitle and (not nextTitle) then
note = mw.ustring.format('See also the preceding %s', prevTitle)
elseif (not prevTitle) and nextTitle then
note = mw.ustring.format('See also the succeeding %s', nextTitle)
elseif prevTitle and nextTitle then
note = mw.ustring.format(
'See also the preceding %s and the succeeding %s',
prevTitle, nextTitle
)
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.new(args[1],'Category')
local nextTitle = args[2] and mw.title.new(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.new(args[1], 14)
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.new(args[1], 14)
return p._pair(nil, nextTitle)
end
return p