Module:Aside

-- 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
    user = frame.args.user or parent.args.user
    page = frame.args.page or parent.args.page
    local basepage, section = mw.ustring.match(page, "(.-)#(.*)")
    if section then page = basepage end
    comments = frame.args.comments or parent.args.comments
    length = frame.args.length or parent.args.length
    order = frame.args.order or parent.args.order or "new"
    if (order == "") then order = "new" end
    comments = comments or 6
    comments = tonumber(comments)
    if (comments == 0 or not(comments)) then comments = 6 end
    length = length or 80
    length = tonumber(length)
    local pagepointer=mw.title.new(page)
    if not(pagepointer) then return "''[[Module:Aside]]: The page " .. '"' .. page .. '"' .. " could not be accessed.''" end
    local text=pagepointer.getContent(pagepointer)
    
    if not(text) then return "''[[Module:Aside]]: The page " .. '"' .. page .. '"' .. " could not be read. Make sure it exists and is not empty.''" end

    if section then
    	local textbits = mw.text.split(text, section, true)
    	if #textbits > 1 then
    		local i = 2
    		repeat
    		    if (mw.ustring.match(textbits[i-1], "==*%s*$")) and (mw.ustring.match(textbits[i], "^%s*==*")) then
    			    text = mw.ustring.gsub(table.concat(textbits, "", i), "%s*==*", "", 1)
    			    text = mw.ustring.gsub(text, "\n%s*==*.*", "", 1)
    			    break
    		    end
    		    i = i + 1
	        until (i > #textbits)
	    else
	    	return "''[[Module:Aside]]: The section " .. '"' .. section .. '"' .. " could not be found in " .. '"' .. page .. '"'
	    end
    end
    		
    local output=mw.ustring.match(text, "<!%-%-+banner%-%-+>(.-)<!%-%-+/banner%-%-+>") or ""
    output = output .. "<br />"
    text = mw.ustring.gsub(text, "<!%-%-+banner%-%-+>(.-)<!%-%-+/banner%-%-+>%s*", "", 1)
    text = mw.ustring.gsub(text, "==+([^\n=]*)=+=%s*", "")
    text = mw.ustring.gsub(text, "<!%-%-+.-%-%-+>", "")
    
    local signaturematch = "%[%[(.-)%]%]%s*%(%[%[(.-)%]%]%)%s*(%d+):(%d+)%s*,%s*(%d+)%s*(.-)%s*(%d+)%s*%(%a%a%a%)%s*"
    local monthlookup = {["January"] = "01", ["February"] = "02", ["March"] = "03", ["April"] = "04", ["May"] = "05", ["June"] = "06", ["July"] = "07", ["August"] = "08", ["September"] = "09", ["October"] = "10", ["November"] = "11", ["December"] = "12"}
    local prowl = mw.ustring.gmatch(text,":*%s*(.-)"..signaturematch)
    local archive = {}
    local keys = {}
    repeat
        local comment, commentuser, commenttalk, commenthour, commentminute, commentday, commentmonth, commentyear = prowl()
        if not (comment) then break end
        comment = mw.ustring.gsub(comment, "$[:%s\n]*", "", 1)
        comment = mw.ustring.gsub(comment, "\n:*", "  ")
        comment = mw.ustring.gsub(comment, "<br ?\\?>", "  ")
        local commentmonthno = monthlookup[commentmonth] or "00"
        if mw.ustring.len(commentday) == 1 then commentday = "0" .. commentday end
        local key = commentyear .. commentmonthno .. commentday .. commenthour .. commentminute
        commentuser = mw.ustring.match(commentuser, "(.-)|") or commentuser
        commentuser = mw.ustring.match(commentuser, "User:(.*)") or commentuser
        commenttalk = mw.ustring.match(commenttalk, "(.-)|") or commenttalk
        commenttalk = mw.ustring.match(commenttalk, "(.-)#") or commenttalk
     
        commentdate = commentmonthno .. "/" .. commentday .. " " .. commenthour .. ":" .. commentminute
        archive[key] = {comment, commentuser, commenttalk, commentdate}
        table.insert(keys, key)
    until false

    if (order == "new") then table.sort(keys) end
    
  
    local lastkey = #keys
    local firstkey = math.max(1, lastkey - comments + 1)
    for i = firstkey, lastkey do
    	local key = keys[i]
    	local comment, commentuser, commenttalk, commentdate = archive[key][1], archive[key][2], archive[key][3], archive[key][4]
    	local longuser = mw.ustring.len(commentuser)
    	if (longuser>12) then commentuser = mw.ustring.sub(commentuser, 1, 5) .. ".." .. mw.ustring.sub(commentuser, longuser - 4, longuser) end
        output=output.. commentdate .." [["..commenttalk.."|"..commentuser.."]]: "..(mw.ustring.sub(comment, 1, length) or "").."<br />"
    end
    return frame.preprocess(frame,output)
end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.