0 Votes

Changes for page CleanBots

Last modified by Ryan C on 2025/04/26 23:47

From version 1.1
edited by Ryan C
on 2025/04/26 23:42
Change comment: There is no comment for this version
To version 2.1
edited by Ryan C
on 2025/04/26 23:44
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -1,1 +1,40 @@
1 -a
1 +{{groovy}}
2 +def xwiki = xcontext.getXWiki()
3 +def context = xwiki.getXWikiContext()
4 +def userDocs = xwiki.getSpaceDocsName("XWiki", context)
5 +
6 +// How many bots to delete per run
7 +def maxDeletes = 100
8 +def deleteCounter = 0
9 +
10 +userDocs.each { username ->
11 + if (deleteCounter >= maxDeletes) {
12 + return
13 + }
14 +
15 + // Skip known real/system pages
16 + if (username in ["Admin", "AdminAngriff", "TelegramBot", "testuser", "XWikiGuest", "SuperAdmin",
17 + "XWikiPreferences", "XWikiRights", "XWikiUsers", "XWikiAllGroup", "XWikiAdminGroup",
18 + "XWikiEditorsGroup", "XWikiReadOnlyGroup", "OfficeServer", "PageAdministration",
19 + "Extensions", "History", "Updater", "AvailableMacros", "XWikiSyntaxGuide", "Index",
20 + "Attachments", "DeletedAttachments", "DeletedPages", "OrphanedPages", "Tree",
21 + "ExternalLinks", "Results", "Macros", "SolrSearchAdministration", "DataTypes",
22 + "OfficeImporter", "XWikiAdvancedAdministrationTools", "XWikiProCommons", "ZoneCode"]) {
23 + println "Skipping real/system page: $username"
24 + } else if (username ==~ /^[0-9a-z]{6}$/) {
25 + def fullName = "XWiki.${username}"
26 + def doc = xwiki.getDocument(fullName, context)
27 + if (doc && doc.getObject("XWiki.XWikiUsers")) {
28 + xwiki.deleteDocument(doc, context)
29 + println "Deleted bot page: $username"
30 + deleteCounter++
31 + } else {
32 + println "Skipping page without user object: $username"
33 + }
34 + } else {
35 + println "Skipping normal page: $username"
36 + }
37 +}
38 +println "✅ Deleted ${deleteCounter} bot pages in this batch."
39 +{{/groovy}}
40 +

XWiki AI Chat