Jump to content

Module:Sandbox/Cookai1205/Community Wishlist

From Meta, a Wikimedia project coordination wiki
Module documentation
local p = {}

function p.csvToFocusAreaLinks( frame )
	local csv = mw.text.trim( frame.args[ 1 ] )
	if csv == '' then
		return ''
	end
	local list = mw.text.split( csv, ",", true )
	local out = {}
	for _, slug in ipairs( list ) do
		local faTitle =  mw.title.new( 'Community Wishlist/Focus areas/' .. slug )
		if faTitle ~= nil then
			if faTitle.exists then
				table.insert( out, mw.getCurrentFrame():expandTemplate{
					-- Prepend the colon as we're transcluding from mainspace.
					title = ':' .. faTitle.prefixedText,
					args = { format = 'title' }
				} )
			else
				-- All focus areas should exist before being added to a list, but if one doesn't then show a link to create it.
				local editUrl = faTitle:fullUrl( { action='edit', preload='Template:Community_Wishlist/Focus_area/preload' } )
				table.insert( out, '[' .. editUrl .. ' Create "' .. slug .. '"]' )
			end
		end
	end
	return table.concat( out, mw.message.new( 'comma-separator' ):plain() .. mw.message.new( 'word-separator' ):plain() )
end

return p