Module:See also
Jump to navigation
Jump to search
require('strict')
local p = {}
local getArgs = require('Module:Arguments').getArgs
local error_message = require('Module:Error')['error']
function p._see_also(args)
local links = {}
local link_count = 0
for k, v in pairs(args) do
if type(k) == 'number' then
link_count = 1 + link_count
links[link_count] = k
end
end
table.sort(links)
for i, k in ipairs(links) do
links[i] = '[[:' .. args[k] .. '|' .. (args['l' .. k] or args[k]) .. ']]'
end
local link
if #links == 0 then
link = error_message({'[[Module:See also]] error: Module must be given at least one article name'})
elseif #links == 1 then
link = links[1]
else
link = table.concat(links, ', ', 1, math.min(#links - 1, 14)) .. ' and ' .. links[math.min(#links, 15)]
if #links > 15 then
link = link .. '<br/>' .. error_message({'[[Module:See also]] error: Too many links specified (maximum is 15)'})
end
end
local text = (args.altphrase or 'See also') .. ': ' .. link
return tostring(mw.html.create('div'):addClass('rellink boilerplate seealso'):css({['margin-left'] = '2em', ['font-style'] = 'italic'}):wikitext(text))
end
function p.see_also(frame)
return p._see_also(getArgs(frame))
end
return p