Saltu al enhavo

Modulo:LinkSkype

El Vikivojaĝo

Versiokontrolo

[redakti]

Versionomo en Vikidatumoj: 2023-12-08 Ok!


-- module variable and administration
local ls = {
	moduleInterface = {
		suite  = 'LinkSkype',
		serial = '2023-12-08',
		item   = 65157314
	}
}

-- module import
-- require( 'strict' )
local li = require( 'Module:Link utilities/i18n' )
local lu = require( 'Module:Link utilities' )

-- check single skype name
function ls.isSkypeName( s )
	if not s or type( s ) ~= 'string' then
		return 0
	end

	local user = s
	local param
	local q = s:find( '?', 1, true )
	if q then
		user = s:sub( 1, q - 1 )
		param = s:sub( q + 1, #s )
		if not li.params[ param ] then
			return 0
		end
	end
	if #user > 32 or #user < 6 then
		return 0
	end
	if not user:match( "^%l[%l%d%.,_%-]+$" ) then
		return 0
	end
	return 1
end

function ls.SkypeLink( m, isDemo )
	m = mw.text.trim( m )
	if m == '' then -- empty string
		return ''
	end
	local catPrefix = '[[Category:'
	if isDemo then
		catPrefix = ' [[:Category:'
	end

	local comment = ''
	local t
	m, comment = lu.extractComment( m )

	m = m:gsub( 'skype:', '' )
	if ls.isSkypeName( m ) > 0 then
		t = '<span class="listing-skype-link">' .. m ..'</span>'
		-- skype: link is performed by a JavaSript: MediaWiki:VCard.js
	else
		t = m .. catPrefix .. li.categories.invalidSkype
	end
	if comment ~= '' then
		t = t .. ' ' .. comment
	end
	return t
end

function ls.linkSkypeSet( args )
	args.skype   = args.skype or args[ 1 ] or ''
	if args.skype == '' then
		return ''
	end

	local ns     = mw.title.getCurrentTitle().namespace
	local isDemo = ns == 10 or ns == 828

	-- split separate Skype names
	local items = lu.splitItems( args.skype, li.delimiters, ';' )

	-- analyse Skype names
	local i = 0
	local s
	local result = ''

	for j = 1, #items, 1 do
		s = ls.SkypeLink( items[ j ], isDemo )
		if s ~= '' then
			if result == '' then
				result = s
			else
				if i == li.addSkype then
					result = result .. '<span class="listing-add-contact">'
				end
				result = result .. li.texts.comma .. s
			end
			i = i + 1
		end
	end
	if i > li.addSkype then
		result = result .. '</span>'
	end
	return result
end

-- #invoke call
function ls.linkSkype( frame )
	return ls.linkSkypeSet( frame.args )
end

-- template call
function ls.linkSkypeTemplate( frame )
	return ls.linkSkypeSet( frame:getParent().args )
end

return ls