Module:Database reports/Hot articles by category
Jump to navigation
Jump to search
This module triggers generation of a list of "hot" (most edited) articles from a given category. This supersedes lists created by User:HotArticlesBot.
Usage
[edit source]{{Database report
| lua_source = Module:Database reports/Hot articles by category
| lua_arg_category = <!-- Name of the talk page category -->
| lua_arg_articles = 10 <!-- Number of hot articles to list -->
| lua_arg_days = 7 <!-- Number of days to count edits from (1–30) -->
| lua_arg_orange = 15 <!-- Number of edits required to hit the orange threshold -->
| lua_arg_red = 30 <!-- Number of edits required to hit the red threshold -->
| silent = <!-- Set to yes (or any value) to suppress the boilerplate text. Note this also suppresses the update link. -->
}}
{{Database report end}}
See also
[edit source]- Module:Database reports/Hot articles – by WikiProject instead of category
local Report = require('Module:Database report')
local Arguments = require('Module:Arguments')
local p = {}
p.main = function(frame)
local args = Arguments.getArgs(frame)
local report = Report:new()
local category = args.category and args.category:gsub(' ', '_')
local articles = args.articles or '10'
local days = args.days or '7'
local red = args.red or '30'
local orange = args.orange or '15'
if category == nil then
return invalid('|category= parameter is required')
end
if tonumber(articles) == nil or tonumber(articles) < 1 then
return invalid('articles must be a number >= 1')
end
if tonumber(days) == nil or tonumber(days) < 1 or tonumber(days) > 30 then
return invalid('days must be between 1 and 30')
end
if tonumber(red) == nil or tonumber(red) < 1 then
return invalid('red: threshold must be a number >= 1')
end
if tonumber(orange) == nil or tonumber(orange) < 1 then
return invalid('orange: threshold must be a number >= 1')
end
report:setSQL([[
WITH hotarticles_presort AS (
WITH incategoryarticleedits AS (
SELECT main.page_title AS Article, rev_id
FROM linktarget
JOIN categorylinks on cl_target_id = lt_id
JOIN page AS talk ON talk.page_id = cl_from AND talk.page_namespace = 1
JOIN page AS main ON main.page_namespace = 0 AND main.page_title = talk.page_title
JOIN revision ON rev_page = main.page_id
WHERE lt_namespace = 14
AND lt_title = ']]..category..[['
AND rev_timestamp >= DATE_SUB(NOW(), INTERVAL ]]..days..[[ DAY)
)
SELECT COUNT(*) AS Edits, Article
FROM incategoryarticleedits
GROUP BY Article
ORDER BY Edits DESC
FETCH FIRST ]]..articles ..[[ ROWS WITH TIES
)
SELECT
Edits,
Article,
ROW_NUMBER() OVER(ORDER BY Edits DESC, Article ASC) AS Row,
IF(EDITS > ]]..red..[[, 'c60d27', IF(EDITS > ]]..orange..[[, 'f75a0d', 'ff9900')) AS Color
FROM hotarticles_presort
ORDER BY Edits DESC, Article ASC
]])
report:useWikilinks(2)
report:setWidth(3, '3em')
report:setTableStyle('overflow-wrap: anywhere; border-width: 0; border-collapse: separate; border-spacing: 0 1px')
report:setTableClass('wikitable')
report:setInterval(1)
report:setHeaderTemplate('Hot articles by category header')
report:setRowTemplate('Hot articles by category row')
report:useNamedParamsInRowTemplate(true)
return report:generate()
end
function invalid(text)
return require('Module:Error').error{ 'Invalid configuration: '.. text, tag = 'p' }
end
return p