Module:PopularArticles: Difference between revisions
Appearance
Created page with "local p = {} -- Get total views for a page local function getViews(pageName) local data = mw.ext.analytics.getViewsData({ page = pageName }) if not data then return 0 end local total = 0 for _, views in pairs(data) do total = total + tonumber(views) or 0 end return total end -- Get pages in a category local function getCategoryPages(categoryName) local category = mw.title.new("Category:" .. categoryName)..." |
No edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function p.main(frame) | function p.main(frame) | ||
local | local pages = mw.ext.dpl.getPages{ | ||
category = "Theses", | |||
ordermethod = "counter", | |||
order = "descending", | |||
count = 1 | |||
} | |||
if not pages or #pages == 0 then | |||
return "No pages found." | |||
end | end | ||
local output = {} | 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 | |||
local | |||
table.insert( | table.insert( | ||
output, | output, | ||
string.format( | string.format( | ||
"%d. [[%s]] — %s views", | |||
i, | |||
mw. | title, | ||
mw.language.getContentLanguage():formatNum(counter) | |||
) | ) | ||
) | ) | ||
end | end | ||
return table.concat(output, "\n") | return table.concat(output, "\n") | ||
Latest revision as of 06:36, 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 = 1
}
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