Module:Sandbox/Aidan9382/DiscussionOverview: Difference between revisions

Content deleted Content added
better date diff sorting stuff
 
(21 intermediate revisions by the same user not shown)
Line 23:
local final = ""
for _,user in next,users do
if string.match(user,"^%d+%.%d+%.%d+%.%d+$") or string.match(user,"^%x+:[%x:]+$") or string.match(user, "^~%d%d%d%d%-%d%d%d%d%d%-%d%d%d$") then --Lazy but mostly working basic IPv6 regex
final = final .. "[[Special:Contributions/"..user.."|"..user.."]], "
else
Line 52:
end
 
--This is a bloody mess of a mix of ideas, but it mostly works, so imgood dealing with itenough
local function getUserMentions(text)
--Returns a list of users, and if they were considered a "participant" or someone who was just mentioned
local mentions = {}
text = mw.text.decode(text,true)
--Timestamp is %d%d:%d%d, %d%d? %w+ %d%d%d%d %(UTC%)) but we allow some (minor) leniancy for those who just slightly edit their dates (why?) so that it still picks up
local timestampRegex = "((%d%d:%d%d, %d%d? %w+,? %d%d%d%d) %(UTC%))"
local userRegex = "(%[%[:?User[Uu]ser:([^#|%]]+))"
local userTalkRegex = "(%[%[:?User[Uu]ser[ _][Tt]alk:([^#|%]]+))"
local userContribRegex = "(%[%[:?Special[Ss]pecial:Contributions[Cc]ontributions/([^#|%]]+))"
for line in string.gmatch(text,"[^\n]+") do
--Split by line and check all content on said line. This assumes all signatures never use newlines, which they should not be doing anyways.
Line 74 ⟶ 75:
break
end
identifier = string.gsub(identifier,"_"," ")
if not string.find(identifier,"/") then --Avoid subpage nonsense
mw.log("Found user on reg",reg,"name is",identifier)
usersOnThisLine[string.find(targetText,reg)] = identifier
end
Line 103 ⟶ 104:
participants[#participants+1] = {user=user,when=identifier,participated=true}
pindex[user] = true
else --else: be confused as hell
mw.log("Timestamp had no associated users on its line (TS "..wholeText..")")
end
index = index + timestampLocation + #wholeText
Line 128 ⟶ 130:
assert(type(page)=="string","Invalid or no page provided")
local success_, text = pcallxpcall(function(Transcluder.get,page)
return Transcluder.get(page)
assert(success,text)
end, function(err)
error(debug.traceback())
end)
local sections = getSectionData(text)
local tableContent = '{| class="wikitable sortable"\n! Sectionstyle="text-align:center" !!colspan=6 Initiator| !!Conversation Lastsummary Commentfor !![[' Size.. !!page Participants.. !! Mentions']]' ..
'<span style="position:absolute;right:2em;font-size:90%">[[Module:Sandbox/Aidan9382/DiscussionOverview|v]]</span>' ..
'\n|-\n! Section !! Initiator !! Last Comment !! Size !! Participants !! Mentions'
for _,section in next,sections do
local sanitisedName = string.gsub(string.gsub(mw.uri.anchorEncode(frame:preprocess(section.name)),"%[%[:?[^|]-|([^%]]-)]]","%1"),"%[%[:?([^%]]-)]]","%1")
local displayName = string.gsub(string.gsub(frame:preprocess(section.name),"%[%[:?[^|]-|([^%]]-)]]","%1"),"%[%[:?([^%]]-)]]","%1")
local wikilinkAnchor = "[[:"..page.."#"..sanitisedName.."|"..sanitisedNamedisplayName.."]]"
local membersInText = getUserMentions(section.content)
local uniqueParticipants = {}
Line 143 ⟶ 151:
end
end
local mentionedUsers = {}
for _,userData in next,membersInText do
if not userData.participated and not table.find(uniqueParticipants,userData.user) and not table.find(mentionedUsers,userData.user) then
mentionedUsers[#mentionedUsers+1] = userData.user
end
end
local now = getTime()
local orderedComments = {}
for _,userData in next,membersInText do
if userData.participated then
local when = getTime(userData.when)
if now > when then --Ensure comment is from the past
if #orderedComments == 0 then
if #orderedComments == 0 then
orderedComments[#orderedComments+1] = {user=userData.user,when=when}
else
for i = 1,#orderedComments do
local comment = orderedComments[i]
if when < comment.when then
for i2 = #orderedComments+1,i,-1 do
orderedComments[i2] = orderedComments[i2-1]
break end
orderedComments[i] = {user=userData.user,when=when}
break
end
if i == #orderedComments then
orderedComments[#orderedComments+1] = {user=userData.user,when=when} --Reached the end, latest comment
break
end
orderedComments[i] = {user=userData.user,when=when}
break
end
if i == #orderedComments then
orderedComments[#orderedComments+1] = {user=userData.user,when=when} --Reached the end, latest comment
break
end
end
Line 167 ⟶ 184:
end
end
local now = getTime()
mw.logObject(orderedComments)
local firstComment,lastComment
Line 182 ⟶ 197:
end
local participants = #uniqueParticipants .. ": " .. concatUsers(uniqueParticipants)
local mentions = "Could#mentionedUsers be.. calculated": but" I'm.. lazy"concatUsers(mentionedUsers)
local sectionContent = "\n|-\n| "..wikilinkAnchor.." || "..firstComment.." || "..lastComment.." || "..#section.content.." || "..participants.." || "..mentions
tableContent = tableContent .. sectionContent