Module:Sandbox/Aidan9382/DiscussionOverview: Difference between revisions

Content deleted Content added
Rewrite the comments now that im less stressed
signatures are cool until they actually aren't cool cause you have to hunt for them with regexs. But hey, it works
Line 5:
local Transcluder = require("Module:Transcluder")
local p = {}
 
table.find = function(t,o) --Used to luau, so assumed this existed. Heres a quick version
for a,b in next,t do
if b == o then
return {}true
end
end
return false
end
 
local function convertTimestamp(timestamp)
return tonumber(lang:formatDate("U",timestamp))
end
 
--Specialised version of Transcluder.getSections, using a similar design
Line 21 ⟶ 34:
end
 
local function getUserSigsgetUserMentions(text)
--Returns a list of users, and if they were considered a "participant" or someone who was just mentioned
return {}
local mentions = {}
--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 so that it still picks up
local timestampRegex = "((%d%d:%d%d, %d%d? %w+,? %d%d%d%d) %(UTC%))"
local userRegex = "(%[%[:?User:([^|%]]+))"
local userTalkRegex = "(%[%[:?User:([^|%]]+))"
local userContribRegex = "(%[%[:?Special:Contributions/([^|%]]+))"
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.
--Bar of entry for being labelled a "participant" is a valid timestamp along with their user/usertalk/contribs
--Users can be noted as being both a participant and a mention during the data, so be smart in using this data
local usersOnThisLine = {}
for _,reg in next,{userRegex,userTalkRegex,userContribRegex} do
local index = 1
while true do
local targetText = string.sub(line,index,-1)
local wholeText,identifier = string.match(targetText,reg)
if not wholeText then
break
end
if not string.find(identifier,"/") then --Subpage nonsense
-- mw.log("Found user on reg",reg,"name is",identifier)
usersOnThisLine[string.find(targetText,reg)] = identifier
end
index = index + string.find(targetText,reg) + #wholeText
end
end
--Start associating timestamps with users
local index = 1
local pindex = {} --Lazy coding
local participants = {}
while true do
local targetText = string.sub(line,index,-1)
local wholeText,identifier = string.match(targetText,timestampRegex)
if not wholeText then
break
end
--Backtrack through the text for a mention
local timestampLocation = string.find(targetText,identifier)
local user,where
for i = timestampLocation,1,-1 do
user,where = usersOnThisLine[i],i
if user then
break
end
end
if user then
participants[#participants+1] = {user=user,when=identifier,participated=true}
pindex[user] = true
--else: be confused as hell
end
index = index + timestampLocation + #wholeText
end
local pings = {}
for _,user in next,usersOnThisLine do
if not pings[user] and not pindex[user] then --If they participated on a line, just ignore all pings
pings[user] = true
end
end
--Integrate the new data
for user,_ in next,pings do
mentions[#mentions+1] = {user=user,participated=false}
end
for _,userData in next,participants do
mentions[#mentions+1] = userData
end
end
return mentions
end
 
Line 37 ⟶ 117:
local sanitisedName = string.gsub(string.gsub(section.name,"%[%[:?[^|]-|([^%]]-)]]","%1"),"%[%[:?([^%]]-)]]","%1")
local wikilinkAnchor = "[[:"..page.."#"..sanitisedName.."|"..sanitisedName.."]]"
local membersInText = getUserMentions(section.content)
local sectionContent = "\n|-\n| "..wikilinkAnchor.." || AHHHHHHHHH"
local uniqueParticipants = {}
for _,userData in next,membersInText do
if userData.participated and not table.find(uniqueParticipants,userData.user) then
uniqueParticipants[#uniqueParticipants+1] = userData.user
end
end
local initiator = "Not yet calculated"
local lastComment = "Not yet calculated"
local participants = #uniqueParticipants .. ": " .. table.concat(uniqueParticipants,", ")
local sectionContent = "\n|-\n| "..wikilinkAnchor.." || "..initiator.." || "..lastComment.." || "..#section.content.." || "..participants
tableContent = tableContent .. sectionContent
end
Line 48 ⟶ 138:
return content .. "\n\n" .. frame:extensionTag("syntaxhighlight",content,{lang="html5"})
end
 
p.getSectionData = getSectionData
p.getUserMentions = getUserMentions
 
return p