Module:Hatnote: Difference between revisions
Jump to navigation
Jump to search
add Template:See also
>Mr. Stradivarius (factor out some of the main code to a shared function) |
>Mr. Stradivarius (add Template:See also) |
||
Line 287: | Line 287: | ||
p.main = makeInvokeFunction(f.main) | p.main = makeInvokeFunction(f.main) | ||
-------------------------------------------------------------------------------- | |||
-- See also | |||
-- | |||
-- Produces a "See also: a, b and c" link. The first parameter is an optional | |||
-- alternative for the "See also" text. The following parameters are an | |||
-- unlimited number of page/display tables. The first entry in the table is the | |||
-- page name, and the second entry in the table is the display text. | |||
-------------------------------------------------------------------------------- | |||
function p._seealso(altphrase, ...) | |||
altphrase = altphrase or 'See also' | |||
local pages = {...} | |||
local links = formatPageTables(pages) | |||
links = mw.text.listToText(links) | |||
local text = altphrase .. ': ' .. links | |||
local extraclasses = 'boilerplate seealso' | |||
return p._rellink(text, extraclasses) | |||
end | |||
function f.seealso(args) | |||
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 makeWikitextError( | |||
'[[Template:See also|' | |||
.. 'Template must be given at least one article name]]' | |||
) | |||
end | |||
local altphrase = args.altphrase | |||
return p._seealso(altphrase, unpack(pages)) | |||
end | |||
p.seealso = makeInvokeFunction(f.seealso) | |||
return p | return p |