Module:See also: Difference between revisions

Updated from sandbox; in particular, applies use of Module:Hatnote list
m (1 revision imported: Templates)
(Updated from sandbox; in particular, applies use of Module:Hatnote list)
Line 1:
--[[
-- This module produces a "See also: a, b, and c" link. It implements the
-- template {{see also}}.
--]]
 
local mHatnote = require('Module:Hatnote')
mTableToolslocal mHatlist = require('Module:TableToolsHatnote list')
local mTableTools -- lazily initialise
local mArguments -- lazily initialise
local libraryUtil = require('libraryUtil')
 
local checkType = libraryUtil.checkType
local p = {}
 
function p.seealsoseeAlso(frame)
mTableTools = require('Module:TableTools')
mArguments = require('Module:Arguments')
local args = mArguments.getArgs(frame, {parentOnly = true})
Line 17:
for k, v in pairs(args) do
if type(k) == 'number' then
local numstringdisplay = tostring(args['label ' .. k] or args['l' .. k)]
local displaypage = args['label ' ..display numstring]and
string.format('%s|%s', string.gsub(v, '|.*$', ''), display) or v
or args['l' .. numstring]
pages[k#pages + 1] = page
local page = {v, display}
pages[k] = page
end
end
pages = mTableTools.compressSparseArray(pages)
if not pages[1] then
return mHatnote.makeWikitextError(
Line 36 ⟶ 34:
selfref = args.selfref
}
return p._seealso(optionspages, unpack(pages)options)
end
 
function p._seealso_seeAlso(optionsargs, ...options)
checkType('_seeAlso', 1, args, 'table')
local altphrase = options and options.altphrase or 'See also'
checkType('_seeAlso', 2, options, 'table', true)
local links = mHatnote.formatPageTables(...)
options = options or {}
links = mw.text.listToText(links)
local textphrase = options.altphrase ..or ':See also' .. links
local list = mHatlist.andList(args, true)
local text = phrase .. ': ' .. list
 
-- Pass options through.
local hnOptions = {selfref = options.selfref}
hnOptions.selfref = options.selfref
 
return mHatnote._hatnote(text, hnOptions)
end
 
--temporary aliases to move to CamelCase
p.seealso = p.seeAlso
p._seealso = p._seeAlso
 
return p
Anonymous user