モジュールの解説[表示] [編集] [履歴] [キャッシュを破棄]

{{de:template:DU}}
{{Template:Module rating|r}}

__NOTOC__

このモジュールは、電話番号にリンクする機能を提供します。FAX番号はチェックされますが、リンクはしてありません。コメント追加は必ず電話番号の後に、半角丸カッコで挟んで記してください。

このモジュールは、国際化のためにModule:Link utilities/i18n モジュールを使用します。サブ配列の意味はそのモジュールのページに説明されています。 {{テンプレート:モジュールのバージョン}}

{{さらに必要なモジュール|リンク ユーティリティ|リンク ユーティリティ/i18n|リンク ユーティリティ/電話番号}}

{{モジュールで必要|電話クイックバーOrtvCard}}

さらに必要なモジュール

モジュールには LinkPhone モジュール - 及び対応するメンテナンス・カテゴリが必要です。そのカテゴリには、このモジュールに依存するすべてのモジュールが再度リストされます。

使い方の例

文字列 コード 結果
+49 123 2 567.890 内線5 {{#invoke:Phone|linkPhone|+49 123 2 567.890 内線5}} +49 123 2 567.890 内線5 Category:無効なフォーマットの電話番号 電話番号のフォーマットが無効です
+49 123 2 567.890 内線5 {{#invoke:Phone|linkPhone|+49 123 2 567.890 内線5|isFax=true}} +49 123 2 567.890 内線5 Category:無効なフォーマットの電話番号 電話番号のフォーマットが無効です
+49 123 / 2 567.890 {{#invoke:Phone|linkPhone|+49 123 / 2 567.890}} +49 123 / 2 567.890 Category:スラッシュ付きの電話番号 電話番号にスラッシュが含まれています
++49 (123) 2 56 78 90 ext. 34 (バー) {{#invoke:Phone|linkPhone|++49 (123) 2 56 78 90 ext. 34 (バー)}} ++49 (123) 2 56 78 90 ext. 34 (バー) Category:無効なフォーマットの電話番号 電話番号のフォーマットが無効です
++49 0123 2 56 78 90 ext. 34 (バー) {{#invoke:Phone|linkPhone|++49 0123 2 56 78 90 ext. 34 (バー)|cc=+49}} ++49 0123 2 56 78 90 ext. 34 (バー) Category:無効なフォーマットの電話番号 電話番号のフォーマットが無効です
+49 (0)123 2 56 78 90;ext=34 {{#invoke:Phone|linkPhone|1=+49 (0)123 2 56 78 90;ext=34}} +49 (0)123 2 56 78 90 ext 34
+49 (123) 2 56 78 90 (バー) {{#invoke:Phone|linkPhone|+49 (123) 2 56 78 90 (バー)}} +49 (123) 2 56 78 90 (バー) Category:無効なフォーマットの電話番号 電話番号のフォーマットが無効です
+49 (0)123 VOYAGE {{#invoke:Phone|linkPhone|+''49'' (0)123 VOYAGE}} +49 (0)123 VOYAGE
(0)123 256 78 90 {{#invoke:Phone|linkPhone|(0)123 256 78 90}} (0)123 256 78 90 Category:国番号のついていない電話番号 電話番号に国番号が付いていません
(0)123 256 78 90 {{#invoke:Phone|linkPhone|(0)123 256 78 90|cc=+49}} (0)123 256 78 90
123 256 78 90 (バー) {{#invoke:Phone|linkPhone|123 256 78 90 (バー)|cc=+49}} 123 256 78 90 (バー) Category:無効なフォーマットの電話番号 電話番号のフォーマットが無効です
+49 (123) 2 56 78 90 (ロビーとバー), 0049 (123) 2 56 78 90 (オアシス・レストラン) {{#invoke:Phone|linkPhone|+49 (123) 2 56 78 90 (ロビーとバー), 0049 (123) 2 56 78 91 (Restaurant)}} +49 (123) 2 56 78 90 (ロビー Category:無効なフォーマットの電話番号 電話番号のフォーマットが無効です、バー) Category:国番号のついていない電話番号 電話番号に国番号が付いていません、0049 (123) 2 56 78 91 (Restaurant) Category:無効なフォーマットの電話番号 電話番号のフォーマットが無効です
+49 (123) 2 56 78 90 oder +49 (123) 2 56 78 91 {{#invoke:Phone|linkPhone|+49 (123) 2 56 78 90 oder +49 (123) 2 56 78 91}} +49 (123) 2 56 78 90 oder +49 (123) 2 56 78 91 Category:無効なフォーマットの電話番号 電話番号のフォーマットが無効です
(212) 307 4100 (USA) {{#invoke:Phone|linkPhone|(212) 307 4100 (USA)|cc=+1}} (212) 307 4100 (USA) Category:無効なフォーマットの電話番号 電話番号のフォーマットが無効です
+49-345-1234567 {{#invoke:Phone|linkPhone|+49-345-1234567|format=true}} +49 (0)345 123 45 67
+20-92-1234567 {{#invoke:Phone|linkPhone|+20-92-1234567|format=true|size=4}} +20 (0)92 123 4567
0800 12 34 56 (フリーダイヤル) {{#invoke:Phone|linkPhone|0800 12 34 56 (フリーダイヤル)|isTollfree=true}} 0800 12 34 56 (フリーダイヤル) Category:国番号のついていない電話番号 電話番号に国番号が付いていません
112 {{LinkPhone | phone = 112 }} テンプレート:LinkPhone
112 {{LinkPhone | phone = 112 | cc=+49}} テンプレート:LinkPhone
112 {{LinkPhone | phone = 112 (緊急通報) }} テンプレート:LinkPhone
0900 12 34 56 (有料通話) {{#invoke:Phone|linkPhone|0900 12 34 56 (有料通話)}} 0900 12 34 56 (有料通話) Category:国番号のついていない電話番号 電話番号に国番号が付いていません

使い方の例

このモジュールは通常、{{listing}} と {{phone}} から呼び出されます。そこでテンプレート自体をコード化しない限り、「文字列」と連携するのは「結果」のみです。

文字列 コード 結果
+1 234 567 890 {{#invoke:LinkPhone|LinkPhone|+1 234 567 890}} スクリプトエラー: 関数「LinkPhone」は存在しません。
+1 234-567-890 {{#invoke:LinkPhone|LinkPhone|+1 234-567-890}} スクリプトエラー: 関数「LinkPhone」は存在しません。
+1 234-567-890 内線 12 {{#invoke:LinkPhone|LinkPhone|+1 234-567-890 内線 12}} スクリプトエラー: 関数「LinkPhone」は存在しません。
+1 (234) 567 890 {{#invoke:LinkPhone|LinkPhone|+1 (234) 567 890}} スクリプトエラー: 関数「LinkPhone」は存在しません。
+1 234.567.890 {{#invoke:LinkPhone|LinkPhone|+1 234.567.890}} スクリプトエラー: 関数「LinkPhone」は存在しません。
234 567 890 {{#invoke:LinkPhone|LinkPhone|234 567 890}} スクリプトエラー: 関数「LinkPhone」は存在しません。
+1 234 567 WIKI {{#invoke:LinkPhone|LinkPhone|+1 234 567 WIKI}} スクリプトエラー: 関数「LinkPhone」は存在しません。
+44 20 7890 1234 予約、 +44 20 7890 1235 お問い合わせ {{#invoke:LinkPhone|LinkPhone|+44 20 7890 1234 予約、 +44 20 7890 1235 お問い合わせ}} スクリプトエラー: 関数「LinkPhone」は存在しません。
+44 20 7890 1234 (予約)、 +44 20 7890 1235 (お問い合わせ) {{#invoke:LinkPhone|LinkPhone|+44 20 7890 1234 (予約), +44 20 7890 1235 (お問い合わせ)}} スクリプトエラー: 関数「LinkPhone」は存在しません。
+44 20 7890 1234, +44 20 7890 1235 {{#invoke:LinkPhone|LinkPhone|+44 20 7890 1234, +44 20 7890 1235}} スクリプトエラー: 関数「LinkPhone」は存在しません。
+44 20 7890 1234 {{#invoke:LinkPhone|LinkPhone|''+44'' 20 7890 1234}} スクリプトエラー: 関数「LinkPhone」は存在しません。
+44 (0)234 567 890 {{#invoke:LinkPhone|LinkPhone|+44 (0)234 567 890}} スクリプトエラー: 関数「LinkPhone」は存在しません。
0844 123 4567 (有料通話) {{#invoke:LinkPhone|LinkPhone|0844 123 4567 (有料通話)}} スクリプトエラー: 関数「LinkPhone」は存在しません。
[email protected] (博物館とガイドツアー)、[email protected] (ロケット打ち上げ) {{#invoke:LinkPhone|LinkEmail|[email protected] (博物館とガイドツアー)、[email protected] (ロケット打ち上げ)}} スクリプトエラー: 関数「LinkEmail」は存在しません。
数字なし {{#invoke:LinkPhone|LinkPhone| }} スクリプトエラー: 関数「LinkPhone」は存在しません。

エラーの強調表示

問題のある電話番号を素早く探せるように、利用者の個人設計で "ErrorHighlighter" ガジェットを有効にします。このガジェットが有効になると、問題のある電話番号の前にとても目立つエラーメッセージが表示されます。

あるいはまた、ガジェットを使用したくない人は個別に common.css ページに次のコードを追加してください。

.phoneinfo {     color: red;     background: yellow;     display: inline !important; } 

ウィキデータでのバージョン: 2024-01-07 問題なし

使用状況

このモジュールを使用しているモジュールは以下の通りです:

-- module variable and administration local lp = { 	moduleInterface = { 		suite  = 'LinkPhone', 		serial = '2024-01-07', 		item   = 16354802 	} }  -- module import -- require( 'strict' ) local li = require( 'Module:Link utilities/i18n' ) local ln = require( 'Module:Link utilities/Phone numbers' ) local lu = require( 'Module:Link utilities' )  local function formatNumber( number, size ) 	if not li.options.formattingWikidata then 		return number 	end  	local pos, first, last, newLast, country, localCode, i  	number = number:gsub( '-', ' ' ) 	i, pos = number:find( '.* ' ) -- find last space 	if size > 0 and pos then 		first = number:sub( 1, pos ) 		last = number:sub( pos + 1, #number ) 		newLast = '' 		if tonumber( last ) then -- inserting additional spaces 			while ( #last > size + 1 ) do 				if newLast == '' then 					newLast = last:sub( -size ) 				else 					newLast = last:sub( -size ) .. ' ' .. newLast 				end 				last = last:sub( 1, #last - size ) 			end 			if newLast ~= '' then 				last = last .. ' ' .. newLast 			end 		end 		pos, i = first:find( ' ' ) 		if li.options.addZeros and pos and ( pos ~= #first ) then 			country = first:sub( 1, pos - 1 ) 			localCode = first:sub( pos + 1, #first ) 			if not ln.noZero[ country ] then 				localCode = localCode:gsub( '[%(%)]', '' ) 				if localCode:sub( 1, 1 ) == '0' then 					localCode = '(0)' .. localCode:sub( 2, #localCode )  				else 					localCode = '(0)' .. localCode 				end 				first = country .. ' ' .. localCode 			end 		end 		number = first .. last 	end 	return number end  -- look for phone-number patterns which are valid local numbers local function checkNumberMatch( key, number ) 	local ar = ln.exceptions[ key ] 	if not ar then 		return false 	end 	for i = 1, #ar, 1 do 		if number:find( ar[ i ] ) then 			return true 		end 	end 	return false end  local function extractExtension( number ) 	local ext = '' 	local t 	for i, extension in ipairs( li.extensions ) do 		t = mw.ustring.gsub( number, '^.*(' .. extension .. ')$', '%1' ) 		if t ~= number then 			ext = t:gsub( '%s*=', ' ' ) -- RFC 3966 			number = mw.ustring.gsub( number, '[%s%c]*(' .. extension .. ')$', '' ) 			break 		end 	end 	return number, ext end  -- handle a single phone number s function lp.linkPhoneNumber( s, args, isDemo ) 	local number = mw.text.trim( s ) 	if number == '' then 		return '' 	end 	local catPrefix = isDemo and ' [[:Category:' or '[[Category:'  	local ext = '' 	local extraCats = '' 	local comment, t 	args.cc = args.cc:gsub( '%-', '' )  	number, comment = lu.extractComment( number ) 	number, ext = extractExtension( number )  	-- normalize country calling code 	number = number:gsub( '^00+', '+' ) 		:gsub( '^%+%++', '+' )  	-- add country calling code, remove lead zero 	if args.cc ~= '' then 		if li.options.withCountryCode and number:sub( 1, 1 ) ~= '+' then 			number = args.cc .. ' ' .. number 		end 		if li.options.preventLeadZero and not ln.noZero[ args.cc ] then 			number = number:gsub( '^(%' .. args.cc .. '%s+)%(+0%)+', '%1' ) 				:gsub( '%(+', '' ):gsub( '%)+', '' ) 		end 	end  	-- formatting phone numbers retrieved from Wikidata 	if args.format then 		number = formatNumber( number, args.size ) 	end  	if li.options.addZeros and not ln.zeroExceptions[ args.cc ] and not number:find( '^00' ) then 		number = number:gsub( '^0', '(0)' ) 	end 	if li.options.addZeros and args.cc ~= '' and not ln.zeroExceptions[ args.cc ] then 		number = number:gsub( '^(%' .. args.cc .. ')( *)0', '%1%2(0)' ) 	end  	-- plain is number for link 	local plain = number 	-- check if slashes are used 	if plain:find( '/', 1, true ) then 		extraCats = catPrefix .. li.categories.withSlash 	end  	-- remove delimiters -.()/' and spaces 	-- including thin space 	plain = mw.ustring.gsub( plain, "[  '/%.%-%)]", '' ) 	local exception = false  	-- handling country code including ++49, 0049 etc. 	if plain:sub( 1, 1 ) == '+' then 		plain = plain:gsub( '%(0', '' ) -- zero in parenthesis 			:gsub( '%(', '' ) 	else 		plain = plain:gsub( '%(0', '0' ) 		if comment ~= '' and checkNumberMatch( 'service', comment ) then 			exception = true 			number = number:gsub( '[%(%)]', '' ) 		elseif args.isTollfree and checkNumberMatch( 'tollfree', plain ) then 			exception = true 			number = number:gsub( '[%(%)]', '' ) 		elseif checkNumberMatch( args.cc, plain ) then 			exception = true 		elseif args.cc ~= '' then 			if ln.noZero[ args.cc ] then 				plain = args.cc .. plain:gsub( '^%(', '' ) 			elseif plain:sub( 1, 1 ) == '0' then 				plain = args.cc .. plain:gsub( '^0', '' ) 			else 				return s .. catPrefix .. li.categories.invalid 			end 		else 			return s .. catPrefix .. li.categories.noCC 		end 	end  	-- minimum 5 characters including country code 	if not exception and #plain < 5 then 		return s .. catPrefix .. li.categories.invalid 	end  	-- lower case letters for numbers are not allowed 	if plain:find( '%l' ) then 		return s .. catPrefix .. li.categories.invalid 	elseif plain:find( '%u' ) then 		-- substitude letters 		local letters = { '', '[A-C]', '[D-F]', '[G-I]', '[J-L]', '[M-O]', 			'[P-S]', '[T-V]', '[W-Z]' } 		for i = 2, 9 do 			plain = plain:gsub( letters[ i ], '' .. i ) 		end 	end  	-- remove zero from local area code 	if args.cc ~= '' and not ln.zeroExceptions[ args.cc ] then 		plain = plain:gsub( args.cc .. '0', args.cc ) 	end  	-- final test 	if not exception and not plain:match( '^%+%d+$' ) then 		return s .. catPrefix .. li.categories.invalid 	end  	-- assemble number, link, ext, comment, and categories 	t = '<span data-phone="' .. plain .. '" class="listing-phone-number' 	if not args.isFax then 		t = t .. ' plainlinks nourlexpansion' 		number = ( '[tel:%s %s]' ):format( plain, number ) 	end 	if exception then 		t = t .. ' listing-phone-exception" title="' .. li.categories.onlyDomestic 	end 	t = t .. '">' .. number .. '</span>'  	return t .. ( ext ~= '' and ( ' ' .. ext ) or '' ) .. 		( comment ~= '' and ( ' ' .. comment ) or '' ) .. extraCats end  function lp.linkPhoneNumbers( args ) 	local addNum = li.addNum 	if args.isFax then 		addNum = li.addNumFax 	end 	args.cc = args.cc:gsub( '^00', '+' ):gsub( '^%+%++', '+' )  	local ns     = mw.title.getCurrentTitle().namespace 	local isDemo = ns == 10 or ns == 828  	-- split separate numbers 	local items = lu.splitItems( args.phone, li.delimiters )  	-- analyse phone numbers 	local result = '' 	local i = 0 	local s 	for j, item in ipairs( items ) do 		s = lp.linkPhoneNumber( item, args, isDemo ) 		if s ~= '' then 			if result == '' then 				result = s 			else 				if i == addNum then 					result = result .. '<span class="listing-add-contact">' 				end 				result = result .. li.texts.comma .. s 			end 			i = i + 1 		end 	end 	if i > addNum then 		result = result .. '</span>' 	end 	return result; end  function lp.getTrunkPrefix( cc ) 	return ln.noZero[ cc ] and '' or '0' end  return lp