Амодуль:Pagesincat

Аматериал Авикипедиа аҟынтә - зхы иақәиҭу аенциклопедиа

-- module reproducing the behavior of 0

{{PAGESINCAT}}


-- module reproducing the behavior of {{PAGESINCATEGORY}}
-- without the bug

local p = {}

-- error message
function p.error(text)
    return '<span class="error">' .. (text or "''no error indicated''") .. "</span>"
end


-- to test the "pageincategory" functionality
function p.pagesincat(frame)
    -- name of the category
    local args = frame:getParent().args
    local cat = args[1]
    -- type of order
    local arg = frame.args["ахкы"] or args["type"]
    -- formatting numbers?
    local mef = args["аформат"] or args["format"]

    local sel  -- selection

    -- if there is no category name, use current page
    if (cat == nil or cat == "") then
        local title = mw.title.getCurrentTitle()
        -- check if there is a category
        if (title.namespace ~= 14) then
            return p.error("No page name specified and current page is not a category")
        end
        -- we use the title of the current page
        cat = mw.title.getCurrentTitle().text
    end
 
    -- we look at the parameter
    if (arg == "all" or arg == nil or arg == "*") then
        sel = "all"
    elseif (arg == "cats") then
        sel = "subcats"
    elseif (arg == "афаилқәа") or (arg == "files") then
        sel = "files"
    elseif (arg == "адаҟьақәа") or (arg == "pages") then
        sel = "pages"
    else
        return p.error("parameter '" .. (arg or "<nil>") .. "' not recognized")
    end
 
    local res = mw.site.stats.pagesInCategory(cat, sel)
    if (res == nil) then
        return p.error("information retrieval error")
    end
    -- if formatting is applied
    if (mef ~= nil) then
        return mw.getContentLanguage():formatNum(res)
    else
        return tostring(res)
    end
end

return p