Module:Communication channels: Difference between revisions

From OpenStreetMap Wiki
Jump to navigation Jump to search
(wrap links in spans)
(automatically add links to social media hashtags (en.osm.town & Twitter) but hide them by default: their display needs to be enabled with a user style)
Line 21: Line 21:
function p.main (frame, debugArgs)
function p.main (frame, debugArgs)
local args = debugArgs or {}
local args = debugArgs or {}
local page_title = 'DebugTitle'
if frame then
if frame then
page_title = frame:getParent():getTitle()
for k, v in pairs(frame:getParent().args) do
for k, v in pairs(frame:getParent().args) do
if not k:find('_') then
if not k:find('_') then
Line 41: Line 43:
table.insert(links, link('https://community.openstreetmap.org/tag/' .. args.forum_tag, bold(args.forum_tag), 'forum tag', 'VisualEditor - Icon - Tag-big.svg|16px'))
table.insert(links, link('https://community.openstreetmap.org/tag/' .. args.forum_tag, bold(args.forum_tag), 'forum tag', 'VisualEditor - Icon - Tag-big.svg|16px'))
end
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, link('https://en.osm.town/tags/' .. hash_tag, '#' .. hash_tag, 'Mastodon', 'Font Awesome 5 brands mastodon.svg|16px', {style=hidden_css, id='channel-en-osm-town'}))
table.insert(links, link('https://twitter.com/search?q=%23' .. hash_tag, '#' .. hash_tag, 'Twitter', 'Twitter font awesome.svg|16px', {style=hidden_css, id='channel-twitter'}))
if args.list_name then
if args.list_name then
local base_url = args.list_baseurl or 'https://lists.openstreetmap.org/listinfo/'
local base_url = args.list_baseurl or 'https://lists.openstreetmap.org/listinfo/'

Revision as of 07:37, 16 October 2022

[Create] Documentation
local p = {}

function link(url, label, alt, icon, attrs)
	if icon then
		label = '[[File:' .. icon .. '|alt=' .. alt .. '|link=]] ' .. label
	end
	return mw.text.tag('span', attrs, ' [' .. url .. ' ' .. label .. ']')
end

function bold(text)
	return "'''" .. text .. "'''"
end

-- See https://matrix-org.github.io/matrix-appservice-irc/latest/bridged_networks.html
local matrix_irc_bridges = {
	['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:getParent():getTitle()
		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
		local parts = mw.text.split(args.forum_category, ':')
		parts[#parts] = bold(parts[#parts])
		local label = table.concat(parts, ':')
		table.insert(links, link('https://community.openstreetmap.org/c/' .. args.forum_category:gsub(':', '/'), label, 'forum category', 'Community Noun project 2280.svg|16px'))
	end
	if args.forum_tag then
		table.insert(links, link('https://community.openstreetmap.org/tag/' .. args.forum_tag, bold(args.forum_tag), 'forum tag', 'VisualEditor - Icon - Tag-big.svg|16px'))
	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, link('https://en.osm.town/tags/' .. hash_tag, '#' .. hash_tag, 'Mastodon', 'Font Awesome 5 brands mastodon.svg|16px', {style=hidden_css, id='channel-en-osm-town'}))
	table.insert(links, link('https://twitter.com/search?q=%23' .. hash_tag, '#' .. hash_tag, 'Twitter', 'Twitter font awesome.svg|16px', {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, link(base_url .. args.list_name, bold(args.list_name), 'mailing list', 'Maki2-post-18.svg'))
	end
	local irc_server = args.irc_server or 'irc.oftc.net'
	if args.irc_channel then
		table.insert(links, link('irc://' .. irc_server .. '/' .. args.irc_channel, 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, link('https://matrix.to/#/' .. args.matrix_room, label, 'Matrix room', 'Matrix icon.svg|x18px'))
	end
	if args.issue_tracker then
		table.insert(links, link(args.issue_tracker, 'issue tracker', '', 'Font Awesome 5 solid list.svg|16px'))
	end
	if args.github_discussions then
		table.insert(links, link('https://github.com/' .. args.github_discussions .. '/discussions', 'GitHub Discussions', '', 'Octicons-mark-github.svg|18px'))
	end
	if args.telegram then
		table.insert(links, link('https://telegram.me/' .. args.telegram, bold('@' .. args.telegram), 'Telegram group', 'Font Awesome 5 brands telegram-plane.svg|18px'))
	end
	
	-- This template intentionally does not support closed platforms that not only
	-- require/bug you to create an account in order to access the channel but
	-- also are proprietary software, such as Slack, Discord, Facebook and Twitter.
	
	return table.concat(links)
end

return p