Last modified by superadmin on 2026/12/02 07:12

From version Icon 3.1 Icon
edited by superadmin
on 2026/12/02 00:12
Change comment: There is no comment for this version
To version Icon 5.1 Icon
edited by superadmin
on 2026/12/02 05:36
Change comment: There is no comment for this version

Summary

Details

Icon Page properties
Syntax
... ... @@ -1,1 +1,1 @@
1 -XWiki 1.0
1 +XWiki 2.1
Content
... ... @@ -1,4 +1,6 @@
1 -#includeMacros("Blog.BlogParameters")
1 +{{include reference="Blog.BlogParameters" author="target" /}}
2 +
3 +{{velocity output="false"}}
2 2  ##
3 3  ##
4 4  ##
... ... @@ -104,7 +104,12 @@
104 104   * @param title The resulting title.
105 105   *###
106 106  #macro(getBlogTitle $blogDoc $title)
107 - #getBlogProperty($blogDoc 'title' $!blogDoc.displayTitle $title)
109 + ## The blog title is the rendered document title. It is displayed as data (never evaluated as
110 + ## Velocity), so an unprivileged user storing script in Blog.BlogClass.title cannot run it. See
111 + ## Blog.BlogSheet, which renders the title literally and falls back to the blog.code.title
112 + ## translation when the stored title is empty.
113 + #set ($title = $NULL)
114 + #setVariable ("$title" $!blogDoc.displayTitle)
108 108  #end
109 109  ##
110 110  ##
... ... @@ -117,7 +117,9 @@
117 117   * @param description The resulting description.
118 118   *###
119 119  #macro(getBlogDescription $blogDoc $description)
120 - #getBlogProperty($blogDoc 'description' '' $description)
127 + #getBlogProperty($blogDoc 'description' '' $result)
128 + #set ($description = $NULL)
129 + #setVariable ("$description" $result)
121 121  #end
122 122  ##
123 123  ##
... ... @@ -313,13 +313,7 @@
313 313   * @param query The basic query for selecting blog entries.
314 314   *###
315 315  #macro(getBlogEntriesBaseQuery $query)
316 - #set ($query = ", BaseObject obj, IntegerProperty isPublished, IntegerProperty hidden, DateProperty publishDate
317 - where doc.fullName <> 'Blog.BlogPostTemplate' and
318 - obj.name = doc.fullName and obj.className = '${blogPostClassname}' and
319 - publishDate.id.id = obj.id and publishDate.id.name = 'publishDate' and
320 - isPublished.id.id = obj.id and isPublished.id.name = 'published' and
321 - hidden.id.id = obj.id and hidden.id.name = 'hidden' and
322 - (doc.creator = '$context.user' or (isPublished.value = 1 and hidden.value = 0))")
325 + #getAllBlogPostsQuery($query)
323 323  #end
324 324  ##
325 325  ##
... ... @@ -349,7 +349,9 @@
349 349   * @param displayType The resulting string. If the blog object does not define anything, it is considered paginated.
350 350   *###
351 351  #macro(getBlogDisplayType $blogDoc $displayType)
352 - #getBlogProperty($blogDoc 'displayType' 'paginated' $displayType)
355 + #getBlogProperty($blogDoc 'displayType' 'paginated' $result)
356 + #set ($displayType = $NULL)
357 + #setVariable ("$displayType" $result)
353 353  #end
354 354  ##
355 355  ##
... ... @@ -841,8 +841,200 @@
841 841   * @param propertyValue The resulting value.
842 842   *###
843 843  #macro(getBlogProperty $blogDoc $propertyName $defaultValue $propertyValue)
844 - #set($propertyValue = "$!{blogDoc.getObject(${blogClassname}).getProperty($propertyName).value}")
845 - #if($propertyValue == '')
846 - #set($propertyValue = $defaultValue)
849 + #set($result = "$!{blogDoc.getObject(${blogClassname}).getProperty($propertyName).value}")
850 + #if($result == '')
851 + #set($result = $defaultValue)
847 847   #end
853 + #set ($propertyValue = $NULL)
854 + #setVariable ("$propertyValue" $result)
848 848  #end
856 +## Compatibility helpers from the installed Blog 9.15.15 package.
857 +#macro(bindQueryParameters $queryObj $queryParams)
858 + #set ($output = $queryObj)
859 + #foreach( $key in $queryParams.keySet() )
860 + #set($output = $queryObj.bindValue($key, $queryParams.get($key)))
861 + #end
862 + #setVariable("$queryObj" $output)
863 +#end
864 +
865 +#macro(blog__actionResponseError $status $text $parameters)
866 + $response.setStatus($status)
867 + #if($request.ajax)
868 + $services.localization.render($text, $!parameters)
869 + #else
870 + {{error}}$services.localization.render($text, $!parameters){{/error}}
871 + #end
872 +#end
873 +
874 +#macro(displayBlogPostsBasedOnContext $targetDoc $postsVisiblity $layout $layoutParams $limit)
875 + #if ($layout == 'link')
876 + #set ($macro.paginated = 'no')
877 + #end
878 + #if ($targetDoc.space == $defaultBlogSpace && !$targetDoc.getObject($blogCategoryClassname))
879 + ## Display all posts that are in the default blog space('Blog') or in category 'Blog.%'
880 + #getBlogPostsLayout($xwiki.getDocument("${defaultBlogSpace}.WebHome") $postsLayout)
881 + #if ("$!layout" == '')
882 + #set ($layout = $postsLayout)
883 + #end
884 + #if ($postsVisiblity == 'recent')
885 + {{blogpostlist blog="${defaultBlogSpace.replaceAll('~', '~~').replaceAll('"', '~"')}.WebHome" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
886 + #elseif($postsVisiblity == 'unpublished')
887 + {{blogpostlist blog="${defaultBlogSpace.replaceAll('~', '~~').replaceAll('"', '~"')}.WebHome" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
888 + #end
889 + #elseif($targetDoc.getObject($blogCategoryClassname))
890 + ## Display all posts that are in a category aCategorySpace.aCategory
891 + #getBlogDocumentForCategoriesSpace($targetDoc.space $blogDoc)
892 + #getBlogPostsLayout($blogDoc $postsLayout)
893 + #if ("$!layout" == '')
894 + #set ($layout = $postsLayout)
895 + #end
896 + #if ($postsVisiblity == 'recent')
897 + {{blogpostlist category="$targetDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
898 + #elseif($postsVisiblity == 'unpublished')
899 + {{blogpostlist category="$targetDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
900 + #end
901 + #elseif($targetDoc.getObject('XWiki.DocumentSheetBinding').sheet == 'Blog.CategoriesSheet')
902 + ## Display all posts that are in a category aCategorySpace.%
903 + #getBlogDocumentForCategoriesSpace($targetDoc.space $blogDoc)
904 + #getBlogPostsLayout($blogDoc $postsLayout)
905 + #if ("$!layout" == '')
906 + #set ($layout = $postsLayout)
907 + #end
908 + #if ($postsVisiblity == 'recent')
909 + {{blogpostlist category="$targetDoc.space.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
910 + #elseif($postsVisiblity == 'unpublished')
911 + {{blogpostlist category="$targetDoc.space.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
912 + #end
913 + #else
914 + ## Display all posts in blog space aBlog
915 + #getBlogDocument($targetDoc.space $blogDoc)
916 + #getBlogPostsLayout($blogDoc $postsLayout)
917 + #if ("$!layout" == '')
918 + #set ($layout = $postsLayout)
919 + #end
920 + #if ($postsVisiblity == 'recent')
921 + {{blogpostlist blog="$blogDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
922 + #elseif($postsVisiblity == 'unpublished')
923 + {{blogpostlist blog="$blogDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
924 + #end
925 + #end
926 +#end
927 +
928 +#macro(displayEntryBlogLocation $entryDoc $entryObj)
929 + #getBlogPostsLocation($entryDoc.getSpace() $blogPostsLocation) ##
930 + #if("$!blogPostsLocation" != "") ##
931 + #set($blogSpaceRef = $services.model.resolveSpace($blogPostsLocation)) ##
932 + #set($blogDocRef = $services.model.createDocumentReference($services.model.getEntityReference('DOCUMENT', 'default').getName(), $blogSpaceRef)) ##
933 + #if($doc.documentReference != $blogDocRef) ##
934 + #set($blogDoc = $xwiki.getDocument($blogDocRef)) ##
935 + #set($blogObj = $blogDoc.getObject('Blog.BlogClass')) ##
936 + #if($blogObj) (% class="blogrefpath" %)((( ##
937 + $services.localization.render('blog.code.postedin') {{html clean="false" wiki="false"}} #hierarchy($blogDocRef, {'selfIsActive' : true, 'local': true}) {{/html}} ##
938 + )))(%%)##
939 + #end
940 + #end
941 + #end
942 +#end
943 +
944 +#macro(getAllBlogPostsQuery $query)
945 + #set ($query = $NULL)
946 + #setVariable("$query" ", BaseObject as obj, IntegerProperty isPublished,
947 + IntegerProperty hidden, DateProperty publishDate
948 + where doc.fullName <> '$blogPostTemplate' and
949 + obj.name=doc.fullName and obj.className='$blogPostClassname' and
950 + isPublished.id.id = obj.id and isPublished.id.name = 'published' and
951 + hidden.id.id = obj.id and hidden.id.name='hidden' and
952 + publishDate.id.id = obj.id and publishDate.id.name='publishDate' and
953 + (doc.creator = '$escapetool.sql($xcontext.user)' or (isPublished.value = 1 and hidden.value = 0))")
954 +#end
955 +
956 +#macro(getAllBlogPostsQueryBasedOnDisplayContext $targetDoc $query $queryParams)
957 + #set ($query = $NULL)
958 + #set ($queryParams = $NULL)
959 + #getCategoryAllBlogPostsQuery($resultQuery)
960 + #set ($resultQueryParams = {})
961 + #set($sanitizedSpace = $targetDoc.space.replaceAll('([%_!])', '!$1').concat('.%'))
962 + #if ($targetDoc.space == $defaultBlogSpace && !$targetDoc.getObject($blogCategoryClassname))
963 + ## Get all posts that are in the default blog space('Blog') or in category 'Blog.%'
964 + #set ($discard = $resultQueryParams.put('space', $targetDoc.space))
965 + #set ($discard = $resultQueryParams.put('catList', $sanitizedSpace))
966 + #set($resultQuery = "${resultQuery} and (doc.space = :space or catList like :catList escape '!')")
967 + #elseif($targetDoc.getObject($blogCategoryClassname))
968 + ## Get all posts that are in a category aCategorySpace.aCategory
969 + #set ($discard = $resultQueryParams.put('catList', $targetDoc.fullName))
970 + #set($resultQuery = "${resultQuery} and (catList=:catList)")
971 + #elseif($targetDoc.getObject('XWiki.DocumentSheetBinding').sheet == 'Blog.CategoriesSheet')
972 + ## Get all posts that are in a category aCategorySpace.%
973 + #set ($discard = $resultQueryParams.put('catList', $sanitizedSpace))
974 + ## Exclude incategorized posts
975 + #set ($excludedCategory = "${targetDoc.space}.WebHome")
976 + #if ($targetDoc.space == $defaultBlogSpace)
977 + #set ($excludedCategory = "Blog.Categories.WebHome")
978 + #end
979 + #set ($discard = $resultQueryParams.put('excludedCategory', $excludedCategory))
980 + #set($resultQuery = "${resultQuery} and (catList<>:excludedCategory) and (catList like :catList escape '!')")
981 + #else
982 + ## Get all posts in blog space aBlog
983 + #getAllBlogPostsQuery($resultQuery)
984 + #getBlogPostsLocation($targetDoc.space $postsLocation)
985 + #set ($discard = $resultQueryParams.put('space', $postsLocation))
986 + #set($resultQuery = "${resultQuery} and doc.space = :space")
987 + #end
988 + #setVariable("$query" $resultQuery)
989 + #setVariable("$queryParams" $resultQueryParams)
990 +#end
991 +
992 +#macro(getBlogCategoriesLocation $blogSpace $categoriesLocation)
993 + #getBlogDocument($blogSpace $blogDoc)
994 + ## Since 9.15, category data may exist in Blog or Blog.Categories. Code supports both paths to maintain backward compatibility.
995 + #set ($defaultBlogCategoryLocation = 'Blog.Categories')
996 + #if ($services.blog.hasLegacyCategoryAssignments())
997 + #set ($defaultBlogCategoryLocation = 'Blog')
998 + #end
999 + #getBlogProperty($blogDoc 'categoriesLocation' $defaultBlogCategoryLocation $result)
1000 + #set ($postsLocation = $NULL)
1001 + #setVariable ("$categoriesLocation" $result)
1002 +#end
1003 +
1004 +#macro(getBlogDocumentForCategoriesSpace $categoriesSpace $blogDoc)
1005 + #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())
1006 + #if($macro.blogDocs.size() > 0 && $categoriesSpace != $defaultBlogSpace)
1007 + #set($macro.result = $xwiki.getDocument($macro.blogDocs.get(0)))
1008 + #else
1009 + ## Fallback to Blog.WebHome, the default blog
1010 + #set($macro.result = $xwiki.getDocument('Blog.WebHome'))
1011 + #end
1012 + #set ($blogDoc = $NULL)
1013 + #setVariable ("$blogDoc" $macro.result)
1014 +#end
1015 +
1016 +#macro(getBlogPostsLayout $blogDoc $postsLayout)
1017 + #getBlogProperty($blogDoc 'postsLayout' 'full' $res)
1018 + #set ($postsLayout = $NULL)
1019 + #setVariable ("$postsLayout" $res)
1020 +#end
1021 +
1022 +#macro(getBlogPostsLocation $blogSpace $postsLocation)
1023 + #getBlogDocument($blogSpace $blogDoc)
1024 + #getBlogProperty($blogDoc 'postsLocation' $blogDoc.space $result)
1025 + #set ($postsLocation = $NULL)
1026 + #setVariable ("$postsLocation" $result)
1027 +#end
1028 +
1029 +#macro(getCategoryAllBlogPostsQuery $query)
1030 + #set ($query = $NULL)
1031 + #getAllBlogPostsQuery($baseQuery)
1032 + #set ($baseQuery = $baseQuery.replace('DateProperty publishDate', 'DateProperty publishDate, DBStringListProperty as category left join category.list catList'))
1033 + #setVariable("$query" "${baseQuery} and obj.id=category.id.id and category.id.name='category'")
1034 +#end
1035 +
1036 +#macro(isDefaultBlog $blogDoc $isDefault)
1037 + #set ($result = false)
1038 + #if ($blogDoc.space == 'Blog')
1039 + #set ($result = true)
1040 + #end
1041 + #setVariable("$isDefault" $result)
1042 +#end
1043 +
1044 +{{/velocity}}
1045 +

#includeMacros("Blog.BlogCode")
#getBlogEntriesBaseQuery($query)
#set($query = "$!{query} and isPublished.value = 1")
#set($recentEntries = $xwiki.searchDocuments("${query} order by publishDate.value desc", 10, 0))
#if($recentEntries.size() > 0 || $showEmptyPanels)
  #panelheader('Recent Blog Posts')
  #foreach($entryDoc in $xwiki.wrapDocs($recentEntries))
    #getEntryObject($entryDoc $entryObj)

  • [$!{entryDoc.display('title', 'view', $entryObj)}>$!{entryDoc.fullName}]
      #end
      #panelfooter()
    #end

#includeMacros("Blog.BlogCode")
#getBlogEntriesBaseQuery($query)
#set($query = "$!{query} and isPublished.value = 0")
#set($unpublishedEntries = $xwiki.searchDocuments("${query} order by publishDate.value desc", 5, 0))
#if($unpublishedEntries.size() > 0 || $showEmptyPanels)
  #panelheader("Unpublished Posts")
  #foreach($entryDoc in $xwiki.wrapDocs($unpublishedEntries))
    #getEntryObject($entryDoc $entryObj)

  • [$!{entryDoc.display('title', 'view', $entryObj)}>$!{entryDoc.fullName}]
      #end
      [View all ($xwiki.countDocuments($query))>Blog.Unpublished]
      #panelfooter()
    #end

#includeMacros("Blog.CategoriesCode")
#panelheader('Blog Categories')
#getCategoriesHierarchy('Blog' $tree)
#displayCategoriesHierarchy($tree 'simple')
#if($xwiki.hasAdminRights())
  <div style="font-size:75%;">(<a href="$xwiki.getURL('Blog.ManageCategories')">Edit Categories</a>)</div>
#end
#panelfooter()

{{include reference="Blog.BlogCode"/}}

{{velocity}} #getAllBlogPostsQueryBasedOnDisplayContext($doc $query $queryParams) #bindQueryParameters($queryObj $queryParams) {{/velocity}}