Wiki source code of Recent Changes

Last modified by superadmin on 2026/12/02 05:22

Show last authors
1 {{velocity}}
2 ##
3 ## Recent changes.
4 ##
5 ## Optional parameters :
6 ##
7 ## Parameters which can be set in velocity before including this page or can be passed as HTTP parameters.
8 ## Note that HTTP parameters supercede velocity set variables.
9 ##
10 ## - rcShowMinor (String set to "true" or "false"): show minor edits.
11 ## - rcShowDiff (String set to "true" or "false"): show diff in items.
12 ## - rcShowRss (String set to "true" or "false"): show RSS at the bottom of the list.
13 ## - rcChangesNb (String set to a numerical value): number of recent changes to display.
14 ## - rcSpace (List of string[s]): restrict recent changes retrieval to pages within the given space.
15 ## - rcTag (List of string[s]): restrict recent changes retrieval to pages with the given tag.
16 ## - rcAuthor (List of string[s]): restrict recent changes retrieval to pages with the given author.
17 ##
18 ## Parameters which can be set before including this page only.
19 ##
20 ## - rcDocumentNames (Collection): The list of recentlyChanged documents, to reuse a previous search query.
21 ##
22 $xwiki.jsx.use("Main.RecentChanges")##
23 $xwiki.ssx.use("Main.RecentChanges")##
24 #set($action = "$!request.getParameter('action')")
25 ##
26 ## Start execution timer
27 ##
28 #set($execStart = $util.getDate())
29 ##
30 ## Go to diff URL service.
31 ##
32 #if($action == "goToDiffURL")
33 #set($page = "$!request.getParameter('page')")
34 #set($author = "$!request.getParameter('author')")
35 #set($date = "$!request.getParameter('date')")
36 #set($period = $xwiki.criteriaService.getPeriodFactory().createDayPeriod($date))
37 #set($criterion = $xwiki.criteriaService.getRevisionCriteriaFactory().createRevisionCriteria($author, $period))
38 #if("$!request.getParameter('rcShowMinor')" == "true")
39 #set($discard = $criterion.setIncludeMinorVersions(true))
40 #end
41 #set($diffDoc = $xwiki.getDocument($page))
42 #set($revisions = $diffDoc.getRevisions($criterion))
43 #set($rev1 = $listtool.get($revisions, 0))
44 #set($revMax = $revisions.size() - 1)
45 #set($rev2 = $listtool.get($revisions, $revMax))
46 #if($rev2 != "1.1")
47 #set($rev2 = $xwiki.getDocument($diffDoc, $rev2).getPreviousVersion())
48 #end
49 $response.sendRedirect($diffDoc.getURL("view", "viewer=changes&rev1=${rev1}&rev2=${rev2}"))
50 #end
51 ## We have to use the HTML macro to avoid prints of multiple &nbsp on macro calls.
52 {{html}}
53 ## Manage minor edits.
54 #setVariableFromRequest($rcShowMinor "rcShowMinor" false)
55 ## Manage show diff in items.
56 #setVariableFromRequest($rcShowDiff "rcShowDiff" true)
57 ## Manage show RSS links.
58 #setVariableFromRequest($rcShowRss "rcShowRss" true)
59 ## Manage number of changes to display.
60 #setVariableFromRequest($rcChangesNb "rcChangesNb" 30)
61 ## Manage tag criterion
62 #setVariableFromRequest($rcTag "rcTag" [])
63 ## Manage space criterion
64 #setVariableFromRequest($rcSpace "rcSpace" [])
65 ## Manage author criterion
66 #setVariableFromRequest($rcAuthor "rcAuthor" [])
67 {{/html}}
68 ##
69 ## Create a string containing one or more ? given the number of values in the passed list.
70 ##
71 #macro(createQueryParameters $values $parameters)
72 #foreach($value in $values)
73 #if($parameters == "")
74 #set($parameters = "?")
75 #else
76 #set($parameters = "${parameters}, ?")
77 #end
78 #end
79 #end
80 ##
81 ## Retrieve recently changed documents.
82 ##
83 #set($criteria = $util.getHashMap())
84 #if("$!rcDocumentNames" == "")
85 #if(!$xwiki.hasMinorEdit() || $rcShowMinor)
86 #set ($hqlQuery = "where 1=1 order by doc.date desc")
87 #else
88 #set ($hqlQuery = "where doc.version like '%.1'#if(!$isAdvancedUser) and doc.author != 'superadmin'#end order by doc.date desc")
89 #end
90 ## Create space criterion.
91 #if($rcSpace.size() > 0)
92 #set($spaceParameters = "")
93 #createQueryParameters($rcSpace $spaceParameters)
94 #set($discard = $criteria.put("doc.space in (${spaceParameters})", $rcSpace))
95 #end
96 ## Create tag criterion.
97 #if("$!xwiki.getPlugin('tag')" != "" && $rcTag.size() > 0)
98 #set($docsWithTag = $util.getArrayList())
99 #foreach($item in $rcTag)
100 #set($discard = $docsWithTag.addAll($xwiki.tag.getDocumentsWithTag($item)))
101 #end
102 #set($docsWithTagParameters = "")
103 #createQueryParameters($docsWithTag $docsWithTagParameters)
104 #set($discard = $criteria.put("doc.fullName in (${docsWithTagParameters})", $docsWithTag))
105 #end
106 #if($rcAuthor.size() > 0)
107 #set($authorParameters = "")
108 #createQueryParameters($rcAuthor $authorParameters)
109 #set($discard = $criteria.put("doc.author in (${authorParameters})", $rcAuthor))
110 #end
111 ## Exclude blacklisted spaces if displaying changes for a whole wiki
112 #if($rcSpace.size() == 0)
113 #set($blacklistedSpacesParameters = "")
114 #createQueryParameters($blacklistedSpaces $blacklistedSpacesParameters)
115 #set($discard = $criteria.put("doc.space not in (${blacklistedSpacesParameters})", $blacklistedSpaces))
116 #end
117 #if($criteria.size() > 0)
118 ## If any, loop over criterias to add them to the query, then perform the query.
119 #set($values = $util.getArrayList())
120 #foreach($criterion in $criteria.keySet())
121 #if($criteria.get($criterion) && $criteria.get($criterion).size() > 0)
122 #set($hqlQuery = $hqlQuery.replaceAll("where", "where ${criterion} and"))
123 #set($discard = $values.addAll(0, $criteria.get($criterion)))
124 #end
125 #end
126 #set ($legacyRaw2c943fa57f_1 = $services.query.hql($hqlQuery).bindValues($values).setLimit($rcChangesNb).setOffset(0).execute())
127 #set ($legacyVisible2c943fa57f_1 = [])
128 #foreach ($legacyEntry2c943fa57f_1 in $legacyRaw2c943fa57f_1)
129 #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntry2c943fa57f_1))
130 #set ($legacyVisibilityDiscard = $legacyVisible2c943fa57f_1.add($legacyEntry2c943fa57f_1))
131 #end
132 #end
133 #set($rcDocumentNames = $legacyVisible2c943fa57f_1)
134 #else
135 ## No query criterion, perform the query as is.
136 #set ($legacyRaw2c943fa57f_2 = $services.query.hql($hqlQuery).setLimit($rcChangesNb).setOffset(0).execute())
137 #set ($legacyVisible2c943fa57f_2 = [])
138 #foreach ($legacyEntry2c943fa57f_2 in $legacyRaw2c943fa57f_2)
139 #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntry2c943fa57f_2))
140 #set ($legacyVisibilityDiscard = $legacyVisible2c943fa57f_2.add($legacyEntry2c943fa57f_2))
141 #end
142 #end
143 #set($rcDocumentNames = $legacyVisible2c943fa57f_2)
144 #end
145 #end
146 ##
147 ## Prepare comments handling
148 #set($commentsOrder = false)
149 #if($xwiki.getSpacePreferenceAsInt('commentsorder', 1) == 0)
150 #set($commentsOrder = true)
151 #end
152 ##
153 ## Comment handling macro.
154 ## Retreive page's last comment if any and
155 ## overwrite variables if this comment is the last modification on the page.
156 ##
157 #macro(handleComment $rcDoc $rcType $rcDt $commentsOrder)
158 ## Retrieve comments from last to first.
159 #set($rcComments = $rcDoc.getComments($commentsOrder))
160 #if($rcComments.size() > 0)
161 ## Retrieve last comment.
162 #set($lastComment = $listtool.get($rcComments, 0))
163 #set($lastCommentDate = $lastComment.getProperty("date").getValue())
164 ## If the last modification on the page is the comment, overwrite values.
165 ## We don't test compareTo() == 0 since the comment date and the save date may vary a little bit.
166 #if($lastCommentDate.compareTo($rcDt.toDate()) > -1 && $lastCommentDate.compareTo($rcDt.toDate()) <= 1)
167 #set($rcType = "comment")
168 #end
169 #end
170 #end
171 ##
172 ## Attachments handling macro.
173 ## Retrieve page's attachments and put those which upload matches the modification entry (author and timeframe)
174 ## in the $rcAttachments List.
175 ##
176 #macro(handleAttachments $rcDoc $rcAuthor $rcDt)
177 #set($attachments = $rcDoc.getAttachmentList())
178 #foreach($attachment in $attachments)
179 #set($attachmentDt = $xwiki.jodatime.getDateTime($attachment.getDate().getTime()))
180 #if($rcAuthor == $attachment.getAuthor() && $rcDt.getYear() == $attachmentDt.getYear() && $rcDt.getDayOfYear() == $attachmentDt.getDayOfYear())
181 #set($discard = $rcAttachments.add($attachment))
182 #end
183 #end
184 #end
185 ##
186 ##
187 ##
188 #macro(displayRcAuthor $author)
189 #useravatar($author)
190 <br/><span class="recentChangesAuthor">
191 #if($author == "XWikiGuest")
192 Guest
193 #else
194 #set($userName = $xwiki.getUserName($author))
195 #if($userName == "")
196 ## userName can be empty when the page has been saved without specifying the author.
197 ## We're printing a non-breaking space to ensure xhtml validity (ie: avoid empty paragraph).
198 &nbsp;
199 #else
200 $userName
201 #end
202 #end
203 </span>
204 #end
205 #macro(displayRcVersion $version)
206 #if($version == "1.1")
207 <span class="rcVersion">(<span class="newVersion">$msg.get("xe.recentchanges.entry.new")</span>)</span>
208 #end
209 #end
210
211 ##
212 ## Display the recent changes list.
213 ##
214 #set($previousDt = $xwiki.jodatime.getDateTime(0))
215 #set($discard = $previousDate.setTime(0))
216 #set($previousAuthor = "")
217 ## Get this very doc, useful when it is included from another one.
218 #set($recentChangesDoc = $xwiki.getDocument("Main.RecentChanges"))
219 {{html clean="false"}}
220 <table class="recentChanges" summary="$msg.get('xe.recentchanges.summary')">
221 <tr class="recentChangesHeader"><th scope="col">$msg.get("xe.recentchanges.column.authoranddate")</th><th scope="col">$msg.get("xe.recentchanges.column.changes")</th></tr>
222 #foreach ($rcDocName in $rcDocumentNames)
223 #set($row = "")
224 #set($rcAttachments = $util.arrayList)
225 ## Verify user access level on the document
226 #if ($xwiki.hasAccessLevel("view", $context.user, "${context.database}:${rcDocName}"))
227 #set($rcDoc = $xwiki.getDocument($rcDocName))
228 #set($rcType = "page")
229 #set($rcAuthor = $rcDoc.getAuthor()) ## TODO : check comments
230 #set($rcDt = $xwiki.jodatime.getDateTime($rcDoc.getDate().getTime()))
231 ## The handleComment macro overwrites rcType variable if the last modification is a comment.
232 #handleComment($rcDoc $rcType $rcDt $commentsOrder)
233 ## The handleAttachments macro put a list of attachments uploaded during the day by the author in $rcAttachments.
234 #handleAttachments($rcDoc $rcAuthor $rcDt)
235 #if($rcAuthor == $previousAuthor && $rcDt.getYear() == $previousDt.getYear() && $rcDt.getDayOfYear() == $previousDt.getDayOfYear())
236 ## Same day and author, continue in the same row.
237 #else
238 ## Different day or author, end previous row and start a new one.
239 #if($velocityCount > 1)</ul></td></tr>#end ## close previous row if needed
240 <tr><td class="recentChangesLeft">#displayRcAuthor($rcAuthor)<br/>
241 <span class="recentChangesDate">$xwiki.formatDate($rcDt.toDate(), "MMMM d")</span></td>
242 <td class="recentChangesRight"><ul class="xlist"> ## open next cell
243 #end
244 ## Compute a GUID for this modification with page name, modification date and author.
245 #set($modGUID = "${rcDoc.fullName}_${xwiki.formatDate($rcDt.toDate(), 'yyyyMMdd')}_${rcAuthor}")
246 ## Build the URL used to retreive the diff viewer URL
247 #set($goToDiffURL = $recentChangesDoc.getURL("view", "xpage=plain&amp;action=goToDiffURL&amp;page=${rcDoc.getFullName()}&amp;author=${rcAuthor}&amp;date=${xwiki.formatDate($rcDt.toDate(), 'yyyyMMdd')}&amp;rcShowMinor=${rcShowMinor}"))
248 <li class="xitem xunderline xhighlight ${rcType}">
249 <div class="xitemcontainer">
250 #if($rcType == "comment")
251 <div class="modifiedPage"><a href="$rcDoc.getURL()" title="$msg.get("xe.recentchanges.entry.comment.tooltip", [$xwiki.formatDate($rcDt.toDate(), "HH:mm")]) ">$xwiki.getXMLEncoded($rcDoc.getDisplayTitle())</a></div>
252 #if($rcShowDiff)
253 <div class="xshowonhover modifiedPageActions"><a class="ajax" href="$rcDoc.getURL("vire", "viewer=comments")" onclick="toggleClass(document.getElementById('$modGUID'), 'hidden'); toggleClass(document.getElementById('${modGUID}_comShow'), 'hidden'); toggleClass(document.getElementById('${modGUID}_comHide'), 'hidden'); return false;"><span id="${modGUID}_comShow">&#91;+&#93; $msg.get("xe.recentchanges.entry.comment.show")</span><span id="${modGUID}_comHide" class="hidden">&#91;-&#93; $msg.get("xe.recentchanges.entry.comment.hide")</span> $msg.get("xe.recentchanges.entry.comment")</a></div>
254 <div class="commentContainer hidden" id="$modGUID">
255 <div class="commentQuote lQuo">&nbsp;</div>
256 <div class="commentQuote rQuo">&nbsp;</div>
257 <div class="comment">
258 {{/html}}
259 $lastComment.get("comment")
260 {{html clean="false"}}
261 </div>
262 ## Display discussion link, this link point to the comments anchor.
263 <div class="commentAdd"><img src="$xwiki.getSkinFile("icons/silk/comment.gif")" alt="Reply icon" /> <a href="${rcDoc.getURL("view")}#Comments">$msg.get("xe.recentchanges.entry.comment.seediscussion")</a></div>
264 </div>
265 #end
266 #else
267 <div class="modifiedPage"><a href="$rcDoc.getURL()" title="$msg.get("xe.recentchanges.entry.page.tooltip", [$rcDoc.getVersion(), $xwiki.formatDate($rcDt.toDate())])">$xwiki.getXMLEncoded($rcDoc.getDisplayTitle())</a> #displayRcVersion($rcDoc.getVersion())</div>
268 #if($rcShowDiff)
269 <div class="xshowonhover modifiedPageActions"><a href="$goToDiffURL" title="$msg.get('xe.recentchanges.entry.page.seemodifications.title', [$rcDoc.fullName])">$msg.get("xe.recentchanges.entry.page.seemodifications")</a></div>
270 ## If the author has uploaded attachments during the day in this page, display them.
271 #if($rcAttachments.size() > 0)
272 <div class="attachmentContainer" id="$modGUID">
273 <ul>
274 #foreach($rcAttachment in $rcAttachments)
275 <li class="attachment"><a href="$rcDoc.getAttachmentURL($rcAttachment.filename)">$rcAttachment.filename</a> #displayRcVersion($rcAttachment.getVersion())</li>
276 #end
277 </ul>
278 </div>
279 #end
280 #end
281 #end
282 <div class="xspacer">&nbsp;</div>
283 </div>
284 </li>
285 #end
286 #set($previousAuthor = $rcAuthor)
287 #set($previousDt = $rcDt)
288 #end
289 ## Close last row if any.
290 #if($rcDocumentNames.size() > 1)</ul></td></tr>#end
291 </table>
292 {{/html}}
293 ##
294 ## Rebuild URL query string
295 ## Workaround until we fix $request.getQueryString()
296 ##
297 #set($queryString = "")
298 #set($paramMap = $request.getParameterMap())
299 #foreach($key in $paramMap.keySet())
300 #foreach($value in $paramMap.get($key))
301 #set($queryString = "${queryString}&amp;${key}=${value}")
302 #end
303 #end
304 ##
305 ## Provide links to display minor edits and RSS feed.
306 ##
307 #if($xwiki.hasMinorEdit())
308
309 {{html}}
310 <p class="recentChangesMoreActions">
311 #if($rcShowMinor)
312 <a href="$xwiki.getURL($tdoc.getFullName(), "view", $queryString.replaceAll('rcShowMinor=true', ''))"><img src="$xwiki.getSkinFile("icons/silk/zoom_out.gif")" alt="Hide minor icon"/>$msg.get("xe.recentchanges.hideminor")</a>
313 #else
314 <a href="$xwiki.getURL($tdoc.getFullName(), "view", "${queryString}&amp;rcShowMinor=true")"><img src="$xwiki.getSkinFile("icons/silk/zoom_in.gif")" alt="Show minor icon"/>$msg.get("xe.recentchanges.showminor")</a>
315 #end
316 #if($rcShowRss)
317 #set($rssURL = "")
318 #set($parameters = 'xpage=plain&amp;outputSyntax=plain')
319 #if($rcTag.size() > 0)
320 #set($parameters = "${parameters}&amp;tag=$listtool.get($rcTag, 0)")
321 #end
322 #if($rcSpace.size() > 0)
323 #set($parameters = "${parameters}&amp;space=$listtool.get($rcSpace, 0)")
324 #end
325 #set($rssURL = $xwiki.getURL('Main.WebRss', 'view', $parameters))
326 <a href="${rssURL}"><img src="$xwiki.getSkinFile("icons/silk/feed.gif")" alt="RSS icon"/>$msg.get("xe.recentchanges.rssfeed")</a>
327 #end
328 </p>
329 {{/html}}
330 #end
331 {{/velocity}}

#panelheader($msg.get("xe.panels.quicklinks"))

  • [DSSF 2008>DSSF2008.WebHome]
  • [DCNM 2009>DCNM2009.WebHome]
  • [HCCF 2010>HCCF2010.WebHome]
  • [$msg.get("xe.panels.quicklinks.index")>Main.AllDocs]
  • [$msg.get("xe.panels.quicklinks.sandbox")>Sandbox.WebHome]
    #if ($xwiki.hasAdminRights())
    <p><a href="$xwiki.getDocument("Panels.QuickLinks").getURL("inline")">$msg.get("xe.panels.edit")</a></p>
    #end
    #panelfooter()