Like Script Service

Last modified by Eleni Cojocariu on 2026/08/12 16:21

Reference

The like Script Service exposes the Like feature to wiki pages as $services.like. It acts on documents only, ignoring a reference of any other type, and it never throws: a failure of the underlying API is logged as a warning and reported as an empty Optional or an empty list.

MethodReturnsDescription
isAuthorized(entityReference)booleanWhether the current user may like the entity. Guests are always refused.
displayButton(entityReference)booleanWhether the Like button should be shown: the feature is enabled, and either the current user is authorized or the wiki is configured to always display it.
isEnabled()booleanWhether the Like feature is enabled.
like(entityReference)Optional<Long>Likes the entity as the current user and returns its new like count. Empty when the user is not authorized.
unlike(entityReference)Optional<Long>Removes the current user's like and returns the new count, under the same conditions as like.
getLikes(entityReference)Optional<Long>The number of likes of the entity.
isLiked(entityReference)booleanWhether the current user already liked the entity.
getLikers(target, offset, limit)List<UserReference>The users who liked the entity, most recently updated first.
getUserLikes(userReference, offset, limit)List<EntityReference>The entities a user liked, most recently updated first.
countUserLikes(userReference)Optional<Long>How many likes a user performed.

Display the like count of the current page, and whether the current user is one of the likers:

#set ($likes = $services.like.getLikes($doc.documentReference))
#if ($likes.isPresent())
  $likes.get() like(s)#if ($services.like.isLiked($doc.documentReference)), including yours#end
#end

Like the current page as the current user:

#set ($newCount = $services.like.like($doc.documentReference))
#if ($newCount.isPresent())
  This page now has $newCount.get() like(s).
#else
  You are not allowed to like this page.
#end

Show a Like button only where it belongs, inactive for the users who may see it without using it:

#if ($services.like.displayButton($doc.documentReference))
  #set ($active = $services.like.isAuthorized($doc.documentReference))
  ## Render the button here, inactive when $active is false.
#end

FAQ

Do the pagination offsets start at zero?

Yes, offset is zero based, so the first page of results starts at 0.

Why does like() return an empty Optional?

Either the current user is not allowed to like that page, or the store failed; the reason is logged as a warning.

Related

Get Connected