Editing Module:User:Kai/sandbox

Jump to navigation Jump to search
Warning: You are not logged in. Once you make an edit, a temporary account will be created for you. Learn more. Log in or create an account to continue receiving notifications after this account expires, and to access other features.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision Your text
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(frame, args)
end
function p._main(frame, 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 to Bucket database
    -- Syntax equivalent to: {{#bucket:Feedback|page=...|user=...|status=...|feedback=...}}
    local bucketOutput = frame:callParserFunction('#bucket', {
        'Feedback',
        'page=' .. currentPage,
        'user=' .. user,
        'status=' .. statusStr,
        'feedback=' .. feedback
    })
    -- HTML presentation
    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 bucketOutput .. tostring(root) .. category
end
return p
Please note that all contributions to The Deadlock Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Deadlock:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template

Page included on this page: