Module:Pagesincat

Ka Wikipedia

Documentation for this module may be created at Module:Pagesincat/doc

-- The unit operates the same work {{PAGESINCATEGORY}}
-- But without errors

local p = {}

-- génère une erreur
function p.erreur(texte)
    return '<span class="error">' .. (texte or "''No undeclared errors''") .. "</span>"
end


-- In order to experience "pageincategory"
function p.pagesincat(frame)
    -- Category Name
    local args = frame:getParent().args
    local cat = args[1]
    -- Type of Request
    local arg = frame.args["type"] or args["type"]
    -- Create the form of the result?
    local mef = args["form"]

    local sel  -- option

    -- In the absence of the label name using the current page name
    if (cat == nil or cat == "") then
        local titre = mw.title.getCurrentTitle()
        -- Make sure it is category
        if (titre.namespace ~= 14) then
            return p.erreur("Not provide the name of the page the current page is not rated")
        end
        -- Use the title of the current page
        cat = mw.title.getCurrentTitle().text
    end
 
    -- See the data
    if (arg == "all" or arg == nil or arg == "*") then
        sel = "all"
    elseif (arg == "cats") then
        sel = "subcats"
    elseif (arg == "files") then
        sel = "files"
    elseif (arg == "pages") then
        sel = "pages"
    else
        return p.erreur("Information '" .. (arg or "<nil>") .. "' Unknown")
    end
 
    local res = mw.site.stats.pagesInCategory(cat, sel)
    if (res == nil) then
        return p.erreur("Error in data retrieval")
    end
    -- In the case of the creation of form
    if (mef ~= nil) then
        return mw.getContentLanguage():formatNum(res)
    else
        return tostring(res)
    end
end

return p