Modul:See also
Tampilan
--[[
-- This module produces a "See also: a, b and c" link. It implements the
-- template {{see also}}.
--]]
local mHatnote = require('Modul:Hatnote')
local mTableTools -- lazily initialise
local mArguments -- lazily initialise
local p = {}
function p.seealso(frame)
mTableTools = require('Modul:TableTools')
mArguments = require('Modul:Arguments')
local args = mArguments.getArgs(frame, {parentOnly = true})
local pages = {}
for k, v in pairs(args) do
if type(k) == 'number' then
local numstring = tostring(k)
local display = args['label ' .. numstring]
or args['l' .. numstring]
local page = {v, display}
pages[k] = page
end
end
pages = mTableTools.compressSparseArray(pages)
if not pages[1] then
return mHatnote.makeWikitextError(
'tidak ada ruang nama halaman ditentukan',
'Templat:Lihat juga#Galat',
args.category
)
end
local options = {
altphrase = args.altphrase,
selfref = args.selfref
}
return p._seealso(options, unpack(pages))
end
function p._seealso(options, ...)
local altphrase = options and options.altphrase or 'Lihat pula'
local links = mHatnote.formatPageTables(...)
-- Use semicolons if any links contain a comma
local separator = ', '
for k, v in pairs(links) do
if string.find(v, ',') then
separator = '; '
break
end
end
-- Apply the Oxford comma in general
-- Insert comma after every item if the first item contains a section link.
if table.getn(links) >= 3 or string.find(links[1], ' § ') then
links = mw.text.listToText(links, separator, (separator .. 'dan '))
else
links = mw.text.listToText(links, ' dan ')
end
local text = altphrase .. ': ' .. links
-- Pass options through.
local hnOptions = {}
hnOptions.selfref = options.selfref
return mHatnote._hatnote(text, hnOptions)
end
return p