Wiki source code of Script Services
Last modified by Eleni Cojocariu on 2026/11/11 11:02
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | ##$services.advancedbookmarks## gives scripts access to the bookmarks of the [[current wiki>>doc:documentation.extensions.dev.advanced-bookmarks.WebHome]]. Each method returns a map ready to be serialized as JSON, with an HTTP status code under the ##status## key and, on failure, an ##error## key. Write methods only accept POST requests carrying a valid CSRF token in the ##form_token## parameter. The ##admin## methods return ##forbidden## to the users who do not administer the wiki. | ||
| 2 | |||
| 3 | |=Member|=Returns|=Default|=What it does | ||
| 4 | |##getBookmarks(String user)##|##user##, ##version##, ##size##, ##maxSize##, ##folders##, ##bookmarks##|Current user|Reads the folders and bookmarks of a user, in display order. Each bookmark has ##page##, ##label##, ##folder##, ##order##, ##panel## and ##viewable##, plus ##exists## and ##url## when the current user can view the page. ##size## and ##maxSize## are the space used and allowed, in bytes. | ||
| 5 | |##getPanel()##|##bookmarks##| |Reads the bookmarks of the current user selected for the Panel, or the first ones, up to the Panel size of the wiki. | ||
| 6 | |##isBookmarked(String page)##|##bookmarked##, ##bookmarkable##| |Tells whether the current user bookmarked the page, and whether the page may be bookmarked (##false## for an excluded page). | ||
| 7 | |##isStarEnabled()##|##boolean##| |Tells whether the current wiki displays the star. | ||
| 8 | |##toggle(String page)##|##bookmarked##| |Adds the page to the uncategorized bookmarks of the current user, or removes it. Write method. | ||
| 9 | |##save(String user, String json, String version)##|##version##, ##size##|Current user|Replaces the bookmarks of a user with the ##folders## and ##bookmarks## arrays of ##json##, provided they were not modified since ##version## was read (##0## if there were none). Write method. | ||
| 10 | |##exportBookmarks(String user)##|##content##|Current user|Returns the [[export file>>doc:documentation.extensions.dev.advanced-bookmarks.export-file-format.WebHome]] of a user, as a JSON string. | ||
| 11 | |##importBookmarks(String user, String json, String mode, String version)##|##version##, ##imported##, ##skipped##|Current user|Imports an export file in ##merge## or ##replace## mode, provided the bookmarks were not modified since ##version## was read. Write method. | ||
| 12 | |##admin.getStoreStatus()##|##available##| |Tells whether the Solr core can be queried. | ||
| 13 | |##admin.exportWiki()##|##content##, ##exported##, ##skipped##| |Returns the wiki export file of the current wiki, and the number of users exported and skipped. | ||
| 14 | |##admin.startWikiImport(String mode)##|##users##| |Checks the wiki export file sent in the ##file## part of the current ##multipart/form-data## request, then imports it in the background in ##merge## or ##replace## mode. Write method. | ||
| 15 | |##admin.getWikiImportStatus()##|##state##, ##progress##, ##importedUsers##, ##skippedUsers##, ##failedUsers##, ##importedBookmarks##, ##skippedBookmarks##, ##failed##| |Reads the state of the running or last import: ##none##, ##running## or ##finished##. ##failed## is ##true## when it stopped on an unexpected error. | ||
| 16 | |||
| 17 | |=##error##|=##status##|=Cause | ||
| 18 | |##forbidden##|##403##|The current user may not perform the operation, or the page is excluded or cannot be viewed. | ||
| 19 | |##invalidToken##|##403##|The CSRF token is missing or invalid. | ||
| 20 | |##methodNotAllowed##|##405##|A write method was called outside a POST request. | ||
| 21 | |##invalid##|##400##|A parameter or the JSON is invalid. | ||
| 22 | |##tooLarge##|##400##|The bookmarks would exceed their maximum size. | ||
| 23 | |##conflict##|##409##|The bookmarks were modified since ##version## was read, or a wiki import is already running. | ||
| 24 | |##storageError##|##500##|The Solr core failed. The details are in the server log. | ||
| 25 | |||
| 26 | {{code language="velocity"}} | ||
| 27 | {{velocity}} | ||
| 28 | #set ($result = $services.advancedbookmarks.getBookmarks('')) | ||
| 29 | #if ($result.status == 200) | ||
| 30 | You have $result.bookmarks.size() bookmarks. | ||
| 31 | #else | ||
| 32 | The bookmarks cannot be read: $result.error | ||
| 33 | #end | ||
| 34 | {{/velocity}} | ||
| 35 | {{/code}} | ||
| 36 | |||
| 37 | The script displays, for instance: | ||
| 38 | |||
| 39 | {{code language="none"}} | ||
| 40 | You have 7 bookmarks. | ||
| 41 | {{/code}} |