Module:LinkPhone
外观
Example Usage
Text | Code | Result |
---|---|---|
+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 | {{#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.890Category:格式有问题的电话 |
234 567 890 | {{#invoke:LinkPhone|LinkPhone|234 567 890}} | 234 567 890Category:缺失国家代码的电话 |
+1 234 567 WIKI | {{#invoke:LinkPhone|LinkPhone|+1 234 567 WIKI}} | +1 234 567 WIKICategory:格式有问题的电话 |
+44 20 7890 1234 reservations, +44 20 7890 1235 general enquiries | {{#invoke:LinkPhone|LinkPhone|+44 20 7890 1234 reservations, +44 20 7890 1235 general enquiries}} | +44 20 7890 1234 reservations, +44 20 7890 1235 general enquiriesCategory:格式有问题的电话 |
+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 1235Category:格式有问题的电话 |
+44 20 7890 1234 | {{#invoke:LinkPhone|LinkPhone|''+44'' 20 7890 1234}} | +44 20 7890 1234 |
+44 (0)234 567 890 | {{#invoke:LinkPhone|LinkPhone|+44 (0)234 567 890}} | +44 (0)234 567 890Category:格式有问题的电话 |
空白 | {{#invoke:LinkPhone|LinkPhone| }} |
local i = {}
function i.LinkPhone(frame)
local demo = frame.args["demo"] or '';
local txt = frame.args[1] or '';
local link = txt;
local catprefix = '';
local catMissingCountryCode = '';
local catFormatIssue = '';
local output;
if demo == 'true' then
catprefix = ':';
end
link = mw.ustring.gsub(txt, ' ', '');
link = mw.ustring.gsub(link, "'", "");
if link == "" then
return "";
end
if mw.ustring.sub(link, 1, 1) ~= '+' then
catMissingCountryCode = '[[' .. catprefix .. 'Category:缺失国家代码的电话]]'
end
if mw.ustring.match(link,"^%+[%d-() ]+$") ~= nil then
output = '<span class="plainlinks nourlexpansion">[tel:' .. link .. ' ' .. txt ..']</span>';
else
output = txt;
if mw.ustring.match('+' .. link,"^%+[%d-() ]+$") == nil then
catFormatIssue = '[[' .. catprefix .. 'Category:格式有问题的电话]]'
end
end
if mw.ustring.match(link,"%(0%)") ~= nil then
catFormatIssue = '[[' .. catprefix .. 'Category:格式有问题的电话]]'
end
-- Note the quote ("") below is not empty and actually contains a hidden unicode character.
-- if mw.ustring.match(link,"") ~= nil then
-- catFormatIssue = '[[' .. catprefix .. 'Category:Listing with hidden unicode character]]'
-- end
if catFormatIssue ~= '' then
output = txt;
end
return output .. catFormatIssue.. catMissingCountryCode;
end
return i;