Module:Communication channels
Jump to navigation
Jump to search
[Create] Documentation
local p = {}
function bold(text)
return "'''" .. text .. "'''"
end
-- See https://matrix-org.github.io/matrix-appservice-irc/latest/bridged_networks.html
local matrix_irc_bridges = {
['irc.freenode.net'] = '#freenode_#channame:matrix.org',
['irc.oftc.net'] = '#_oftc_#channame:matrix.org',
['irc.libera.chat'] = '#channame:libera.chat',
}
-- debug with e.g. =p.main(nil, {forum_category = 'foo'})
function p.main (frame, debugArgs)
local args = debugArgs or {}
local page_title = 'DebugTitle'
if frame then
page_title = frame:preprocess('{{PAGENAME}}')
-- Note that this loop does not preserve the order of the passed
-- parameters due to https://phabricator.wikimedia.org/T197516
for k, v in pairs(frame:getParent().args) do
if not k:find('_') then
-- Just for convenience so that we can write args.foo_bar instead of having to write args['foo bar']
args[k:gsub(' ', '_')] = v
end
end
end
local links = {}
if args.forum_category then
table.insert(links, {url='https://community.openstreetmap.org/c/' .. args.forum_category:gsub(':', '/'), label='forum', alt='forum category', icon='Community Noun project 2280.svg|16px'})
end
if args.forum_tag then
table.insert(links, {url='https://community.openstreetmap.org/tag/' .. args.forum_tag, label=bold(args.forum_tag), alt='forum tag', icon='VisualEditor - Icon - Tag-big.svg|16px'})
end
if args.forum then
table.insert(links, {url=args.forum, label='Forum', alt='', icon='Font Awesome 5 solid comments.svg|18px'})
end
-- Links to hashtags on social media are hidden by default. Their display can be enabled via a user style.
local hash_tag = page_title:gsub('%s', '')
local hidden_css = 'display: none'
-- Note that using the 'hidden' HTML attribute would be better (since user styles wouldn't need !important)
-- but the MediaWiki sanitizer doesn't allow it (see https://phabricator.wikimedia.org/T224445).
table.insert(links, {url='https://en.osm.town/tags/' .. hash_tag, label='#' .. hash_tag, alt='Mastodon', icon='Font Awesome 5 brands mastodon.svg|16px', attrs={style=hidden_css, id='channel-en-osm-town'}})
table.insert(links, {url='https://twitter.com/search?q=%23' .. hash_tag, label='#' .. hash_tag, alt='Twitter', icon='Twitter font awesome.svg|16px', attrs={style=hidden_css, id='channel-twitter'}})
if args.list_name then
local base_url = args.list_baseurl or 'https://lists.openstreetmap.org/listinfo/'
table.insert(links, {url=base_url .. args.list_name, label=bold(args.list_name), alt='mailing list', icon='Maki2-post-18.svg'})
end
local irc_server = args.irc_server or 'irc.oftc.net'
if args.irc_channel then
table.insert(links, {url='irc://' .. irc_server .. '/' .. args.irc_channel, label=bold(args.irc_channel)})
end
if not args.matrix_room and args.irc_channel and matrix_irc_bridges[irc_server] then
args.matrix_room = matrix_irc_bridges[irc_server]:gsub('#channame', args.irc_channel)
end
if args.matrix_room then
local parts = mw.text.split(args.matrix_room, ':')
parts[1] = bold(parts[1])
local label = table.concat(parts, ':')
table.insert(links, {url='https://matrix.to/#/' .. args.matrix_room, label=label, alt='Matrix room', icon='Matrix icon.svg|x18px'})
end
if args.mastodon_address then
table.insert(links, {url='https://fedirect.toolforge.org/?id=' .. args.mastodon_address, label='Mastodon', alt='', icon='Font Awesome 5 brands mastodon.svg|18px'})
end
if args.bluesky_handle then
table.insert(links, {url='https://bsky.app/profile/' .. args.bluesky_handle, label='Bluesky', alt='', icon='Bluesky logo (black).svg|18px'})
end
if args.issue_tracker then
table.insert(links, {url=args.issue_tracker, label='issue tracker', alt='', icon='Font Awesome 5 solid list.svg|16px'})
end
-- closed platforms
if args.github_discussions then
table.insert(links, {url='https://github.com/' .. args.github_discussions .. '/discussions', label='GitHub Discussions', alt='', icon='Octicons-mark-github.svg|18px'})
end
if args.telegram then
table.insert(links, {url='https://telegram.me/' .. args.telegram, label='Telegram', alt='', icon='Font Awesome 5 brands telegram-plane.svg|18px'})
end
if args.slack_url then
table.insert(links, {url=args.slack_url, label='Slack', alt='', icon='Font Awesome 5 brands slack-hash.svg|18px'})
end
if args.discord then
table.insert(links, {url='https://discord.com/invite/' .. args.discord, label='Discord', alt='', icon='Discord_black_D.svg|x18px'})
end
if args.facebook_group then
table.insert(links, {url='https://www.facebook.com/groups/' .. args.facebook_group, label='Facebook', alt='', icon='Font Awesome 5 brands facebook.svg|18px'})
end
local out = ''
for _, link in ipairs(links) do
if link.icon then
link.label = '[[File:' .. link.icon .. '|alt=' .. link.alt .. '|link=]] ' .. link.label
end
out = out .. mw.text.tag('span', link.attrs, ' [' .. link.url .. ' ' .. link.label .. ']')
end
return out
end
return p