🇮🇷 Iran Proxy | https://www.wikipedia.org/wiki/Module:Database_reports/Hot_articles
Jump to content

Module:Database reports/Hot articles

From Wikipedia, the free encyclopedia

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 project = args.project
	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 project == nil then
		return invalid('|project= parameter is unspecified')	
	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 inprojectarticleedits AS (
				SELECT *
				FROM page_assessments_projects
				JOIN page_assessments ON pa_project_id = pap_project_id AND pa_class NOT IN ('Disambig', 'Redirect')
				JOIN revision ON rev_page = pa_page_id AND rev_timestamp > (NOW() - INTERVAL ]]..days..[[ DAY)
				JOIN page ON page_id = rev_page AND page_namespace = 0
				WHERE pap_project_title = ']]..project..[['
			)
			SELECT COUNT(*) AS Edits, page_title AS Article, pa_class AS Rating
			FROM inprojectarticleedits
			GROUP BY page_title
			ORDER BY Edits DESC
			FETCH FIRST ]]..articles ..[[ ROWS WITH TIES
		)
		SELECT *, 
			ROW_NUMBER() OVER(ORDER BY Edits DESC, Article ASC) AS RowNum, 
			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(1, '3em')
	report:setWidth(3, '4em')
	report:setTableStyle('overflow-wrap: anywhere; border-width: 0; border-collapse: separate; border-spacing: 0 1px')
	report:setTableClass('wikitable')
	report:setInterval(1)
	report:setRowTemplate('Hot articles report row')
	report:setHeaderTemplate('Hot articles report header')

	return report:generate()
end 

function invalid(text)
	return require('Module:Error').error{ 'Invalid configuration: '.. text, tag = 'p' }
end

return p