このテンプレートは、以下のLuaモジュールを使用しています。 |
このモジュールは、メールアドレスを整形し、メール用のリンクを付け加えます。
コメントはメールアドレスの後に括弧で囲んで追加する必要があります。認識できないエラーが出ている場合、メールアドレスに左から右のマーク(通常@の前後またはメールアドレスの末尾)などの目に見えない制御文字が含まれていたり、ハイフンの文字が間違っている可能性があります。ソフトハイフン(U+00AD
:「」)やハイフンマイナス(U+002D
:「-」)ではなくハイフン(U+2010
:「‐」)を使用してください。また、全角になっていないかも注意が必要です。
使用状況
このモジュールを使用しているモジュールは以下の通りです:
このモジュールを使用しているテンプレートは以下の通りです:
メンテナンスカテゴリ
このモジュールは以下のメンテナンスカテゴリを使用します:
使用例
メールアドレス | ウィキ構文 | 出力 |
---|---|---|
[email protected] | {{#invoke:LinkMail|linkMails|[email protected]}} | [email protected] |
café@xyz.hotel.com | {{#invoke:LinkMail|linkMails|café@xyz.hotel.com}} | café@xyz.hotel.com Category:Unicode文字を含んだメールアドレス |
[email protected] | {{#invoke:LinkMail|linkMails|[email protected] (情報)}} | [email protected] (情報) Category:無効なフォーマットのメールアドレス メールアドレスのフォーマットが無効です |
[email protected], [email protected] | {{#invoke:LinkMail|linkMails|[email protected], [email protected]}} | [email protected]、[email protected] |
info@$xyz.hotel.com | {{#invoke:LinkMail|linkMails|info@$xyz.hotel.com}} | info@$xyz.hotel.com Category:無効なフォーマットのメールアドレス メールアドレスのフォーマットが無効です |
エラーが発生した場合、メンテナンスカテゴリに加えてメールアドレスの後にエラーメッセージが表示されます。
関数
function lm._isEmail( s )
s: string;
メールアドレス s
が有効なフォーマットかどうかを調べます。
function lm._linkMail( m, args, ignoreUnicode )
m: string;
args: arguments array;
ignoreUnicode: boolean;
渡されたメールアドレスの有効性を確認して、有効ならばリンクを付けて返します.
function lm.linkMailSet( args )
args: arguments array;
この関数は複数のメールアドレスを切り分け、1つずつlm.linkMail
に渡します。
function lm.linkMails( frame )
frame: frame object;
この関数は、ウィキテキスト内でのマジックワード呼び出しのインターフェースを提供します。
function lm.linkMailsTemplate( frame )
frame: frame object;
この関数はテンプレート呼び出しのインターフェースを提供します。
変数
lm.categories
— エラーメッセージと同じ名前のカテゴリを含む配列lm.delimiters
— 電話番号の様々な区切り文字を含む配列。この配列に半角カンマを入れる必要はありません。lm.addNum
— 実際に表示されるメールアドレスの数。余分なアドレス(何もしなければ非表示のアドレス)はHTMLのソースに入っており、CSSスタイルを使うことで表示できます。
CSSクラス
このモジュールは以下のCSSクラスを使用します:
error
— エラーメッセージに付与されるクラスlisting-check-recommended
— 推奨される注意事項のクラスlisting-add-contact
— 非表示のメールアドレスのクラス。メールアドレスが既定の数以上ある場合、余ったアドレスは非表示になりますが、HTMLのソーステキストには追加されます。
関連項目
この解説は、モジュール:LinkMail/docから呼び出されています。 (編集 | 履歴) 編集者は、このモジュールをサンドボックス (作成 | 複製)とテストケース (作成)で試すことができます。(解説) このモジュールのサブページ一覧。 |
-- module variable and administration local lm = { moduleInterface = { suite = 'LinkMail', serial = '2023-12-08', item = 65157414 } } -- module import -- require( 'strict' ) local li = require( 'Module:Link utilities/i18n' ) local lu = require( 'Module:Link utilities' ) -- check single email address function lm._isEmail( s ) local result = 2 if s == nil or type( s ) ~= 'string' or #s > 254 or s:find( '%s' ) or s:find( '%.%.' ) or s:find( '%.@' ) or s:find( '@[%.%-]' ) or s:find( '%-%.' ) or s:find( '%.%-' ) or s:match( '^%.' ) then return 0 end local repl, at = s:gsub( '@', '@' ) if at ~= 1 then return 0 end at = s:find( '@' ) local user = s:sub( 1, at - 1 ) local domain = s:sub( at + 1, #s ) if not user or not domain or #user > 64 or #domain > 253 then return 0 end -- handle user part if not mw.ustring.match( user, "^[%w!#&'/=_`{|}~%^%$%%%+%-%*%.%?]+$" ) then return 0 end if not user:match( "^[%w!#&'/=_`{|}~%^%$%%%+%-%*%.%?]+$" ) then result = 1 end -- handle domain part if not mw.ustring.match( domain, '^[%w%.%-]+%.%a%a+$' ) then return 0 end if not domain:match( '^[%w%.%-]+%.%a%a+$' ) then result = 1 end -- not yet analysed: texts in quotes in user part -- added on demand return result end function lm._linkMail( m, isDemo, ignoreUnicode ) m = mw.text.trim( m ) if m == '' then return '' end local catPrefix = '[[Category:' if isDemo then catPrefix = ' [[:Category:' end local comment = '' m, comment = lu.extractComment( m ) m = m:gsub( 'mailto:', '' ) local isEmail = lm._isEmail( m ) local t if isEmail > 0 then t = '<span class="plainlinks nourlexpansion">[mailto:' .. m .. ' ' .. m .. ']</span>' if isEmail == 1 and not ignoreUnicode then t = t .. catPrefix .. li.categories.nonASCII end else t = m .. catPrefix .. li.categories.invalidMail end if comment ~= '' then t = t .. ' ' .. comment end return t end function lm.linkMailSet( args ) args.email = args.email or args[ 1 ] or '' if args.email == '' then return '' end local ns = mw.title.getCurrentTitle().namespace local isDemo = ns == 10 or ns == 828 -- split separate email local items = lu.splitItems( args.email, li.delimiters ) -- analyse emails local result = '' local i = 0 local s for j, item in ipairs( items ) do s = lm._linkMail( item, isDemo, args.ignoreUnicode ) if s ~= '' then if result == '' then result = s else if i == li.addMail then result = result .. '<span class="listing-add-contact">' end result = result .. li.texts.comma .. s end i = i + 1 end end if i > li.addMail then result = result .. '</span>' end return result end -- #invoke call function lm.linkMails( frame ) return lm.linkMailSet( frame.args ) end -- template call function lm.linkMailsTemplate( frame ) return lm.linkMailSet( frame:getParent().args ) end return lm