Wiki source code of Like Script Service

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

Show last authors
1 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.
2
3 |=Method|=Returns|=Description
4 |##isAuthorized(entityReference)##|##boolean##|Whether the current user may like the entity. Guests are always refused.
5 |##displayButton(entityReference)##|##boolean##|Whether 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.
6 |##isEnabled()##|##boolean##|Whether the Like feature is enabled.
7 |##like(entityReference)##|##Optional<Long>##|Likes the entity as the current user and returns its new like count. Empty when the user is not authorized.
8 |##unlike(entityReference)##|##Optional<Long>##|Removes the current user's like and returns the new count, under the same conditions as ##like##.
9 |##getLikes(entityReference)##|##Optional<Long>##|The number of likes of the entity.
10 |##isLiked(entityReference)##|##boolean##|Whether the current user already liked the entity.
11 |##getLikers(target, offset, limit)##|##List<UserReference>##|The users who liked the entity, most recently updated first.
12 |##getUserLikes(userReference, offset, limit)##|##List<EntityReference>##|The entities a user liked, most recently updated first.
13 |##countUserLikes(userReference)##|##Optional<Long>##|How many likes a user performed.
14
15 Display the like count of the current page, and whether the current user is one of the likers:
16
17 {{code language="velocity"}}
18 #set ($likes = $services.like.getLikes($doc.documentReference))
19 #if ($likes.isPresent())
20 $likes.get() like(s)#if ($services.like.isLiked($doc.documentReference)), including yours#end
21 #end
22 {{/code}}
23
24 Like the current page as the current user:
25
26 {{code language="velocity"}}
27 #set ($newCount = $services.like.like($doc.documentReference))
28 #if ($newCount.isPresent())
29 This page now has $newCount.get() like(s).
30 #else
31 You are not allowed to like this page.
32 #end
33 {{/code}}
34
35 Show a Like button only where it belongs, inactive for the users who may see it without using it:
36
37 {{code language="velocity"}}
38 #if ($services.like.displayButton($doc.documentReference))
39 #set ($active = $services.like.isAuthorized($doc.documentReference))
40 ## Render the button here, inactive when $active is false.
41 #end
42 {{/code}}

Get Connected