
Questo è un modulo scritto in Lua. Le istruzioni che seguono sono contenute nella sottopagina Modulo:LinkPhone/man (modifica · cronologia)
Sandbox: Modulo:LinkPhone/sandbox (modifica · cronologia) · Test: Modulo:LinkPhone/test (modifica · cronologia · Esegui)
Esempi d'uso
Testo | Codice | Risultato |
---|---|---|
Esempi corretti | ||
+1 234 567 890 | {{#invoke:LinkPhone|LinkPhone|+1 234 567 890}} | +1 234 567 890 |
+1 234-567-890 | {{#invoke:LinkPhone|LinkPhone|+1 234-567-890}} | +1 234-567-890 |
+1 234-567-890 ext 12 | {{#invoke:LinkPhone|LinkPhone|+1 234-567-890 ext 12}} | +1 234-567-890 ext 12 |
+1 (234) 567 890 | {{#invoke:LinkPhone|LinkPhone|+1 (234) 567 890}} | +1 (234) 567 890 |
+1 234 567 WIKI | {{#invoke:LinkPhone|LinkPhone|+1 234 567 WIKI}} | +1 234 567 WIKI (9454) |
+44 20 7890 1234 (prenotazioni), +44 20 7890 1235 (informazioni) | {{#invoke:LinkPhone|LinkPhone|+44 20 7890 1234 (prenotazioni), +44 20 7890 1235 (informazioni)}} | +44 20 7890 1234 (prenotazioni), +44 20 7890 1235 (informazioni) |
+44 20 7890 1234, +44 20 7890 1235 | {{#invoke:LinkPhone|LinkPhone|+44 20 7890 1234, +44 20 7890 1235}} | +44 20 7890 1234, +44 20 7890 1235 |
+44 20 7890 1234 | {{#invoke:LinkPhone|LinkPhone|''+44'' 20 7890 1234}} | +44 20 7890 1234 |
[email protected] (museo e tour), [email protected] (lancio razzi) | {{#invoke:LinkPhone|LinkEmail|[email protected] (museo e tour), [email protected] (lancio razzi)}} | [email protected] (museo e tour), [email protected] (lancio razzi) |
blank | {{#invoke:LinkPhone|LinkPhone| }} | |
Esempi errati | ||
234 567 890 | {{#invoke:LinkPhone|LinkPhone|234 567 890}} | 234 567 890Categoria:Listing con telefoni privi di prefisso nazionale |
+1 234.567.890 | {{#invoke:LinkPhone|LinkPhone|+1 234.567.890}} | +1 234.567.890Categoria:Listing con telefoni con problemi di formato |
+44 20 7890 1234 prenotazioni, +44 20 7890 1235 informazioni | {{#invoke:LinkPhone|LinkPhone|+44 20 7890 1234 prenotazioni, +44 20 7890 1235 informazioni}} | +44 20 7890 1234 prenotazioniCategoria:Listing con telefoni con problemi di formato , +44 20 7890 1235 informazioniCategoria:Listing con telefoni con problemi di formato |
+44 (0)234 567 890 | {{#invoke:LinkPhone|LinkPhone|+44 (0)234 567 890}} | +44 (0)234 567 890Categoria:Listing con telefoni con problemi di formato |
info at wikivoyage.org | {{#invoke:LinkPhone|LinkEmail|info at wikivoyage.org}} | infoatwikivoyage.orgCategoria:Listing con email con problemi di formato |
Debugging
Per rendere più facile vedere eventuali problemi con i numeri di telefono, è possibile attivare nelle proprie preferenze l'accessorio Phoneinfo.
Oppure Debuginfo per vedere anche altre tipologie di informazioni errate.
local p = {} function p.LinkOnePhone(txt, demo, fax, tollfree) local link = txt local othertxt = "" local catprefix = demo == 'true' and ':' or '' local catMissingCountryCode = '' local catFormatIssue = '' local output -- any other text in brackets at the end is stored separately and ignored for the dialing number if mw.ustring.gsub(txt, "(.*)( %(.*%))$", "%2") ~= txt then othertxt = mw.ustring.gsub(txt, "(.*)( %(.*%))$", "%2") txt = mw.ustring.gsub(txt, "(.*)( %(.*%))$", "%1") end -- Don't include "ext NNNN" in the link link = mw.ustring.gsub(txt, " +[Ee][Xx][Tt] +%d+$", "") -- Don't include " xNNNN" in the link link = mw.ustring.gsub(link, " +x%d+$", "") link = mw.ustring.gsub(link, " ", "") link = mw.ustring.gsub(link, "'", "") if link == "" then return "" end if mw.ustring.sub(link, 1, 1) ~= '+' and mw.ustring.len(link) > 4 then if tollfree == 'yes' and ( mw.ustring.sub(link, 1, 3) == '800' or mw.ustring.sub(link, 1, 3) == '803' or mw.ustring.sub(link, 1, 3) == '840' or mw.ustring.sub(link, 1, 3) == '892' or mw.ustring.sub(link, 1, 3) == '199' or mw.ustring.sub(link, 1, 3) == '848' or mw.ustring.sub(link, 1, 4) == '1800' or mw.ustring.sub(link, 1, 5) == '1 800' or mw.ustring.sub(link, 1, 5) == '1-800' or mw.ustring.sub(link, 1, 4) == '1888' or mw.ustring.sub(link, 1, 5) == '1 888' or mw.ustring.sub(link, 1, 5) == '1-888' ) then --Alcune numerazioni speciali non prevedono il prefisso nazionale. Questa patch può essere migliorata per restringere le casistiche local htmlTel = fax == 'true' and txt or ('[tel:' .. link .. ' ' .. txt .. ']') output = '<span class="plainlinks nourlexpansion">' .. htmlTel .. '</span>' .. othertxt else catMissingCountryCode = '[[' .. catprefix .. 'Categoria:Listing con telefoni privi di prefisso nazionale]]<span class="phoneinfo debuginfo" style="display:none;">PREFISSO MANCANTE</span>' end end if mw.ustring.match(link,"^%+[%d-() ]+$") ~= nil then local htmlTel = fax == 'true' and txt or ('[tel:' .. link .. ' ' .. txt .. ']') output = '<span class="plainlinks nourlexpansion">' .. htmlTel .. '</span>' .. othertxt elseif mw.ustring.match(link,"^%+[%d%u- ]+$") ~= nil then local extra = mw.ustring.match(link, "%u[%d%u- ]+") link = mw.ustring.gsub(link, "[A-C]", "2") link = mw.ustring.gsub(link, "[D-F]", "3") link = mw.ustring.gsub(link, "[G-I]", "4") link = mw.ustring.gsub(link, "[J-L]", "5") link = mw.ustring.gsub(link, "[M-O]", "6") link = mw.ustring.gsub(link, "[P-S]", "7") link = mw.ustring.gsub(link, "[T-V]", "8") link = mw.ustring.gsub(link, "[W-Z]", "9") extra = mw.ustring.gsub(extra, "[A-C]", "2") extra = mw.ustring.gsub(extra, "[D-F]", "3") extra = mw.ustring.gsub(extra, "[G-I]", "4") extra = mw.ustring.gsub(extra, "[J-L]", "5") extra = mw.ustring.gsub(extra, "[M-O]", "6") extra = mw.ustring.gsub(extra, "[P-S]", "7") extra = mw.ustring.gsub(extra, "[T-V]", "8") extra = mw.ustring.gsub(extra, "[W-Z]", "9") local htmlTel = fax == 'true' and (' (' .. extra .. ')') or ('[tel:' .. link .. ' ' .. txt .. ' (' .. extra .. ')' .. ']') output = '<span class="plainlinks nourlexpansion">' .. htmlTel .. '</span>' .. othertxt else output = txt .. othertxt if mw.ustring.match('+' .. link,"^%+[%d-() ]+$") == nil then catFormatIssue = '[[' .. catprefix .. 'Categoria:Listing con telefoni con problemi di formato]]<span class="phoneinfo debuginfo" style="display:none;">FORMATO</span>' end end if mw.ustring.match(link,"%(0%)") ~= nil then catFormatIssue = '[[' .. catprefix .. 'Categoria:Listing con telefoni con problemi di formato]]<span class="phoneinfo debuginfo" style="display:none;">FORMATO</span>' end if mw.title.getCurrentTitle().namespace == 0 or demo == 'true' then output = output .. catFormatIssue .. catMissingCountryCode end return output end function p.LinkPhone(frame) local demo = frame.args["demo"] or '' local fax = frame.args["fax"] or '' local txtall = frame.args[1] or '' .. ',' local tollfree = frame.args["tollfree"] or '' local txt = "" local result = "" -- replace or / and with comma txtall = mw.ustring.gsub(txtall, " or %+", ", +") txtall = mw.ustring.gsub(txtall, " and %+", ", +") for txt in mw.ustring.gmatch(txtall, "([^,]+)") do result = result .. ", " .. p.LinkOnePhone(txt, demo, fax, tollfree) end result = mw.ustring.sub(result, 3, mw.ustring.len(result) ) return result end function p.LinkOneEmail(txt, demo) local othertxt = "" local catprefix = '' local catFormatIssue = '' local output if demo == 'true' then catprefix = ':' end -- any other text in brackets at the end is stored separately and ignored for the dialing number if mw.ustring.gsub(txt, "(.*)( %(.*%))$", "%2") ~= txt then othertxt = mw.ustring.gsub(txt, "(.*)( %(.*%))$", "%2") or '' txt = mw.ustring.gsub(txt, "(.*)( %(.*%))$", "%1") or '' end txt = mw.ustring.gsub(txt, " ", "") output = '[mailto:' .. txt .. ' ' .. txt .. ']' .. othertxt if mw.ustring.match(txt,"@.+@") or mw.ustring.match(txt,"@[^.]+%.%.") or mw.ustring.match(txt,"@") == nil or mw.ustring.match(txt,"@[^.]+%.[^.]+") == nil then catFormatIssue = '[[' .. catprefix .. 'Categoria:Listing con email con problemi di formato]]<span class="phoneinfo debuginfo" style="display:none;" title="Email has formatting issue">FORMATO</span>' end if mw.title.getCurrentTitle().namespace == 0 or demo == 'true' then output = output .. catFormatIssue end return output end function p.LinkEmail(frame) local demo = frame.args["demo"] or '' local txtall = frame.args[1] or '' .. ',' local txt = "" local result = "" -- replace semicolon with comma txtall = mw.ustring.gsub(txtall, "; ", ", ") for txt in mw.ustring.gmatch(txtall, "([^,]+)") do result = result .. ", " .. p.LinkOneEmail(txt, demo) end result = mw.ustring.sub(result, 3, mw.ustring.len(result) ) return result end return p