Module:Feedback

From RuneRealm Wiki

This is the current revision of this page, as edited by Alex (talk | contribs) at 00:12, 17 October 2024 (Created page with "local pt = require('Module:Paramtest') local yn = require('Module:Yesno') local p = {} p.yn=yn function p.main(frame) return p._main(frame:getParent().args) end function p._main(args) local isResolved = false if pt.has_content(args.resolved) then isResolved = yn(args.resolved) end local stars = tonumber(args.rating) or 0 stars = math.min(math.floor(stars), 5) local comment = pt.default_to(args.feedback, "''No comment provided''") local id = pt.default_to(args...."). The present address (URL) is a permanent link to this version.

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Feedback/doc

local pt = require('Module:Paramtest')
local yn = require('Module:Yesno')
local p = {}
p.yn=yn
function p.main(frame)
	return p._main(frame:getParent().args)
end

function p._main(args)
	local isResolved = false
	if pt.has_content(args.resolved) then
		isResolved = yn(args.resolved)
	end
	local stars = tonumber(args.rating) or 0
	stars = math.min(math.floor(stars), 5)
	local comment = pt.default_to(args.feedback, "''No comment provided''")
	local id = pt.default_to(args.id, '')
	local fbdate = nil
	if pt.has_content(args.date) then
		fbdate = args.date
	end
	
	local outDiv = mw.html.create('div')
	outDiv:addClass('tile gloop-feedback-wrapper')
		:attr('id', 'gloop-feedback-scrollto-'..id)
		:attr('data-id', id)
		:css({
			['margin-bottom'] = '0.75em'
		})
	local toggleDiv = outDiv:tag('div')
	toggleDiv:css({
			['float'] = 'right',
			['padding'] = '0.25em 0.5em',
			['border-radius'] = '5px',
			['font-size'] = '0.85em',
			['font-weight'] = '800',
			['margin'] = '0 0 10px 10px'
		})
	if isResolved then
		toggleDiv:addClass('table-bg-green gloop-feedback-resolve-toggle')
			:tag('span'):wikitext('Resolved[[Category:Pages with resolved feedback]]')
	else
		toggleDiv:addClass('table-bg-red gloop-feedback-resolve-toggle')
			:tag('span'):wikitext('Unresolved[[Category:Pages with unresolved feedback]]')
	end
	local starsP = outDiv:tag('div'):addClass('gloop-feedback-rating gloop-feedback-rating-'..tostring(stars)):tag('p')
	for i=0,stars-1,1 do
		starsP:wikitext('[[File:Star.svg|25px|link=]]')
	end
	
	outDiv:newline():newline()
	outDiv:tag('div')
			:addClass('gloop-feedback-comment')
			:wikitext(comment)
	outDiv:newline():newline()
		:tag('span')
		:css({
			['font-size'] = '0.9em'
		})
		:wikitext('—Submitted via [[RuneScape:Article feedback|Article feedback]]')
	
	-- 1 => talk
	if mw.title.getCurrentTitle().namespace == 1 then
		mw.smw.subobject({
			['Feedback resolved'] = tostring(isResolved),
			['Feedback comment'] = mw.text.nowiki(comment),
			['Feedback ID'] = id,
			['Feedback stars'] = stars,
			['Feedback timestamp'] = fbdate
		})
	end
	
	return tostring(outDiv)
end

function p.list(frame)
	return p._list(frame:getParent().args)
end
function p._list(args)
	function stars(x)
		local ret = ''
		for i=0,x-1,1 do
			ret = ret .. '[[File:Star.svg|15px|link=]]'
		end
		return ret
	end
	
	local query = {
		'[[Feedback ID::+]]',
		'?Feedback ID',
		'?Feedback comment',
		'?Feedback stars',
		'?Feedback resolved',
		'?Feedback timestamp',
		'?#-=',
		sort='Feedback timestamp',
		order='desc',
		limit = 2500
	}
	if pt.has_content(args.page) then
		table.insert(query, 2, '[[Talk:'..args.page..']]')
	end
	local resolvedfilter = '[[Feedback resolved::false]]'
	if pt.has_content(args.show) then
		if string.lower(args.show) == 'resolved' then
			resolvedfilter = '[[Feedback resolved::true]]'
		elseif string.lower(args.show) == 'all' then
			resolvedfilter = '[[Feedback resolved::+]]'
		end
	end
	table.insert(query, 2, resolvedfilter)
	
	local data = mw.smw.ask(query)
	if data == nil then
		return tostring('No feedback to display.')
	end
	local lang = mw.getContentLanguage()
	local outT = mw.html.create('table')
	local header = outT:addClass('wikitable sortable')
		:tag('tr')
			:tag('th'):wikitext('Page'):done()
			:tag('th'):wikitext('Date'):done()
			:tag('th'):wikitext('Comment'):done()
		if pt.has_content(args.show) and string.lower(args.show) == 'all' then
			header:tag('th'):wikitext('Resolved'):done()
		end
	for i,v in ipairs(data) do
		local tr = outT:newline():tag('tr')
		local pagename = string.gsub(v[1], '^Talk:(.*)#.*$', '%1')
		local fbdate = v['Feedback timestamp']
		local fbsort = 0
		if fbdate then
			fbsort = fbdate
			fbdate = lang:formatDate('Y-m-d H:i:s', '@'..string.sub(fbdate,0,-4))
		else
			fbdate = ''
		end
		tr	:tag('td')
				:wikitext('[['..pagename..']]' .. ' ([[Talk:'..pagename..'#gloop-feedback-scrollto-'..v['Feedback ID']..'|talk]])'):done()
			:tag('td')
				:attr('data-sort-value', fbsort):wikitext(fbdate):done()
			:tag('td')
				:wikitext(v['Feedback comment']):done()
		if pt.has_content(args.show) and string.lower(args.show) == 'all' then
			if yn(v['Feedback resolved']) then
				tr:tag('td'):wikitext('[[File:Yes check.svg|15px|link=]]')
			else
				tr:tag('td'):wikitext('[[File:X mark.svg|15px|link=]]')
			end
		end
	end
	return tostring(outT)
end


return p