Module:Feedback
Jump to navigation
Jump to search
Module documentation
This documentation is transcluded from Module:Feedback/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:Feedback/doc. [edit]
Module:Feedback's function main is invoked by Template:Feedback.
Module:Feedback requires Module:Paramtest.
Module:Feedback requires Module:Yesno.
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 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
outDiv:newline():newline()
outDiv:tag('div')
:addClass('gloop-feedback-comment')
:wikitext(comment)
-- 1 => talk
if mw.title.getCurrentTitle().namespace == 1 then
bucket("feedback").put({
resolved = yn(isResolved),
comment = comment,
id = id,
timestamp = fbdate
})
end
return tostring(outDiv)
end
function p.list(frame)
return p._list(frame:getParent().args)
end
function p._list(args)
local b = bucket("feedback")
.select('page_name', 'id', 'comment', 'resolved', 'timestamp')
.orderBy('timestamp', 'DESC')
.limit(2500)
if pt.has_content(args.page) then
b.where('page_name', args.page)
end
if pt.has_content(args.show) then
if string.lower(args.show) == 'resolved' then
b.where('resolved', true)
end
else
b.where('resolved', false)
end
local data = b.run()
if #data == 0 then
return tostring('No feedback to display.')
end
local lang = mw.getContentLanguage()
local outT = mw.html.create('table')
local header = outT:addClass('wikitable sortable sticky-header align-center-2')
:tag('tr')
:tag('th')
:wikitext('Page')
:css({ ['width'] = '300px' })
:done()
:tag('th')
:wikitext('Date')
:css({ ['width'] = '115px' })
:done()
:tag('th')
:wikitext('Feedback')
: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.page_name, '^Talk:(.*)$', '%1')
local fbdate = v['timestamp']
local fbsort = 0
if fbdate then
fbsort = fbdate
fbdate = lang:formatDate('Y-m-d', '@'..string.sub(fbdate,0,-4))
else
fbdate = ''
end
tr :tag('td')
:wikitext('[['..pagename..']]' .. ' ([[Talk:'..pagename..'#gloop-feedback-scrollto-'..v['id']..'|talk]])'):done()
:tag('td')
:attr('data-sort-value', fbsort):wikitext(fbdate):done()
:tag('td')
:wikitext(mw.text.nowiki(v['comment'])):done()
if pt.has_content(args.show) and string.lower(args.show) == 'all' then
if yn(v['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