Jump to content

Module:PopularArticles: Difference between revisions

From Iskomunidad
No edit summary
No edit summary
Line 3: Line 3:
function p.main(frame)
function p.main(frame)


     local category = frame.args.category or "Theses"
     local pages = mw.ext.dpl.getPages{
        category = "Theses",
        ordermethod = "counter",
        order = "descending",
        count = 10
    }
 
    if not pages or #pages == 0 then
        return "No pages found."
    end


     local data = mw.ext.analytics.getViewsData({
     local output = {}
        page = "Category:" .. category
    })


     if not data then
     for i, page in ipairs(pages) do
        return "NO DATA RETURNED"
    end


    local output = {
        local title = page.prefixedText or page.title or "Unknown page"
         "Analytics test for Category:" .. category
         local counter = page.counter or 0
    }


    for key, value in pairs(data) do
         table.insert(
         table.insert(
             output,
             output,
             tostring(key) .. " = " .. tostring(value)
             string.format(
                "%d. [[%s]] — %s views",
                i,
                title,
                mw.language.getContentLanguage():formatNum(counter)
            )
         )
         )
     end
     end


     return table.concat(output, "<br>")
     return table.concat(output, "\n")
end
end


return p
return p

Revision as of 06:35, 2 October 2026

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

local p = {}

function p.main(frame)

    local pages = mw.ext.dpl.getPages{
        category = "Theses",
        ordermethod = "counter",
        order = "descending",
        count = 10
    }

    if not pages or #pages == 0 then
        return "No pages found."
    end

    local output = {}

    for i, page in ipairs(pages) do

        local title = page.prefixedText or page.title or "Unknown page"
        local counter = page.counter or 0

        table.insert(
            output,
            string.format(
                "%d. [[%s]] — %s views",
                i,
                title,
                mw.language.getContentLanguage():formatNum(counter)
            )
        )

    end

    return table.concat(output, "\n")
end

return p