Content deleted Content added
signatures are cool until they actually aren't cool cause you have to hunt for them with regexs. But hey, it works |
temporary user stuff (from mw:Trust and Safety Product/Temporary Accounts#Updates) |
||
(23 intermediate revisions by the same user not shown) | |||
Line 15:
end
local lang = mw.getContentLanguage()
local function
return tonumber(lang:formatDate("U",timestamp))
end
local function concatUsers(users)
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
final = final .. "[[:User:"..user.."|"..user.."]], "
end
end
return string.sub(final,1,-3)
end
--Specialised version of Sandbox/Smalljim/ParsePageTest.formatDateDiff that just does hours (better for sorting cause im not learning wikitables)
local function formatDateDiff( date_diff )
return tonumber( math.floor(date_diff/(6*60))/10 ) .. ' hours';
end
Line 34 ⟶ 52:
end
--This is a bloody mess of a mix of ideas, but it mostly works, so good enough
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 = "(%[%[:?
local userTalkRegex = "(%[%[:?
local userContribRegex = "(%[%[:?
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.
--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
Line 55 ⟶ 75:
break
end
if not string.find(identifier,"/") then --Avoid subpage nonsense
usersOnThisLine[string.find(targetText,reg)] = identifier
end
Line 84 ⟶ 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 109 ⟶ 130:
assert(type(page)=="string","Invalid or no page provided")
local
return Transcluder.get(page)
end, function(err)
error(debug.traceback())
end)
local sections = getSectionData(text)
local tableContent = '{| class="wikitable sortable"\n!
'<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.."|"..
local membersInText = getUserMentions(section.content)
local uniqueParticipants = {}
Line 122 ⟶ 149:
if userData.participated and not table.find(uniqueParticipants,userData.user) then
uniqueParticipants[#uniqueParticipants+1] = userData.user
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
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]
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
end
end
end
end
local firstComment,lastComment
if #orderedComments == 0 then
local lastComment = "Not yet calculated"▼
firstComment = "N/A"
local participants = #uniqueParticipants .. ": " .. table.concat(uniqueParticipants,", ")▼
local sectionContent = "\n|-\n| "..wikilinkAnchor.." || "..initiator.." || "..lastComment.." || "..#section.content.." || "..participants▼
elseif #orderedComments == 1 then
firstComment = formatDateDiff(now-orderedComments[1].when) .. " ago" .. "<br>" .. concatUsers({orderedComments[1].user})
lastComment = "N/A"
else
firstComment = formatDateDiff(now-orderedComments[1].when) .. " ago" .. "<br>" .. concatUsers({orderedComments[1].user})
lastComment = formatDateDiff(now-orderedComments[#orderedComments].when) .. " ago" .. "<br>" .. concatUsers({orderedComments[#orderedComments].user})
end
▲ local participants = #uniqueParticipants .. ": " ..
local mentions = #mentionedUsers .. ": " .. concatUsers(mentionedUsers)
▲ local sectionContent = "\n|-\n| "..wikilinkAnchor.." || "..
tableContent = tableContent .. sectionContent
end
|