Module:Forumlink
Documentation [edit]
This page is a stub - it only covers the very basics of its subject. More information should be added to make the page informative and useful. If no more information is available, the page should be considered for a merge, redirect, or deletion.
Details: documentation to be written
If you can correct the issue, please edit the page to do so, then remove this notice.
Please see Template:Forumlink for usage information. Use the template rather than invoking the module.Details: documentation to be written
If you can correct the issue, please edit the page to do so, then remove this notice.
The above documentation is transcluded from Module:Forumlink/doc.
local p = {}
local largs
--Keys must be lowercase
local presets = {
npo = { domain = 'npowned.net', type = 'ips' }
}
--Keys must be lowercase
local types = {
ips = {
sep = '-',
announcement = 'announcement/%s/',
forum = 'forums/forum/%s/',
news = 'news/community/%s/',
profile = 'profile/%s/',
topic = 'forums/topic/%s/',
default = 'forums/'
}
}
local function argDefault(arg, default)
if mw.text.trim(largs[arg] or '') == '' then
return default
else
return largs[arg]
end
end
local function geturl(url, arg, ftype)
if arg == 'default' then
return url .. ftype[arg]
end
local text = mw.ustring.lower(largs[arg])
if ftype.sep ~= ' ' then
text = mw.ustring.gsub(text, '%s', ftype.sep)
end
return url .. mw.ustring.format(ftype[arg], text)
end
function p.main(frame)
return p.call(frame:getParent().args)
end
function p.call(args)
largs = args-- lazy shortcut for local args
local ftype, url, domain, display
if argDefault('http') then
url = 'http://'
else
url = 'https://'
end
local preset = presets[mw.ustring.lower(argDefault(1, ''))]
if not preset then
domain = argDefault(1)
ftype = argDefault('type')
else
domain = preset.domain
ftype = preset.type
end
if not domain then
return '<span class="error">missing site address</span>'
end
if not ftype then
return '<span class="error">missing forum type</span>'
end
ftype = types[mw.ustring.lower(ftype)]
if not ftype then
return '<span class="error">type is invalid or unrecognized</span>'
end
url = url .. domain .. '/'
local params = {'topic', 'profile', 'forum', 'news', 'announcement'}
local component = 'default'
for i, para in ipairs(params) do
if argDefault(para) then
component = para
break
end
end
url = geturl(url, component, ftype)
if argDefault('numbered') then
return '[' .. url .. ']'
end
display = argDefault(2)
if not display then
if component == 'default' then
display = args[1] .. ' forums'
else
display = args[component]
end
end
return '[' .. url .. ' ' .. display .. ']'
end
return p