Changes for page Macros for the Blog application
on 2026/12/02 00:14
Summary
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. Admin1 +XWiki.superadmin - Content
-
... ... @@ -1,4 +1,4 @@ 1 -{{include document="Blog.BlogParameters"/}} 1 +{{include document="Blog.BlogParameters" author="target" /}} 2 2 3 3 {{velocity output="false"}} 4 4 ## ... ... @@ -75,7 +75,14 @@ 75 75 #set($blogDoc = $xwiki.getDocument("${space}.Blog")) 76 76 #if(!$blogDoc.getObject($blogClassname)) 77 77 ## Third, try searching for a blog document in the current space 78 - #set($blogDocs = $xwiki.searchDocuments(", BaseObject obj where doc.space = ? and obj.name = doc.fullName and obj.className = '$blogClassname' order by doc.name", 1, 0, [${space}])) 78 +#set ($legacyRawf3cf9e4833_1 = $services.query.hql(", BaseObject obj where doc.space = ? and obj.name = doc.fullName and obj.className = '$blogClassname' order by doc.name").setLimit(1).setOffset(0).bindValues([${space}]).execute()) 79 +#set ($legacyVisiblef3cf9e4833_1 = []) 80 +#foreach ($legacyEntryf3cf9e4833_1 in $legacyRawf3cf9e4833_1) 81 + #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryf3cf9e4833_1)) 82 + #set ($legacyVisibilityDiscard = $legacyVisiblef3cf9e4833_1.add($legacyEntryf3cf9e4833_1)) 83 + #end 84 +#end 85 + #set($blogDocs = $legacyVisiblef3cf9e4833_1) 79 79 #if($blogDocs.size() > 0) 80 80 #set($blogDoc = $xwiki.getDocument($blogDocs.get(0))) 81 81 #else ... ... @@ -159,8 +159,15 @@ 159 159 #set($defaultItemsPerPage = $util.parseInt($defaultItemsPerPage)) 160 160 ## This macro is defined in the default macros.vm library. It also sets $itemsPerPage and $startAt. 161 161 #preparePagedViewParams($totalEntries $defaultItemsPerPage) 162 - #set($entries = $xwiki.searchDocuments("${query} order by publishDate.value desc", $itemsPerPage, $startAt)) 169 +#set ($legacyRawf3cf9e4833_2 = $services.query.hql("${query} order by publishDate.value desc").setLimit($itemsPerPage).setOffset($startAt).execute()) 170 +#set ($legacyVisiblef3cf9e4833_2 = []) 171 +#foreach ($legacyEntryf3cf9e4833_2 in $legacyRawf3cf9e4833_2) 172 + #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryf3cf9e4833_2)) 173 + #set ($legacyVisibilityDiscard = $legacyVisiblef3cf9e4833_2.add($legacyEntryf3cf9e4833_2)) 174 + #end 163 163 #end 176 + #set($entries = $legacyVisiblef3cf9e4833_2) 177 +#end 164 164 ## 165 165 ## 166 166 ## ... ... @@ -181,8 +181,15 @@ 181 181 #set($maxDay = $dateFormatter.print($weekDate.toMutableDateTime().weekOfWeekyear().roundCeiling())) 182 182 #set($query = "${query} and publishDate.value >= '$minDay' and publishDate.value < '$maxDay'") 183 183 #set($totalEntries = $xwiki.countDocuments(${query})) 184 - #set($entries = $xwiki.searchDocuments("${query} order by publishDate.value desc")) 198 +#set ($legacyRawf3cf9e4833_3 = $services.query.hql("${query} order by publishDate.value desc").execute()) 199 +#set ($legacyVisiblef3cf9e4833_3 = []) 200 +#foreach ($legacyEntryf3cf9e4833_3 in $legacyRawf3cf9e4833_3) 201 + #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryf3cf9e4833_3)) 202 + #set ($legacyVisibilityDiscard = $legacyVisiblef3cf9e4833_3.add($legacyEntryf3cf9e4833_3)) 203 + #end 185 185 #end 205 + #set($entries = $legacyVisiblef3cf9e4833_3) 206 +#end 186 186 ## 187 187 ## 188 188 ## ... ... @@ -203,8 +203,15 @@ 203 203 #set($maxDay = $dateFormatter.print($monthDate.toMutableDateTime().monthOfYear().roundCeiling())) 204 204 #set($query = "${query} and publishDate.value >= '$minDay' and publishDate.value < '$maxDay'") 205 205 #set($totalEntries = $xwiki.countDocuments(${query})) 206 - #set($entries = $xwiki.searchDocuments("${query} order by publishDate.value desc")) 227 +#set ($legacyRawf3cf9e4833_4 = $services.query.hql("${query} order by publishDate.value desc").execute()) 228 +#set ($legacyVisiblef3cf9e4833_4 = []) 229 +#foreach ($legacyEntryf3cf9e4833_4 in $legacyRawf3cf9e4833_4) 230 + #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryf3cf9e4833_4)) 231 + #set ($legacyVisibilityDiscard = $legacyVisiblef3cf9e4833_4.add($legacyEntryf3cf9e4833_4)) 232 + #end 207 207 #end 234 + #set($entries = $legacyVisiblef3cf9e4833_4) 235 +#end 208 208 ## 209 209 ## 210 210 ## ... ... @@ -218,8 +218,15 @@ 218 218 *### 219 219 #macro(getAllBlogEntries $blogDoc $query $entries) 220 220 #set($totalEntries = $xwiki.countDocuments(${query})) 221 - #set($entries = $xwiki.searchDocuments("${query} order by publishDate.value desc")) 249 +#set ($legacyRawf3cf9e4833_5 = $services.query.hql("${query} order by publishDate.value desc").execute()) 250 +#set ($legacyVisiblef3cf9e4833_5 = []) 251 +#foreach ($legacyEntryf3cf9e4833_5 in $legacyRawf3cf9e4833_5) 252 + #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryf3cf9e4833_5)) 253 + #set ($legacyVisibilityDiscard = $legacyVisiblef3cf9e4833_5.add($legacyEntryf3cf9e4833_5)) 254 + #end 222 222 #end 256 + #set($entries = $legacyVisiblef3cf9e4833_5) 257 +#end 223 223 ## 224 224 ## 225 225 ## ... ... @@ -234,8 +234,15 @@ 234 234 #macro(getUnpublishedBlogEntries $blogDoc $query $entries) 235 235 #set($query = "${query} and isPublished.value = 0") 236 236 #set($totalEntries = $xwiki.countDocuments(${query})) 237 - #set($entries = $xwiki.searchDocuments("${query} order by publishDate.value desc")) 272 +#set ($legacyRawf3cf9e4833_6 = $services.query.hql("${query} order by publishDate.value desc").execute()) 273 +#set ($legacyVisiblef3cf9e4833_6 = []) 274 +#foreach ($legacyEntryf3cf9e4833_6 in $legacyRawf3cf9e4833_6) 275 + #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryf3cf9e4833_6)) 276 + #set ($legacyVisibilityDiscard = $legacyVisiblef3cf9e4833_6.add($legacyEntryf3cf9e4833_6)) 277 + #end 238 238 #end 279 + #set($entries = $legacyVisiblef3cf9e4833_6) 280 +#end 239 239 ## 240 240 ## 241 241 ## ... ... @@ -250,8 +250,15 @@ 250 250 #set($defaultItemsPerPage = 20) 251 251 ## This macro is defined in the default macros.vm library. It also sets $itemsPerPage and $startAt. 252 252 #preparePagedViewParams($totalEntries $defaultItemsPerPage) 253 - #set($entries = $xwiki.searchDocuments("${query} order by publishDate.value desc", $itemsPerPage, $startAt)) 295 +#set ($legacyRawf3cf9e4833_7 = $services.query.hql("${query} order by publishDate.value desc").setLimit($itemsPerPage).setOffset($startAt).execute()) 296 +#set ($legacyVisiblef3cf9e4833_7 = []) 297 +#foreach ($legacyEntryf3cf9e4833_7 in $legacyRawf3cf9e4833_7) 298 + #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryf3cf9e4833_7)) 299 + #set ($legacyVisibilityDiscard = $legacyVisiblef3cf9e4833_7.add($legacyEntryf3cf9e4833_7)) 300 + #end 254 254 #end 302 + #set($entries = $legacyVisiblef3cf9e4833_7) 303 +#end 255 255 ## 256 256 ## 257 257 ## ... ... @@ -262,13 +262,7 @@ 262 262 * @param query The basic query for selecting blog entries. 263 263 *### 264 264 #macro(getBlogEntriesBaseQuery $query) 265 - #set ($query = ", BaseObject obj, IntegerProperty isPublished, IntegerProperty hidden, DateProperty publishDate 266 - where doc.fullName <> '${blogPostTemplate}' and 267 - obj.name = doc.fullName and obj.className = '${blogPostClassname}' and 268 - publishDate.id.id = obj.id and publishDate.id.name = 'publishDate' and 269 - isPublished.id.id = obj.id and isPublished.id.name = 'published' and 270 - hidden.id.id = obj.id and hidden.id.name = 'hidden' and 271 - (doc.creator = '$context.user' or (isPublished.value = 1 and hidden.value = 0))") 314 + #getAllBlogPostsQuery($query) 272 272 #end 273 273 ## 274 274 ## ... ... @@ -572,6 +572,7 @@ 572 572 * @param onlyExtract If <tt>true</tt>, try to display only a summary of the entry, instead of the full content. 573 573 *### 574 574 #macro(displayEntryContent $entryDoc $entryObj $onlyExtract) 618 + #set($entryContent = '') 575 575 <div class="#if($onlyExtract)entry-summary#{else}entry-content#end"> 576 576 #getEntryContent($entryDoc $entryObj $onlyExtract $entryContent) 577 577 {{html wiki="false"}}$entryDoc.getRenderedContent($entryContent, $entryDoc.getSyntax().toIdString()){{/html}} ... ... @@ -797,4 +797,194 @@ 797 797 #set($propertyValue = $defaultValue) 798 798 #end 799 799 #end 844 + 845 +## Compatibility helpers from the installed Blog 9.15.15 package. 846 +#macro(bindQueryParameters $queryObj $queryParams) 847 + #set ($output = $queryObj) 848 + #foreach( $key in $queryParams.keySet() ) 849 + #set($output = $queryObj.bindValue($key, $queryParams.get($key))) 850 + #end 851 + #setVariable("$queryObj" $output) 852 +#end 853 + 854 +#macro(blog__actionResponseError $status $text $parameters) 855 + $response.setStatus($status) 856 + #if($request.ajax) 857 + $services.localization.render($text, $!parameters) 858 + #else 859 + {{error}}$services.localization.render($text, $!parameters){{/error}} 860 + #end 861 +#end 862 + 863 +#macro(displayBlogPostsBasedOnContext $targetDoc $postsVisiblity $layout $layoutParams $limit) 864 + #if ($layout == 'link') 865 + #set ($macro.paginated = 'no') 866 + #end 867 + #if ($targetDoc.space == $defaultBlogSpace && !$targetDoc.getObject($blogCategoryClassname)) 868 + ## Display all posts that are in the default blog space('Blog') or in category 'Blog.%' 869 + #getBlogPostsLayout($xwiki.getDocument("${defaultBlogSpace}.WebHome") $postsLayout) 870 + #if ("$!layout" == '') 871 + #set ($layout = $postsLayout) 872 + #end 873 + #if ($postsVisiblity == 'recent') 874 + {{blogpostlist blog="${defaultBlogSpace.replaceAll('~', '~~').replaceAll('"', '~"')}.WebHome" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} 875 + #elseif($postsVisiblity == 'unpublished') 876 + {{blogpostlist blog="${defaultBlogSpace.replaceAll('~', '~~').replaceAll('"', '~"')}.WebHome" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} 877 + #end 878 + #elseif($targetDoc.getObject($blogCategoryClassname)) 879 + ## Display all posts that are in a category aCategorySpace.aCategory 880 + #getBlogDocumentForCategoriesSpace($targetDoc.space $blogDoc) 881 + #getBlogPostsLayout($blogDoc $postsLayout) 882 + #if ("$!layout" == '') 883 + #set ($layout = $postsLayout) 884 + #end 885 + #if ($postsVisiblity == 'recent') 886 + {{blogpostlist category="$targetDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} 887 + #elseif($postsVisiblity == 'unpublished') 888 + {{blogpostlist category="$targetDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} 889 + #end 890 + #elseif($targetDoc.getObject('XWiki.DocumentSheetBinding').sheet == 'Blog.CategoriesSheet') 891 + ## Display all posts that are in a category aCategorySpace.% 892 + #getBlogDocumentForCategoriesSpace($targetDoc.space $blogDoc) 893 + #getBlogPostsLayout($blogDoc $postsLayout) 894 + #if ("$!layout" == '') 895 + #set ($layout = $postsLayout) 896 + #end 897 + #if ($postsVisiblity == 'recent') 898 + {{blogpostlist category="$targetDoc.space.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} 899 + #elseif($postsVisiblity == 'unpublished') 900 + {{blogpostlist category="$targetDoc.space.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} 901 + #end 902 + #else 903 + ## Display all posts in blog space aBlog 904 + #getBlogDocument($targetDoc.space $blogDoc) 905 + #getBlogPostsLayout($blogDoc $postsLayout) 906 + #if ("$!layout" == '') 907 + #set ($layout = $postsLayout) 908 + #end 909 + #if ($postsVisiblity == 'recent') 910 + {{blogpostlist blog="$blogDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} 911 + #elseif($postsVisiblity == 'unpublished') 912 + {{blogpostlist blog="$blogDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} 913 + #end 914 + #end 915 +#end 916 + 917 +#macro(displayEntryBlogLocation $entryDoc $entryObj) 918 + #getBlogPostsLocation($entryDoc.getSpace() $blogPostsLocation) ## 919 + #if("$!blogPostsLocation" != "") ## 920 + #set($blogSpaceRef = $services.model.resolveSpace($blogPostsLocation)) ## 921 + #set($blogDocRef = $services.model.createDocumentReference($services.model.getEntityReference('DOCUMENT', 'default').getName(), $blogSpaceRef)) ## 922 + #if($doc.documentReference != $blogDocRef) ## 923 + #set($blogDoc = $xwiki.getDocument($blogDocRef)) ## 924 + #set($blogObj = $blogDoc.getObject('Blog.BlogClass')) ## 925 + #if($blogObj) (% class="blogrefpath" %)((( ## 926 + $services.localization.render('blog.code.postedin') {{html clean="false" wiki="false"}} #hierarchy($blogDocRef, {'selfIsActive' : true, 'local': true}) {{/html}} ## 927 + )))(%%)## 928 + #end 929 + #end 930 + #end 931 +#end 932 + 933 +#macro(getAllBlogPostsQuery $query) 934 + #set ($query = $NULL) 935 + #setVariable("$query" ", BaseObject as obj, IntegerProperty isPublished, 936 + IntegerProperty hidden, DateProperty publishDate 937 + where doc.fullName <> '$blogPostTemplate' and 938 + obj.name=doc.fullName and obj.className='$blogPostClassname' and 939 + isPublished.id.id = obj.id and isPublished.id.name = 'published' and 940 + hidden.id.id = obj.id and hidden.id.name='hidden' and 941 + publishDate.id.id = obj.id and publishDate.id.name='publishDate' and 942 + (doc.creator = '$escapetool.sql($xcontext.user)' or (isPublished.value = 1 and hidden.value = 0))") 943 +#end 944 + 945 +#macro(getAllBlogPostsQueryBasedOnDisplayContext $targetDoc $query $queryParams) 946 + #set ($query = $NULL) 947 + #set ($queryParams = $NULL) 948 + #getCategoryAllBlogPostsQuery($resultQuery) 949 + #set ($resultQueryParams = {}) 950 + #set($sanitizedSpace = $targetDoc.space.replaceAll('([%_!])', '!$1').concat('.%')) 951 + #if ($targetDoc.space == $defaultBlogSpace && !$targetDoc.getObject($blogCategoryClassname)) 952 + ## Get all posts that are in the default blog space('Blog') or in category 'Blog.%' 953 + #set ($discard = $resultQueryParams.put('space', $targetDoc.space)) 954 + #set ($discard = $resultQueryParams.put('catList', $sanitizedSpace)) 955 + #set($resultQuery = "${resultQuery} and (doc.space = :space or catList like :catList escape '!')") 956 + #elseif($targetDoc.getObject($blogCategoryClassname)) 957 + ## Get all posts that are in a category aCategorySpace.aCategory 958 + #set ($discard = $resultQueryParams.put('catList', $targetDoc.fullName)) 959 + #set($resultQuery = "${resultQuery} and (catList=:catList)") 960 + #elseif($targetDoc.getObject('XWiki.DocumentSheetBinding').sheet == 'Blog.CategoriesSheet') 961 + ## Get all posts that are in a category aCategorySpace.% 962 + #set ($discard = $resultQueryParams.put('catList', $sanitizedSpace)) 963 + ## Exclude incategorized posts 964 + #set ($excludedCategory = "${targetDoc.space}.WebHome") 965 + #if ($targetDoc.space == $defaultBlogSpace) 966 + #set ($excludedCategory = "Blog.Categories.WebHome") 967 + #end 968 + #set ($discard = $resultQueryParams.put('excludedCategory', $excludedCategory)) 969 + #set($resultQuery = "${resultQuery} and (catList<>:excludedCategory) and (catList like :catList escape '!')") 970 + #else 971 + ## Get all posts in blog space aBlog 972 + #getAllBlogPostsQuery($resultQuery) 973 + #getBlogPostsLocation($targetDoc.space $postsLocation) 974 + #set ($discard = $resultQueryParams.put('space', $postsLocation)) 975 + #set($resultQuery = "${resultQuery} and doc.space = :space") 976 + #end 977 + #setVariable("$query" $resultQuery) 978 + #setVariable("$queryParams" $resultQueryParams) 979 +#end 980 + 981 +#macro(getBlogCategoriesLocation $blogSpace $categoriesLocation) 982 + #getBlogDocument($blogSpace $blogDoc) 983 + ## Since 9.15, category data may exist in Blog or Blog.Categories. Code supports both paths to maintain backward compatibility. 984 + #set ($defaultBlogCategoryLocation = 'Blog.Categories') 985 + #if ($services.blog.hasLegacyCategoryAssignments()) 986 + #set ($defaultBlogCategoryLocation = 'Blog') 987 + #end 988 + #getBlogProperty($blogDoc 'categoriesLocation' $defaultBlogCategoryLocation $result) 989 + #set ($postsLocation = $NULL) 990 + #setVariable ("$categoriesLocation" $result) 991 +#end 992 + 993 +#macro(getBlogDocumentForCategoriesSpace $categoriesSpace $blogDoc) 994 + #set($macro.blogDocs = $services.query.hql(", BaseObject obj, StringProperty as categoriesLocationProp where obj.name = doc.fullName and obj.className = '$blogClassname' and obj.id=categoriesLocationProp.id.id and categoriesLocationProp.id.name='categoriesLocation' and categoriesLocationProp.value=:categoriesLocation order by doc.creationDate").setLimit(1).setOffset(0).bindValue('categoriesLocation', $categoriesSpace).execute()) 995 + #if($macro.blogDocs.size() > 0 && $categoriesSpace != $defaultBlogSpace) 996 + #set($macro.result = $xwiki.getDocument($macro.blogDocs.get(0))) 997 + #else 998 + ## Fallback to Blog.WebHome, the default blog 999 + #set($macro.result = $xwiki.getDocument('Blog.WebHome')) 1000 + #end 1001 + #set ($blogDoc = $NULL) 1002 + #setVariable ("$blogDoc" $macro.result) 1003 +#end 1004 + 1005 +#macro(getBlogPostsLayout $blogDoc $postsLayout) 1006 + #getBlogProperty($blogDoc 'postsLayout' 'full' $res) 1007 + #set ($postsLayout = $NULL) 1008 + #setVariable ("$postsLayout" $res) 1009 +#end 1010 + 1011 +#macro(getBlogPostsLocation $blogSpace $postsLocation) 1012 + #getBlogDocument($blogSpace $blogDoc) 1013 + #getBlogProperty($blogDoc 'postsLocation' $blogDoc.space $result) 1014 + #set ($postsLocation = $NULL) 1015 + #setVariable ("$postsLocation" $result) 1016 +#end 1017 + 1018 +#macro(getCategoryAllBlogPostsQuery $query) 1019 + #set ($query = $NULL) 1020 + #getAllBlogPostsQuery($baseQuery) 1021 + #set ($baseQuery = $baseQuery.replace('DateProperty publishDate', 'DateProperty publishDate, DBStringListProperty as category left join category.list catList')) 1022 + #setVariable("$query" "${baseQuery} and obj.id=category.id.id and category.id.name='category'") 1023 +#end 1024 + 1025 +#macro(isDefaultBlog $blogDoc $isDefault) 1026 + #set ($result = false) 1027 + #if ($blogDoc.space == 'Blog') 1028 + #set ($result = true) 1029 + #end 1030 + #setVariable("$isDefault" $result) 1031 +#end 800 800 {{/velocity}} 1033 + 1034 +\\