Módulo:LinkPhone

Icono de documentación de módulo Documentación del módulo[ver] [editar] [historial] [purgar]

Version check

Designación de la versión en Wikidata: 2024-01-07 Ok!

Uso

This module provides functions to link to phone numbers. Fax numbers are shown, but not linked. Comments must be added in brackets after the phone number.

Maintenance categories

Examples

TextCodeErgebnis
+49 123 2 567.890 App. 5{{#invoke:Phone|linkPhone|+49 123 2 567.890 App. 5}}+49 123 2 567.890 App. 5
+49 123 2 567.890 App. 5{{#invoke:Phone|linkPhone|+49 123 2 567.890 App. 5|isFax=true}}+49 123 2 567.890 App. 5
+49 123 / 2 567.890{{#invoke:Phone|linkPhone|+49 123 / 2 567.890}}+49 123 / 2 567.890 Category:Contacto: El teléfono contiene una barra (/) El teléfono contiene una barra (/)
++49 (123) 2 56 78 90 ext. 34 (Bar){{#invoke:Phone|linkPhone|++49 (123) 2 56 78 90 ext. 34 (Bar)}}+49 (123) 2 56 78 90 ext. 34 (Bar)
++49 0123 2 56 78 90 ext. 34 (Bar){{#invoke:Phone|linkPhone|++49 0123 2 56 78 90 ext. 34 (Bar)|cc=+49}}+49 (0)123 2 56 78 90 ext. 34 (Bar)
+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 Bar{{#invoke:Phone|linkPhone|+49 (123) 2 56 78 90 Bar}}+49 (123) 2 56 78 90 Bar Category:Contacto: Formato de teléfono inválido Formato de teléfono inválido
+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:Contacto: Teléfono sin código númerico del país Teléfono sin código númerico del país
(0)123 256 78 90{{#invoke:Phone|linkPhone|(0)123 256 78 90|cc=+49}}(0)123 256 78 90
123 256 78 90 (Bar){{#invoke:Phone|linkPhone|123 256 78 90 (Bar)|cc=+49}}123 256 78 90 (Bar) Category:Contacto: Formato de teléfono inválido Formato de teléfono inválido
+49 (123) 2 56 78 90 (Lobby Bar), 0049 (123) 2 56 78 90 (Oasis Restaurant){{#invoke:Phone|linkPhone|+49 (123) 2 56 78 90 (Vestíbulo y bar), 0049 (123) 2 56 78 91 (Restaurante)}}+49 (123) 2 56 78 90 (Vestíbulo y bar), +49 (123) 2 56 78 91 (Restaurante)
+49 (123) 2 56 78 90 oder +49 (123) 2 56 78 91{{#invoke:Phone|linkPhone|+49 (123) 2 56 78 90 y +49 (123) 2 56 78 91}}+49 (123) 2 56 78 90, +49 (123) 2 56 78 91
(212) 307 4100 (USA){{#invoke:Phone|linkPhone|(212) 307 4100 (USA)|cc=+1}}(212) 307 4100 (USA)
+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 (gebührenfrei){{#invoke:Phone|linkPhone|0800 12 34 56 (gratis)|isTollfree=true}}0800 12 34 56 (gratis )
112{{#invoke:Phone|linkPhone| 112 }}112 Category:Contacto: Teléfono sin código númerico del país Teléfono sin código númerico del país
112{{#invoke:Phone|linkPhone| 112 | cc=+49}}112
112{{#invoke:Phone|linkPhone| 112 (Emergencia) }}112 (Emergencia) Category:Contacto: Teléfono sin código númerico del país Teléfono sin código númerico del país
0900 12 34 56 (teure Servicenummer){{#invoke:Phone|linkPhone|0900 12 34 56 (Número de servicio caro)}}0900 12 34 56 (Número de servicio caro) Category:Contacto: Teléfono sin código númerico del país Teléfono sin código númerico del país
Esta documentación está transcluida desde Módulo:LinkPhone/doc.
Los editores pueden experimentar en la zona de pruebas (crear) y en los casos de prueba (crear) del módulo.
Por favor, añade las categorías en la subpágina de documentación. Subpáginas de este módulo.

-- module variable and administrationlocal 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 thenreturn numberendlocal pos, first, last, newLast, country, localCode, inumber = number:gsub( '-', ' ' )i, pos = number:find( '.* ' ) -- find last spaceif size > 0 and pos thenfirst = number:sub( 1, pos )last = number:sub( pos + 1, #number )newLast = ''if tonumber( last ) then -- inserting additional spaceswhile ( #last > size + 1 ) doif newLast == '' thennewLast = last:sub( -size )elsenewLast = last:sub( -size ) .. ' ' .. newLastendlast = last:sub( 1, #last - size )endif newLast ~= '' thenlast = last .. ' ' .. newLastendendpos, i = first:find( ' ' )if li.options.addZeros and pos and ( pos ~= #first ) thencountry = first:sub( 1, pos - 1 )localCode = first:sub( pos + 1, #first )if not ln.noZero[ country ] thenlocalCode = localCode:gsub( '[%(%)]', '' )if localCode:sub( 1, 1 ) == '0' thenlocalCode = '(0)' .. localCode:sub( 2, #localCode ) elselocalCode = '(0)' .. localCodeendfirst = country .. ' ' .. localCodeendendnumber = first .. lastendreturn numberend-- look for phone-number patterns which are valid local numberslocal function checkNumberMatch( key, number )local ar = ln.exceptions[ key ]if not ar thenreturn falseendfor i = 1, #ar, 1 doif number:find( ar[ i ] ) thenreturn trueendendreturn falseendlocal function extractExtension( number )local ext = ''local tfor i, extension in ipairs( li.extensions ) dot = mw.ustring.gsub( number, '^.*(' .. extension .. ')$', '%1' )if t ~= number thenext = t:gsub( '%s*=', ' ' ) -- RFC 3966number = mw.ustring.gsub( number, '[%s%c]*(' .. extension .. ')$', '' )breakendendreturn number, extend-- handle a single phone number sfunction lp.linkPhoneNumber( s, args, isDemo )local number = mw.text.trim( s )if number == '' thenreturn ''endlocal catPrefix = isDemo and ' [[:Category:' or '[[Category:'local ext = ''local extraCats = ''local comment, targs.cc = args.cc:gsub( '%-', '' )number, comment = lu.extractComment( number )number, ext = extractExtension( number )-- normalize country calling codenumber = number:gsub( '^00+', '+' ):gsub( '^%+%++', '+' )-- add country calling code, remove lead zeroif args.cc ~= '' thenif li.options.withCountryCode and number:sub( 1, 1 ) ~= '+' thennumber = args.cc .. ' ' .. numberendif li.options.preventLeadZero and not ln.noZero[ args.cc ] thennumber = number:gsub( '^(%' .. args.cc .. '%s+)%(+0%)+', '%1' ):gsub( '%(+', '' ):gsub( '%)+', '' )endend-- formatting phone numbers retrieved from Wikidataif args.format thennumber = formatNumber( number, args.size )endif li.options.addZeros and not ln.zeroExceptions[ args.cc ] and not number:find( '^00' ) thennumber = number:gsub( '^0', '(0)' )endif li.options.addZeros and args.cc ~= '' and not ln.zeroExceptions[ args.cc ] thennumber = number:gsub( '^(%' .. args.cc .. ')( *)0', '%1%2(0)' )end-- plain is number for linklocal plain = number-- check if slashes are usedif plain:find( '/', 1, true ) thenextraCats = catPrefix .. li.categories.withSlashend-- remove delimiters -.()/' and spaces-- including thin spaceplain = mw.ustring.gsub( plain, "[  '/%.%-%)]", '' )local exception = false-- handling country code including ++49, 0049 etc.if plain:sub( 1, 1 ) == '+' thenplain = plain:gsub( '%(0', '' ) -- zero in parenthesis:gsub( '%(', '' )elseplain = plain:gsub( '%(0', '0' )if comment ~= '' and checkNumberMatch( 'service', comment ) thenexception = truenumber = number:gsub( '[%(%)]', '' )elseif args.isTollfree and checkNumberMatch( 'tollfree', plain ) thenexception = truenumber = number:gsub( '[%(%)]', '' )elseif checkNumberMatch( args.cc, plain ) thenexception = trueelseif args.cc ~= '' thenif ln.noZero[ args.cc ] thenplain = args.cc .. plain:gsub( '^%(', '' )elseif plain:sub( 1, 1 ) == '0' thenplain = args.cc .. plain:gsub( '^0', '' )elsereturn s .. catPrefix .. li.categories.invalidendelsereturn s .. catPrefix .. li.categories.noCCendend-- minimum 5 characters including country codeif not exception and #plain < 5 thenreturn s .. catPrefix .. li.categories.invalidend-- lower case letters for numbers are not allowedif plain:find( '%l' ) thenreturn s .. catPrefix .. li.categories.invalidelseif plain:find( '%u' ) then-- substitude letterslocal letters = { '', '[A-C]', '[D-F]', '[G-I]', '[J-L]', '[M-O]','[P-S]', '[T-V]', '[W-Z]' }for i = 2, 9 doplain = plain:gsub( letters[ i ], '' .. i )endend-- remove zero from local area codeif args.cc ~= '' and not ln.zeroExceptions[ args.cc ] thenplain = plain:gsub( args.cc .. '0', args.cc )end-- final testif not exception and not plain:match( '^%+%d+$' ) thenreturn s .. catPrefix .. li.categories.invalidend-- assemble number, link, ext, comment, and categoriest = '<span data-phone="' .. plain .. '" class="listing-phone-number'if not args.isFax thent = t .. ' plainlinks nourlexpansion'number = ( '[tel:%s %s]' ):format( plain, number )endif exception thent = t .. ' listing-phone-exception" title="' .. li.categories.onlyDomesticendt = t .. '">' .. number .. '</span>'return t .. ( ext ~= '' and ( ' ' .. ext ) or '' ) ..( comment ~= '' and ( ' ' .. comment ) or '' ) .. extraCatsendfunction lp.linkPhoneNumbers( args )local addNum = li.addNumif args.isFax thenaddNum = li.addNumFaxendargs.cc = args.cc:gsub( '^00', '+' ):gsub( '^%+%++', '+' )local ns     = mw.title.getCurrentTitle().namespacelocal isDemo = ns == 10 or ns == 828-- split separate numberslocal items = lu.splitItems( args.phone, li.delimiters )-- analyse phone numberslocal result = ''local i = 0local sfor j, item in ipairs( items ) dos = lp.linkPhoneNumber( item, args, isDemo )if s ~= '' thenif result == '' thenresult = selseif i == addNum thenresult = result .. '<span class="listing-add-contact">'endresult = result .. li.texts.comma .. sendi = i + 1endendif i > addNum thenresult = result .. '</span>'endreturn result;endfunction lp.getTrunkPrefix( cc )return ln.noZero[ cc ] and '' or '0'endreturn lp