Module:Wy/ko/LinkPhone

From Wikimedia Incubator

예시[edit source]

Text Code Result
+1 234 567 890 {{#invoke:Wy/ko/LinkPhone|LinkPhone|+1 234 567 890}} +1 234 567 890
+1 234-567-890 {{#invoke:Wy/ko/LinkPhone|LinkPhone|+1 234-567-890}} +1 234-567-890
+1 234-567-890 ext 12 {{#invoke:Wy/ko/LinkPhone|LinkPhone|+1 234-567-890 ext 12}} +1 234-567-890 ext 12
+1 (234) 567 890 {{#invoke:Wy/ko/LinkPhone|LinkPhone|+1 (234) 567 890}} +1 (234) 567 890
+1 234.567.890 {{#invoke:Wy/ko/LinkPhone|LinkPhone|+1 234.567.890}} +1 234.567.890Category:Listing with phone format issue
234 567 890 {{#invoke:Wy/ko/LinkPhone|LinkPhone|234 567 890}} 234 567 890Category:Listing with phone missing country code
+1 234 567 WIKI {{#invoke:Wy/ko/LinkPhone|LinkPhone|+1 234 567 WIKI}} +1 234 567 WIKI (9454)
+44 20 7890 1234 reservations, +44 20 7890 1235 general enquiries {{#invoke:Wy/ko/LinkPhone|LinkPhone|+44 20 7890 1234 reservations, +44 20 7890 1235 general enquiries}} +44 20 7890 1234 reservationsCategory:Listing with phone format issue, +44 20 7890 1235 general enquiriesCategory:Listing with phone format issue
+44 20 7890 1234 (reservations), +44 20 7890 1235 (general enquiries) {{#invoke:Wy/ko/LinkPhone|LinkPhone|+44 20 7890 1234 (reservations), +44 20 7890 1235 (general enquiries)}} +44 20 7890 1234 (reservations), +44 20 7890 1235 (general enquiries)
+44 20 7890 1234, +44 20 7890 1235 {{#invoke:Wy/ko/LinkPhone|LinkPhone|+44 20 7890 1234, +44 20 7890 1235}} +44 20 7890 1234, +44 20 7890 1235
+44 20 7890 1234 {{#invoke:Wy/ko/LinkPhone|LinkPhone|''+44'' 20 7890 1234}} +44 20 7890 1234
+44 (0)234 567 890 {{#invoke:Wy/ko/LinkPhone|LinkPhone|+44 (0)234 567 890}} +44 (0)234 567 890Category:Listing with phone format issue
0844 123 4567 (high cost) {{#invoke:Wy/ko/LinkPhone|LinkPhone|0844 123 4567 (high cost)}} 0844 123 4567 (high cost)
blank {{#invoke:Wy/ko/LinkPhone|LinkPhone| }}

Highlighting issues[edit source]

To make it easier to see any issues with the phone numbers, you can add the following to your own common.css page.

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

local i = {}
 
function i.LinkOnePhone(txt, demo, tollfree)
    local link = txt;
    local othertxt = "";
    local catprefix = '';
    local catMissingCountryCode = '';
    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, "(.*)( %([^0-9]*%))$", "%2") ~= txt then
        othertxt = mw.ustring.gsub(txt, "(.*)( %([^0-9]*%))$", "%2");
        txt = mw.ustring.gsub(txt, "(.*)( %([^0-9]*%))$", "%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
    	catMissingCountryCode = '[[' .. catprefix .. 'Category:Listing with phone missing country code]]<span class="phoneinfo" style="display:none;">NOCC</span>';
        if tollfree == 'yes' and mw.ustring.sub(link, 1, 4) == '0508' then
           catMissingCountryCode = '';
        end
        if tollfree == 'yes' and mw.ustring.sub(link, 1, 4) == '0800' then
           catMissingCountryCode = '';
        end
        if tollfree == 'yes' and mw.ustring.sub(link, 1, 4) == '1300' then
           catMissingCountryCode = '';
        end
        if tollfree == 'yes' and mw.ustring.sub(link, 1, 4) == '1800' then
           catMissingCountryCode = '';
        end
        if mw.ustring.match(mw.ustring.lower(othertxt),"high cost") ~= nil then
           catMissingCountryCode = '';
        end
        if mw.ustring.match(mw.ustring.lower(othertxt),"extra charge") ~= nil then
           catMissingCountryCode = '';
        end
        if mw.ustring.match(mw.ustring.lower(othertxt),"premium") ~= nil then
           catMissingCountryCode = '';
        end
        if mw.ustring.match(mw.ustring.lower(othertxt),"local rate") ~= nil then
           catMissingCountryCode = '';
        end
    end
    if mw.ustring.match(link,"^%+[%d-() ]+$") ~= nil then
        output = '<span class="plainlinks nourlexpansion">[tel:' .. link .. ' ' .. txt .. ']</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");
        output = '<span class="plainlinks nourlexpansion">[tel:' .. link .. ' ' .. txt .. ' (' .. extra .. ')' ..']</span>' .. othertxt;
    else
        output = txt .. othertxt;
        if mw.ustring.match('+' .. link,"^%+[%d-() ]+$") == nil then
            catFormatIssue = '[[' .. catprefix .. 'Category:Listing with phone format issue]]<span class="phoneinfo" style="display:none;">FORMAT</span>';
        end
    end
    if mw.ustring.match(link,"%(0%)") ~= nil then
        catFormatIssue = '[[' .. catprefix .. 'Category:Listing with phone format issue]]<span class="phoneinfo" style="display:none;">FORMAT</span>';
    end
    if mw.title.getCurrentTitle().namespace == 0 or demo == 'true' then
        output = output .. catFormatIssue .. catMissingCountryCode;
    end
    return output;
end

function i.LinkPhone(frame)
    local demo = frame.args["demo"] or '';
    local txtall = frame.args[1] or '' .. ',';
    local tollfree = frame.args["tollfree"] or '';
    local txt = "";
    local result = "";
    local catprefix = '';
    -- 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 .. ", " .. i.LinkOnePhone(txt, demo, tollfree)
    end
    result = mw.ustring.sub(result, 3, mw.ustring.len(result) );
    return result;
end 
return i;