跳转到内容

Module: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;