Changes for page RecentlyUpdated

Last modified by Frank Fock on 2025/04/04 21:18

From version 1.1
edited by Frank Fock
on 2024/02/07 18:16
Change comment: Install extension [com.xwiki.pro:xwiki-pro-macros/1.14.3]
To version 4.1
edited by Frank Fock
on 2025/04/04 21:18
Change comment: Install extension [com.xwiki.pro:xwiki-pro-macros-ui/1.26.14]

Summary

Details

Page properties
Content
... ... @@ -6,17 +6,20 @@
6 6  = Parameters =
7 7  
8 8  |=Parameter|=Description|=Required|=Default
9 -|**types**|Comma-separated list of types ({{{ page }}}, {{{ blogpost }}}, {{{ comment }}} or {{{ attachment }}}), possibly prefixed with "-".|No|//all types//
10 -|**spaces**|Comma-separated list of spaces, possibly prefixed with "+" or "-", or special value like {{{ @self }}}, {{{ @global }}} or {{{ @all }}}.|No|{{{ @self }}}
11 -|**author**|Comma-separated list of authors.|No|
12 -|**labels**|Comma-separated list of tags, possibly prefixed with "+" or "-".|No|
9 +|**types**|Select one or multiple content types. The macro will display only the content of the type you specify here.|No|//all types//
10 +|**spaces**|Select one or multiple spaces. The macro will display only the documents present in the selected spaces.|No|{{{@self}}}
11 +|**author**|Comma-separated list of authors.|No|
12 +|**labels**|Comma-separated list of tags.|No|
13 +|**excludedLabels**|Comma-separated list of tags.|No|
13 13  |**max**|Maximum number of results.|No| {{{ 15 }}}
14 14  |**theme**|Appearance of the macro ({{{ concise }}}, {{{ social }}}, {{{ sidebar }}}).|No| {{{ concise }}}
15 15  |**width**|Width of the macro in percentage.|No| {{{ 100% }}}
16 16  |**hideHeading**|Whether to hide the text "Recently Updated" as title|No| {{{ false }}}
17 17  |**showProfilePic**|Whether to show the profile picture of users|No| {{{ false }}}
19 +|**currentWiki**|If this parameter is selected then the spaces & excluded spaces parameters are ignored and the macro will display the documents from the current wiki.|No| {{{ false}}}
20 +|**excludedSpaces**|Select one or multiple spaces. The macro will not display the documents present in the selected spaces.|No|
21 +|**global**|If this parameter is selected then spaces, excluded spaces and the current wiki parameters are ignored and the macro will display the documents from the current wiki and subwikis. |No| {{{ false}}}
18 18  
19 -
20 20  = Example Usage =
21 21  
22 22  {{code}}
XWiki.WikiMacroClass[0]
Macro code
... ... @@ -8,52 +8,6 @@
8 8  ## Parameter formatting macros
9 9  ## -----------------------------------------------------------------
10 10  
11 -## Format serialized comma-separated list coming from macro parameters
12 -## so that it can be used inside a solr filter query parameter
13 -## * Escape spaces inside values by wrapping them inside quotes,
14 -## making sure "+" and "-" filter modifiers stay outside the quotes
15 -## * Remove commas so that values are separated only by spaces
16 -#macro (formatSerializedList $serializedList $return)
17 - ## Wrap each value around quotes and replace commas by spaces
18 - ## (adds extra quotes / spaces at the beginning and end of the string)
19 - #set ($searchRegex = '(?:^|$|,)\s*([-+]?)')
20 - #set ($replacement = '" $1"')
21 - #if (!$serializedList)
22 - #set($serializedList = "")
23 - #end
24 - #set ($formatted = $serializedList.replace($searchRegex, $replacement))
25 - ## Remove extra quotes / spaces at the beginning and end of the string
26 - #set ($formatted = $!stringtool.substring($formatted, 2, -2))
27 - ## Return
28 - #set ($return = $NULL)
29 - #setVariable("$return" $formatted)
30 -#end
31 -
32 -## Format serialized comma-separated author list coming from macro parameters
33 -## Author format is different between comments and document metadata
34 -## ("xwiki:" wiki prefix is missing from comments author metadata),
35 -## so add both versions in the formatted serialized list
36 -#macro (formatSerializedAuthorList $serializedAuthorList $return)
37 - #set ($authorsList = [])
38 - #set ($splittedAuthorList = $!stringtool.split($serializedAuthorList, ','))
39 - #foreach ($author in $splittedAuthorList)
40 - #set ($author = $!stringtool.strip($author))
41 - #set ($modifier = '')
42 - #if ($author.startsWith('-'))
43 - #set ($modifier = '-')
44 - #set ($author = $author.substring(1))
45 - #end
46 - #set ($resolvedAuthor = $services.model.resolveDocument($author))
47 - #set ($discard = $authorsList.add("${modifier}${author}"))
48 - #set ($discard = $authorsList.add("${modifier}${services.model.serialize($resolvedAuthor, 'default')}"))
49 - #end
50 - #set ($authors = $!stringtool.join($authorsList, ','))
51 - #formatSerializedList($authors, $authors)
52 - ## Return
53 - #set ($return = $NULL)
54 - #setVariable("$return" $authors)
55 -#end
56 -
57 57  ## Format serialized comma-separated types list coming from macro parameters
58 58  ## Return a list containing all the types of results that need to be displayed
59 59  #macro (parseTypes $serializedTypeList $return)
... ... @@ -89,6 +89,60 @@
89 89   #setVariable("$return" $types)
90 90  #end
91 91  
46 +## Creates the final space parameter. ConfluenceSpaces comes from migreations and is a mix of prefixed(+/-) spaces and excludedSpaces comes
47 +## from XWiki and are the spaces that should be excluded when doing the solr query.
48 +#macro (constructSpaceParameter $confluenceSpaces, $excludedSpaces)
49 + #set ($exclude = "")
50 + #foreach ($excludedSpace in $excludedSpaces.split(","))
51 + #if (!$excludedSpace.trim().isBlank())
52 + #if ($foreach.first)
53 + #set ($exclude = "-$excludedSpace")
54 + #else
55 + #set ($exclude = "$exclude,-$excludedSpace")
56 + #end
57 + #end
58 + #end
59 + #if (!$confluenceSpaces.trim().isEmpty() && !$exclude.trim().isEmpty())
60 + #set ($finalSpace = "${confluenceSpaces},${exclude}")
61 + #elseif(!$confluenceSpaces.trim().isEmpty())
62 + #set ($finalSpace = $confluenceSpaces)
63 + #else
64 + #set ($finalSpace = $exclude)
65 + #end
66 +#end
67 +
68 +## Determine if the search should be done in the currentWiki, globally or only on specific spaces.
69 +#macro (determinateSpaceScope $confluenceSpacesString)
70 + ## If the global parameter is marked then we set the search to everywhere, if the currentWiki is marked then we select the current wiki
71 + ## otherwise we just the actual space selected.
72 + #if ($xcontext.macro.params.global == "true")
73 + #set ($confluenceSpacesString = '@all')
74 + #elseif ($xcontext.macro.params.currentWiki == "true")
75 + #set ($confluenceSpacesString = '@global')
76 + #end
77 +#end
78 +
79 +## Handles the construction of the tags parameter.
80 +#macro (constructTagsParameter $confluenceTags, $excludedTags)
81 + #set ($exclude = "")
82 + #foreach ($excludedSpace in $excludedTags.split(","))
83 + #if (!$excludedSpace.trim().isBlank())
84 + #if ($foreach.first)
85 + #set ($exclude = "-$excludedSpace")
86 + #else
87 + #set ($exclude = "$exclude,-$excludedSpace")
88 + #end
89 + #end
90 + #end
91 + #if (!$confluenceTags.trim().isEmpty() && !$exclude.trim().isEmpty())
92 + #set ($finalTags = "${confluenceTags},${exclude}")
93 + #elseif (!$confluenceTags.trim().isEmpty())
94 + #set ($finalTags = $confluenceTags)
95 + #else
96 + #set ($finalTags = $exclude)
97 + #end
98 +#end
99 +
92 92  ## Init options from macro parameters
93 93  #macro (initOptionsFromParameters $return)
94 94   ## Gather every parameter in an option object that will be returned
... ... @@ -100,19 +100,19 @@
100 100   #end
101 101  
102 102   ## Authors
103 - #set ($confluenceAuthorsString = "$!stringtool.strip($!wikimacro.parameters.author)")
104 - #formatSerializedAuthorList($confluenceAuthorsString, $authors)
105 - #set ($options.authors = $authors)
106 -
111 + #set ($options.authors = "$!stringtool.strip($!stringtool.join($!wikimacro.parameters.author, ','))")
107 107   ## Wiki & Spaces
108 - #set ($confluenceSpacesString = "$!stringtool.strip($!wikimacro.parameters.spaces)")
113 + #set ($excludedSpaces = "$!xcontext.macro.params.excludedSpaces")
114 + #set ($confluenceSpacesString = "$!stringtool.strip($!xcontext.macro.params.spaces)")
109 109   #set ($options.spaces = $NULL)
110 110   #set ($options.wiki = $doc.wiki)
117 + #determinateSpaceScope($confluenceSpacesString)
111 111   #if (
112 112   $confluenceSpacesString.equals('')
113 113   || $confluenceSpacesString.equals('@self')
114 114   )
115 115   ## Search in current space
123 + ## Newly migrated content don't have @self, see https://jira.xwiki.org/projects/CONFLUENCE/issues/CONFLUENCE-236
116 116   #set ($options.spaces = $doc.space)
117 117   #elseif (
118 118   $confluenceSpacesString.equals('@global')
... ... @@ -132,17 +132,16 @@
132 132   #set ($options.wiki = $NULL)
133 133   #else
134 134   ## Search in specified spaces
135 - #formatSerializedList($confluenceSpacesString, $spaces)
136 - #set ($options.spaces = $spaces)
143 + #constructSpaceParameter($confluenceSpacesString, $excludedSpaces)
144 + #set ($options.spaces = $finalSpace)
137 137   #end
138 138  
139 139   ## Tags
140 - #set ($confluenceLabelString = "$!stringtool.strip($!wikimacro.parameters.labels)")
141 - #formatSerializedList($confluenceLabelString, $tags)
142 - #set ($options.tags = $tags)
148 + #constructTagsParameter("$!stringtool.strip($!xcontext.macro.params.labels)", "$!stringtool.strip($!xcontext.macro.params.excludedLabels)")
149 + #set ($options.tags = $finalTags)
143 143  
144 144   ## Types
145 - #set ($confluenceTypesString = "$!stringtool.strip($!wikimacro.parameters.types)")
152 + #set ($confluenceTypesString = "$!stringtool.strip($!xcontext.macro.params.types)")
146 146   #parseTypes($confluenceTypesString, $types)
147 147   #set ($options.types = $types)
148 148  
... ... @@ -202,18 +202,14 @@
202 202  #end
203 203  {{/velocity}}
204 204  
205 -{{include reference="Licenses.Code.VelocityMacros"/}}
206 -
207 207  {{velocity}}
208 208  ## We need to check if there is a valid license because the macro is registered even if the user doesn't have view right
209 209  ## on the macro definition page. See XWIKI-14828: Rendering macros defined in wiki pages are available to users that
210 210  ## don't have view right on those pages.
211 -#if ($services.licensing.licensor.hasLicensureForEntity($xcontext.macro.doc.documentReference))
216 +#if ($services.promacrolicensing.hasLicensureForEntity($xcontext.macro.doc.documentReference))
212 212   #executeMacro
213 213  #else
214 - {{error}}
215 - #getMissingLicenseMessage('proMacros.extension.name')
216 - {{/error}}
219 + {{missingLicenseMessage extensionName="proMacros.extension.name"/}}
217 217  #end
218 218  {{/velocity}}
219 219  
Macro description
... ... @@ -1,1 +1,0 @@
1 -Add the Recently Updated macro to a page to show a list of pages, blogs, files, and comments that have been created or edited recently. This is great for project landing, information pages, or team space home pages. It's very flexible, you can limit the list to specific people, spaces, types of content, and more.
Default categories
... ... @@ -1,0 +1,1 @@
1 +Content
XWiki.WikiMacroParameterClass[0]
Parameter description
... ... @@ -1,1 +1,0 @@
1 -Filter the results by author. The macro will display only the pages etc which were last modified by the author(s) you specify here. You can specify multiple users.
Parameter type
... ... @@ -1,1 +1,1 @@
1 -java.lang.String
1 +com.xwiki.macros.internal.userlist.UserReferenceList
XWiki.WikiMacroParameterClass[1]
Parameter description
... ... @@ -1,1 +1,0 @@
1 -This parameter allows you to filter content by space. The macro will display only the pages etc which belong to the space(s) you specify here. You can specify one or more space keys, separated by a comma or a space. To exclude content in a specific space, put a minus sign (-) immediately in front of that space key. For example: If you specify a space key of -BADSPACE you will get only content which is not in the BADSPACE. To indicate that the results must come from a specific space, put a plus sign (+) immediately in front of that space key. For example: If you specify a space key of +GOODSPACE you will get only content in GOODSPACE. (Note that this is not particularly useful, because each content item belongs to one space only. If you put a plus sign next to one space key and list other space keys too, the other space keys will be ignored.) Special values: "@self" - the current space, "@global" - all spaces in wiki, "@all" or "*" - all spaces in every wiki
Parameter type
... ... @@ -1,1 +1,1 @@
1 -java.lang.String
1 +com.xwiki.pickers.SuggestSpacesReference
XWiki.WikiMacroParameterClass[2]
Parameter description
... ... @@ -1,1 +1,0 @@
1 -Filter the results by label. The macro will display only the pages etc which are tagged with the label(s) you specify here. You can specify one or more label values, separated by a comma or a space. To exclude content which matches a given label, put a minus sign (-) immediately in front of that label value. For example: If you specify a label value of -badpage you will get only content which is not labeled with 'badpage'. To indicate that the results** **must match a given label value, put a plus sign (+) immediately in front of that label value. For example: If you specify a label value of +superpage,+goodpage you will get only content which has at least two labels, being 'superpage' and 'goodpage'. The labels parameter only applies to the page and blog content types.
Parameter type
... ... @@ -1,1 +1,1 @@
1 -java.lang.String
1 +com.xwiki.pickers.TagsReference
XWiki.WikiMacroParameterClass[3]
Parameter description
... ... @@ -1,1 +1,0 @@
1 -Specify the width of the macro display, as a percentage of the window width.
XWiki.WikiMacroParameterClass[4]
Parameter description
... ... @@ -1,1 +1,0 @@
1 -This parameter allows you to filter content by content type. The macro will display only the content of the type you specify here. You can specify one or more types, separated by a comma or a space. To exclude content of a given content type, put a minus sign (-) immediately in front of that content type. For example: If you specify a content type of -blogpost you will get pages and all other content except for blog posts. Available values: "page" - documents, "blogpost" or "news" - blogpost documents, "comment" - comments on documents, "attachment" - attachments
Parameter type
... ... @@ -1,1 +1,1 @@
1 -java.lang.String
1 +com.xwiki.pickers.recentlyupdated.RecentlyUpdateType
XWiki.WikiMacroParameterClass[5]
Parameter description
... ... @@ -1,1 +1,0 @@
1 -Specify the maximum number of results to be displayed. If this parameter is omitted, then a maximum of 15 results are displayed.
XWiki.WikiMacroParameterClass[6]
Parameter description
... ... @@ -1,1 +1,0 @@
1 -Choose the appearance of this macro: "concise" - the default list, showing the names of pages which were updated or commented on, the users who made the page modifications and time when the modifications occurred. "social" - lists recent modifications in reverse chronological order, but groups them by user into short time segments. A 'sub' list appears within each user's time segment, showing the names of pages which they updated or commented on and time when these modifications occurred. "sidebar" - lists recent updates in reverse chronological order, showing the names of pages which were updated or commented on and time when the page modifications occurred. This theme does not show authorship.
Parameter type
... ... @@ -1,1 +1,1 @@
1 -java.lang.String
1 +com.xwiki.macros.internal.recentlyupdated.RecentlyUpdatedThemeEnum
XWiki.WikiMacroParameterClass[7]
Parameter description
... ... @@ -1,1 +1,0 @@
1 -Specify "showProfilePic=true" to display the profile pictures of the users who updated the content.
XWiki.WikiMacroParameterClass[8]
Parameter description
... ... @@ -1,1 +1,0 @@
1 -Determines whether the macro hides or displays the text 'Recently Updated' as a title above the list of content. Only available in wikimarkup and storage format. Accepted values: "true" - Title is hidden, "false" - Title is shown.
XWiki.WikiMacroParameterClass[9]
Parameter name
... ... @@ -1,0 +1,1 @@
1 +excludedLabels
Parameter type
... ... @@ -1,0 +1,1 @@
1 +com.xwiki.pickers.TagsReference
XWiki.WikiMacroParameterClass[10]
Parameter default value
... ... @@ -1,0 +1,1 @@
1 +false
Parameter name
... ... @@ -1,0 +1,1 @@
1 +global
Parameter type
... ... @@ -1,0 +1,1 @@
1 +java.lang.Boolean
Parameter mandatory
... ... @@ -1,0 +1,1 @@
1 +No
XWiki.WikiMacroParameterClass[11]
Parameter default value
... ... @@ -1,0 +1,1 @@
1 +false
Parameter name
... ... @@ -1,0 +1,1 @@
1 +currentWiki
Parameter type
... ... @@ -1,0 +1,1 @@
1 +java.lang.Boolean
Parameter mandatory
... ... @@ -1,0 +1,1 @@
1 +No
XWiki.WikiMacroParameterClass[12]
Parameter name
... ... @@ -1,0 +1,1 @@
1 +excludedSpaces
Parameter type
... ... @@ -1,0 +1,1 @@
1 +com.xwiki.pickers.SuggestSpacesReference