|
|
| (14 intermediate revisions by the same user not shown) |
| Line 1: |
Line 1: |
| local p = {}
| |
|
| |
|
| local function isTruthy(v)
| |
| if v == nil then
| |
| return false
| |
| end
| |
| v = mw.text.trim(tostring(v)):lower()
| |
| return v ~= '' and v ~= '0' and v ~= 'false' and v ~= 'no' and v ~= 'off'
| |
| end
| |
|
| |
| local function formatUser(user)
| |
| user = mw.text.trim(tostring(user or ''))
| |
| if user == '' or user:lower() == 'anonymous' then
| |
| return 'Anonymous'
| |
| end
| |
| return string.format('[[User:%s|%s]]', user, user)
| |
| end
| |
|
| |
| function p.main(frame)
| |
| local parent = frame:getParent()
| |
| local args = parent and parent.args or frame.args
| |
| return p._main(args)
| |
| end
| |
|
| |
| function p._main(args)
| |
| local feedback = args.feedback or "No feedback provided"
| |
| local user = args.user or "Anonymous"
| |
| local resolved = isTruthy(args.resolved)
| |
| local statusStr = resolved and 'resolved' or 'unresolved'
| |
| local currentPage = mw.title.getCurrentTitle().fullText
| |
|
| |
| -- Write directly to the Bucket database
| |
| if mw.ext and mw.ext.bucket then
| |
| mw.ext.bucket('feedback').put({
| |
| page = currentPage,
| |
| user = user,
| |
| status = statusStr,
| |
| feedback = feedback
| |
| })
| |
| end
| |
|
| |
| -- Build HTML display
| |
| local root = mw.html.create('div')
| |
| :addClass('feedback-box')
| |
| :addClass(resolved and 'feedback-box--resolved' or 'feedback-box--unresolved')
| |
|
| |
| local meta = root:tag('div')
| |
| :addClass('feedback-meta')
| |
|
| |
| meta:tag('span')
| |
| :addClass('feedback-user')
| |
| :wikitext(formatUser(user))
| |
|
| |
| meta:tag('span')
| |
| :addClass('feedback-separator')
| |
| :wikitext(' • ')
| |
|
| |
| meta:tag('span')
| |
| :addClass('feedback-status')
| |
| :addClass(resolved and 'feedback-status--resolved' or 'feedback-status--unresolved')
| |
| :wikitext(resolved and 'Resolved' or 'Unresolved')
| |
|
| |
| root:tag('div')
| |
| :addClass('feedback-body')
| |
| :wikitext(feedback)
| |
|
| |
| if not resolved then
| |
| root:tag('div')
| |
| :addClass('feedback-instruction')
| |
| :wikitext('If this feedback has been resolved, edit this page and set <code>|resolved=true</code>.')
| |
| end
| |
|
| |
| local category = resolved and '[[Category:Resolved Feedback]]' or '[[Category:Unresolved Feedback]]'
| |
|
| |
| return tostring(root) .. category
| |
| end
| |
|
| |
| function p.view(frame)
| |
| local parent = frame:getParent()
| |
| local args = parent and parent.args or frame.args
| |
| return p._view(args)
| |
| end
| |
|
| |
| function p._view(args)
| |
| if not (mw.ext and mw.ext.bucket) then
| |
| return "<em>Bucket extension is not available.</em>"
| |
| end
| |
|
| |
| local filterStatus = mw.text.trim(args.status or args[1] or 'all'):lower()
| |
|
| |
| local query = mw.ext.bucket('feedback')
| |
| :select({'page', 'user', 'status', 'feedback'})
| |
|
| |
| if filterStatus == 'resolved' or filterStatus == 'unresolved' then
| |
| query = query:where('status', filterStatus)
| |
| end
| |
|
| |
| local results = query:run()
| |
|
| |
| if not results or #results == 0 then
| |
| return "<em>No feedback entries found.</em>"
| |
| end
| |
|
| |
| local tableRoot = mw.html.create('table')
| |
| :addClass('wikitable sortable')
| |
| :css('width', '100%')
| |
|
| |
| local header = tableRoot:tag('tr')
| |
| header:tag('th'):wikitext('Page')
| |
| header:tag('th'):wikitext('User')
| |
| header:tag('th'):wikitext('Status')
| |
| header:tag('th'):wikitext('Feedback')
| |
|
| |
| for _, row in ipairs(results) do
| |
| local tr = tableRoot:tag('tr')
| |
| tr:tag('td'):wikitext(string.format('[[%s]]', row.page or ''))
| |
| tr:tag('td'):wikitext(formatUser(row.user))
| |
|
| |
| local isResolved = row.status == 'resolved'
| |
| local statusText = isResolved and 'Resolved' or 'Unresolved'
| |
| local statusStyle = isResolved and 'color: #2e7d32; font-weight: bold;' or 'color: #c62828; font-weight: bold;'
| |
|
| |
| tr:tag('td')
| |
| :cssText(statusStyle)
| |
| :wikitext(statusText)
| |
|
| |
| tr:tag('td'):wikitext(row.feedback or '')
| |
| end
| |
|
| |
| return tostring(tableRoot)
| |
| end
| |
|
| |
| return p
| |