ವಿಷಯಕ್ಕೆ ಹೋಗು

ಮಾಡ್ಯೂಲ್:Index progress

ವಿಕಿಸೋರ್ಸ್ದಿಂದ

Documentation for this module may be created at ಮಾಡ್ಯೂಲ್:Index progress/doc

require('strict')

--[=[
This is a module to extract data from the ProofreadPage Lua API and feed it into a progress bar
]=]
local p = {} --p stands for package

local getArgs = require('Module:Arguments').getArgs
local proofreadPage = require('mw.ext.proofreadPage')
local yesno = require('Module:Yesno')
local error_message = require('Module:Error')['error']
local progress_bar = require('Module:Progress bar')._progress_bar
local progress_pie_chart = require('Module:Progress pie chart')._progress_pie_chart

--[=[
Map ProofreadPage Lua index progress to progress_bar
]=]

function p.bar(frame)
	local args = getArgs(frame)
	
	if not args or not args[1] then
		return error_message({'[[Module:Index progress]] error: no index provided'})
	end
	
	local idx = args[1]:gsub('^Index:', '')
	
	local index = proofreadPage.newIndex(idx)
	if not index then
		return error_message({'[[Module:Index progress]] error: index not found'})
	end
	
	local barArgs = {
		['total'] = index.pageCount,
		['notext'] = index:pagesWithLevel(0),
		['not_proofread'] = index:pagesWithLevel(1),
		['problematic'] = index:pagesWithLevel(2),
		['proofread'] = index:pagesWithLevel(3),
		['validated'] = index:pagesWithLevel(4),
		['height'] = args.height,
		['width'] = args.width,
		['existing_only'] = args.existing_only
	}
	
	return progress_bar(barArgs)
end

--[=[
Map ProofreadPage Lua index progress to progress_pie_chart and return the expanded template
]=]

function p.pie(frame)
	local args = getArgs(frame)
	
	if not args or not args[1] then
		return error_message({'[[Module:Index progress]] error: no index provided'})
	end
	
	local idx = args[1]:gsub('^Index:', '')
	
	local index = proofreadPage.newIndex(idx)
	if not index then
		return error_message({'[[Module:Index progress]] error: index not found'})
	end
	
	local pieArgs = {
		['total'] = index.pageCount,
		['notext'] = index:pagesWithLevel(0),
		['not_proofread'] = index:pagesWithLevel(1),
		['problematic'] = index:pagesWithLevel(2),
		['proofread'] = index:pagesWithLevel(3),
		['validated'] = index:pagesWithLevel(4),
		['existing_only'] = args.existing_only,
		['no_legend'] = args.no_legend,
		['size'] = args.size
	}
	return progress_pie_chart(pieArgs)
end

return p