Jump to content

Module:Aside

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Wnt (talk | contribs) at 19:27, 1 October 2016 (d+ not d* to make sure there are some digits in the snarfs). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

-- This module is an experiment in an altered discussion dynamic for Wikipedia forums.
-- It presents a brief digest of the referenced discussion on a user's talk subpage.
-- The full conversation remains available via V-D-E buttons (V = view the talk subpage, 
-- D = file a comment to the user's MAIN talk page like if there's something you want him to 'admin' or to request an invite as applicable
-- E = edit the talk subpage
-- The digest should present usernames and the first words of each comment, for the past N comments
-- One intention is to allow off-topic conversations to be less obtrusive on the parent thread.
-- Another is that, potentially, some of these may be invite-only conversations in some forum where that is deemed appropriate.
-- Discussions of this type might be indexed in multiple specialized forums.
-- Part of the experiment is that if users feel *invited* to a discussion, it gives editors a chance to express mutual esteem,
-- as a counterbalance against the usual where they only really talk personally when in conflict.  Not sure this will really happen...

-- To try to keep things more accessible, I think the Lua module should only do the text processing to create the talk page extract
-- This then should get wrapped up in V-D-E boxes and cute formatting by an enveloping template.
-- There are some things I can't be perfect about - if you reply in the middle of someone's comment you'll get their beginning attributed to you.

local p = {}

function p.main(frame,header)
    local parent=frame.getParent(frame) or {}
    local currentpage,top
    ---- args in the #invoke itself trump args in the parent frame - not sure if I should even access these but leaving them for now.
    user = frame.args.user or parent.args.user -- the location for discussion with whoever admins the aside, usually user talk:(x).  "D" defaults to (user)
    page = frame.args.page or parent.args.page -- the location of the page for the aside.  "V/E" defaults to (page), usually user talk:(x)/subpage
    comments = frame.args.comments or parent.args.comments -- the last N comments are returned
    length = frame.args.length or parent.args.length -- return at most N characters of text per comment
    -- "position" (left, right, plain) is a template parameter that can be handled in the template, so will not be used here.
    ---- args in the parent frame come next
    ---- default values if parameters aren't provided
    comments = comments or 6 -- Last 6 comments
    length = length or 80 -- In homage to TRS, but probably this will get longer
    -- get a pointer to the aside
    local pagepointer=mw.title.new(page)
    -- this needs to be revised to fail gracefully if the aside is deleted/not started
    assert(pagepointer,"failed to access mw.title.new("..tostring(page)..")")
    ---- get the text of the aside
    local text=pagepointer.getContent(pagepointer)
    assert (text,"error: failed to get text from ".. page)
    
    local signaturematch = "%[%[(.-)%]%]%s*%(%[%[(.-)%]%]%)%s*(%d+):(%d+)%s*,%s*(%d+)%s*(.-)%s*(%d+)"
    local prowl = mw.ustring.gmatch(text,"(.-)"..signaturematch)
    local archive = {} -- dictionary that pulls comment from the time
    local keys = {} -- shove all the times in here, then sort it later, use to pull out most recent comments wherever they are on the page
    repeat
        local comment, commentuser, commenttalk, commenthour, commentminute, commentday, commentmonth, commentyear = prowl()
        if not (comment) then break end
        local key = commentyear .. commentmonth .. commentday .. commenthour .. commentminute -- have to unfuck the month still
        archive[key] = {comment, commentuser} -- should check user = talk, only store one
        table.insert(keys, key)
    until false

    -- sort keys
    -- extract any text in <banner> tags and put first
    -- pick the last N keys

    local output=""
    for i = 1, table.maxn(keys) do
        output=output..(archive[keys[i]][1] or "") -- this isn't really the output I want yet
    end
    return frame.preprocess(frame,output)
end

return p