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 |
More features (timestamping and what not) |
||
Line 4:
--]=]
local Transcluder = require("Module:Transcluder")
local pp = require("Module:Sandbox/Smalljim/ParsePageTest")
local p = {}
Line 15 ⟶ 16:
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:]+$") 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
Line 34 ⟶ 48:
end
--This is a bloody mess of a mix of ideas, but it mostly works, so im dealing with it
local function getUserMentions(text)
--Returns a list of users, and if they were considered a "participant" or someone who was just mentioned
Line 43 ⟶ 58:
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 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 ⟶ 70:
break
end
if not string.find(identifier,"/") then --
usersOnThisLine[string.find(targetText,reg)] = identifier
end
Line 113 ⟶ 128:
local sections = getSectionData(text)
local tableContent = '{| class="wikitable sortable"\n! Section !! Initiator !! Last Comment !! Size !! Participants !! Mentions'
for _,section in next,sections do
local sanitisedName = string.gsub(string.gsub(section.name,"%[%[:?[^|]-|([^%]]-)]]","%1"),"%[%[:?([^%]]-)]]","%1")
Line 124 ⟶ 139:
end
end
local orderedComments = {}
for _,userData in next,membersInText do
if userData.participated then
local when = getTime(userData.when)
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
local now = getTime()
mw.logObject(orderedComments)
local firstComment,lastComment
local initiator = "Not yet calculated"▼
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 = concatUsers({orderedComments[1].user}) .. "<br>" .. pp.formatDateDiff(now-orderedComments[1].when)
lastComment = "N/A"
else
firstComment = concatUsers({orderedComments[1].user}) .. "<br>" .. pp.formatDateDiff(now-orderedComments[1].when)
lastComment = concatUsers({orderedComments[#orderedComments].user}) .. "<br>" .. pp.formatDateDiff(now-orderedComments[#orderedComments].when)
end
▲ local participants = #uniqueParticipants .. ": " ..
▲ local sectionContent = "\n|-\n| "..wikilinkAnchor.." || "..
tableContent = tableContent .. sectionContent
end
|