Module:Connect Groups

Module documentation

Usage

edit

{{#invoke:Connect Groups|groups}}

This loops through all the groups in the Lua table onto Connect/Groups on Connect.

Translation

edit

The strings for this module are contained in Template:i18n/Wikimedia Resource Center.


local p = {}

-- To edit the list of groups in its raw form, go to the page named below.
content = require( 'Module:Wikimedia Resource Center/Groups' )
is_rtl = require( 'Module:Is rtl' )
lang = mw.getCurrentFrame():preprocess('{{int:lang}}')
ModuleMsg = require( 'Module:ModuleMsg' )
msg = ModuleMsg:get_msgs('Template:I18n/Wikimedia Resource Center', lang)

function get_translation(details)
	-- Get translated version of a list entry
	--
	-- Usage:
	--   details: table containing the entry to translate
	--
	-- Return table: translated entry (with English as fallback)
	
	if details.name == nil or lang == 'en' then
		-- This system assumes that a unique name is assigned.
		return details
	end

	for k, v in pairs(details) do
		if msg[k] ~= nil then
			details[k] = msg[k]
		end
	end

	return details

end

function get_directionality()
	-- Should something be left-aligned or right-aligned?
	if is_rtl[lang] == true then
		return 'right'
	end
	return 'left'
end

function build_entry(frame, details, template)
	-- Builds a group entry on [[m:Connect/Groups]]
	--
	-- Usage:
	--   frame: The frame object
	--   details: a table with type, name, description, icon is required
	--
	-- Return string: wikitext
	
	details = get_translation(details)
	
	template_args = {
		type = details.type,
	}
	
	if details.name ~= nil then
		template_args.name = details.name:gsub("%_", " ")
	end
	
	if details.edit_id == nil then
		template_args.edit_id = details.name
	end
	
	if template == 'Connect group' then
		if details.introduction ~= nil then
			template_args.introduction = details.introduction
		end
	else
		if details.description ~= nil then
			template_args.description = string.sub(details.description, 0, 200) .. "..."
		end
	end
	
	if details.icon ~= nil then
		template_args.icon = details.icon
	end
	
	if details.facebook ~= nil then
		template_args.facebook = details.facebook
	end
	
	if details.twitter ~= nil then
		template_args.twitter = details.twitter
	end
	
	if details.youtube ~= nil then
		template_args.youtube = details.youtube
	end

	entrycontent = frame:expandTemplate{
		title = template,
		args = template_args
	}
	
	return entrycontent
	
end

function p.groups(frame)
	-- Function for building group views
	-- 
	-- Usage:
	--   frame: The frame object
	--
	-- Return string: wikitext
	
	groupcontent = ''
	template = 'Connect listing'
	
	for _, group in ipairs(content) do
		groupcontent = groupcontent .. build_entry(frame, group, template)
	end
	
	return '<div dir="' .. frame:expandTemplate{ title = 'dir', args = { lang } } .. '">' .. groupcontent .. '</div>'
	
end

return p