Module:redlink category

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
Text-x-generic with pencil.svg This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local export = {}

function export.cat (frame)

    local redlink_category = ""

    if pcall(mw.incrementExpensiveFunctionCount) then
        local m_languages = require("Module:languages")
        local code = frame.args[1] -- language code
        local template = frame.args["template"]

        local lang = m_languages.getByCode(frame.args[1])
        local langname = lang:getCanonicalName()
        local text = lang:makeEntryName(frame.args[2]) -- entry name (parameter 2 in Template:m, Template:l)

        local link_object = mw.title.new (text) or nil
        local link_id = link_object.id

        if link_object.id == 0 then
            redlink_category = "[[Category:" .. langname .. " redlinks]]"
            if template and template ~= "-" then
                redlink_category = redlink_category .. "[[Category:" .. langname .. " redlinks/" .. template .. "]]"
            end
        end
    end

    return redlink_category

end

return export