Wiki source code of sidebyside
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | {{groovy}} | ||
2 | import java.text.SimpleDateFormat | ||
3 | |||
4 | def guestId = "XWiki.XWikiGuest" | ||
5 | def cutoff = new Date(System.currentTimeMillis() - (1000L * 60 * 60 * 48)) // last 48 hours | ||
6 | def dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") | ||
7 | def context = xcontext.getContext() | ||
8 | def results = [] | ||
9 | |||
10 | xwiki.searchDocuments("where 1=1").each { docName -> | ||
11 | def doc = xwiki.getDocument(docName) | ||
12 | def lastMod = doc.getDate() | ||
13 | |||
14 | if (lastMod && lastMod.after(cutoff) && doc.author == guestId) { | ||
15 | def archive = doc.getDocumentArchive() | ||
16 | def versions = archive.getRevisionList().sort() | ||
17 | |||
18 | if (versions.size() >= 2) { | ||
19 | def prevVersion = archive.loadXWikiDocument(versions[-2], context) | ||
20 | def currVersion = archive.loadXWikiDocument(versions[-1], context) | ||
21 | |||
22 | def oldContent = prevVersion.getContent() | ||
23 | def newContent = currVersion.getContent() | ||
24 | |||
25 | if (oldContent != newContent) { | ||
26 | results << """ | ||
27 | === [[${currVersion.displayTitle}>>path:/bin/view/${currVersion.space}/${currVersion.name}]] — edited at ${dateFormat.format(lastMod)} === | ||
28 | |||
29 | **📝 Before (v${versions[-2]}):** | ||
30 | ---- | ||
31 | ${oldContent.take(3000)} | ||
32 | ---- | ||
33 | |||
34 | **🆕 After (v${versions[-1]}):** | ||
35 | ---- | ||
36 | ${newContent.take(3000)} | ||
37 | ---- | ||
38 | """ | ||
39 | } | ||
40 | } | ||
41 | } | ||
42 | } | ||
43 | |||
44 | if (results) { | ||
45 | println "== 🚨 Content Changes by XWiki.XWikiGuest (last 48h) ==\\n" | ||
46 | results.each { println it } | ||
47 | } else { | ||
48 | println "✅ No content changes by guest in the last 48 hours." | ||
49 | } | ||
50 | {{/groovy}} |