Jump to content
Discussions

Module:Feedback

From Deltarune Wiki

Handles storing article feedback into a bucket, displaying the feedback list, and buttons for resolving the feedback.

Documentation

Package items

feedback.store(frame) (function)
Stores feedback into a bucket and creates a button.
Parameter: frame Scribunto frame object (table)
Returns: Feedback text prefixed with a resolution button (string)
See also: Template:Feedback
feedback.list() (function)
Creates a table with all unresolved feedback.
Returns: Table HTML (string)
See also: Project:Feedback
feedback.count() (function)
Counts the amount of all, resolved and unresolved feedback.
Returns: Formatted count and percentage from all (string)
See also: Project:Feedback

See also

Project:Feedback

--- Handles storing article feedback into a bucket, displaying the feedback
--  list, and buttons for resolving the feedback.
--  @module             feedback
--  @require            Module:Yesno
--  @require            Module:Date
--  @author             [[User:KockaAdmiralac|KockaAdmiralac]]
--  @see                [[Project:Feedback]]
--  <nowiki>
local feedback = {}

require('strict')

--  Module dependencies
local bucket = mw.ext.bucket

--- Stores feedback into a bucket and creates a button.
--  @function           feedback.store
--  @param              {table} frame Scribunto frame object
--  @return             {string} Feedback text prefixed with a resolution button
--  @see                [[Template:Feedback]]
function feedback.store(frame)
	local args = frame:getParent().args
	local text = args.text
	local resolved = require('Module:Yesno')(args.resolved)
	local title = mw.title.getCurrentTitle()
	if title:inNamespace(1) then
		bucket('feedback').put({
			text = text,
			resolved = resolved,
			time = args.time,
			page = title.text
		})
	end
	return string.format(
		'<span class="feedback %s" id="feedback-jump-%s">%s</span> %s',
		resolved and 'resolved' or 'unresolved',
		args.time,
		resolved and 'Resolved' or 'Unresolved',
		text
	)
end

--- Creates a table with all unresolved feedback.
--  @function           feedback.list
--  @return             {string} Table HTML
--  @see                [[Project:Feedback]]
function feedback.list()
	local Date = require('Module:Date')
	local rows = bucket('feedback')
		.where('resolved', false)
		.select(
			'page_name',
			'page',
			'text',
			'time'
		)
		.orderBy('time', 'DESC')
		.run()
	local html = mw.html.create('table')
		:attr('class', 'wikitable')
		:tag('tr')
			:tag('th')
				:wikitext('Page')
			:done()
			:tag('th')
				:wikitext('Date')
			:done()
			:tag('th')
				:wikitext('Comment')
			:done()
		:done()
	for _, row in ipairs(rows) do
		html:tag('tr')
				:tag('td')
					:wikitext(string.format(
						'[[%s]] ([[%s#feedback-jump-%s|talk]])',
						row.page,
						row.page_name,
						row.time
					))
				:done()
				:tag('td')
					:wikitext(Date(tonumber(row.time) / 1000):fmt('%B %d, %Y.'))
				:done()
				:tag('td')
					:wikitext(row.text)
				:done()
			:done()
	end
	return tostring(html:done())
end

--- Counts the amount of all, resolved and unresolved feedback.
--  @function           feedback.count
--  @return             {string} Formatted count and percentage from all
--  @see                [[Project:Feedback]]
function feedback.count(frame)
	local data = mw.loadData('Module:Feedback/count')
	local prop = frame.args[1]
	local language = mw.language.getContentLanguage()
	if prop == 'all' then
		return language:formatNum(data.all)
	end
	return string.format(
		'%d (%.2f%%)',
		language:formatNum(data[prop]),
		data[prop] / data.all * 100
	)
end

return feedback
--  </nowiki>