0 Votes

Changes for page IncidentGallery

Last modified by Ryan C on 2025/07/17 06:41

From version 2.17
edited by Ryan C
on 2025/07/17 05:09
Change comment: There is no comment for this version
To version 4.8
edited by Ryan C
on 2025/07/17 05:51
Change comment: There is no comment for this version

Summary

Details

XWiki.WikiMacroClass[0]
Macro code
... ... @@ -1,14 +1,15 @@
1 1  {{groovy}}
2 +def results = []
3 +
2 2  def hql = """
3 - select doc.fullName
4 - from XWikiDocument doc, BaseObject obj
5 - where obj.name = doc.fullName
5 + select doc.fullName
6 + from XWikiDocument doc, BaseObject obj
7 + where obj.name = doc.fullName
6 6   and obj.className = 'Main Categories.Anti White Incidents.Code.MoviesClass'
7 7   order by doc.date desc
8 8  """
9 9  
10 10  def docs = xwiki.search(hql, 100, 0)
11 -def results = []
12 12  
13 13  docs.each { docName ->
14 14   def doc = xwiki.getDocument(docName)
... ... @@ -21,10 +21,14 @@
21 21  
22 22   if (!title || !summary) return
23 23  
24 - def isValidURL = externalURL?.startsWith("http://") || externalURL?.startsWith("https://")
25 + // ✅ Choose external link if valid, otherwise link to doc
26 + def isValidURL = externalURL && (externalURL.startsWith("http://") || externalURL.startsWith("https://"))
25 25   def linkTarget = isValidURL ? externalURL : "doc:${docName}"
28 +
29 + // ✅ Escape brackets in title to avoid wiki breakage
26 26   def safeTitle = title.replaceAll(/[\[\]\|]/, '').replaceAll(/\>\>/, '>>\u200B')
27 27  
32 + // ✅ Auto-detect first attached image
28 28   def imageFile = doc.getAttachmentList()?.find {
29 29   it.filename.toLowerCase().matches(".*\\.(png|jpg|jpeg|gif)")
30 30   }?.filename
... ... @@ -35,20 +35,20 @@
35 35   }
36 36  
37 37   def block = """
38 - (% style="margin-bottom:20px; width:100%" %)
39 - |${imageMarkup}|
43 +(% style="margin-bottom:20px; width:100%" %)
44 +|${imageMarkup}|
40 40  
41 - === [[${safeTitle}>>${linkTarget}]] ===
46 +=== [[${safeTitle}>>${linkTarget}]] ===
42 42  
43 - ${summary}
44 - [[Read More>>${linkTarget}]]
45 - """.trim()
48 +${summary}
49 +[[Read More>>${linkTarget}]]
50 +""".trim()
46 46  
47 47   results << block
48 48  }
49 49  
50 50  if (results.isEmpty()) {
51 - println "⚠️ No incidents to display."
56 + println "⚠️ Still no incident blocks rendered — ensure at least one page has valid title/summary/attachment."
52 52  } else {
53 53   println results.join("\n\n")
54 54  }
Macros.AntiWhiteTagClass.WebHome[0]
XWiki.WikiMacroParameterClass[0]
Parameter advanced
... ... @@ -1,0 +1,1 @@
1 +Yes
Parameter default value
... ... @@ -1,0 +1,1 @@
1 +Job Discrimination
Parameter deprecated
... ... @@ -1,0 +1,1 @@
1 +No
Parameter description
... ... @@ -1,0 +1,1 @@
1 +tags
Parameter hidden
... ... @@ -1,0 +1,1 @@
1 +No
Parameter mandatory
... ... @@ -1,0 +1,1 @@
1 +No
Parameter name
... ... @@ -1,0 +1,1 @@
1 +tags
Parameter type
... ... @@ -1,0 +1,1 @@
1 +Wiki