I have been asked to be able to get notified whenever a user clicks on a link to download a software we provide through the wiki. More specifically we provide a release notes page with a button that is a link to an attached file to this page. I first looked into the statistics module but it is not detailed enough to give this level of information.
I am now thinking about using a velocity macro to detect each time a user clicks the button, and the idea behind is that the macro would send an email whose content would be the url of the page and the name of the user.
I am new to velocity programming, but I would just like to know if I am pointing in the right direction here, and if this is the best solution to get the information I need or if there are simpler ways. Any advice welcome ï
Thanks a lot for these smart guidelines! I am almost there. I am just struggling with the third point âredirect to the query string paramâ. Actually the redirection works fine if the string param is a page, but fails if the link points to an attachment. I tried different solutions, but all of them failed.
Here is what works when the param is a page :
On the source page I created this link (the param is named âlinkâ, the special page DownloadNotificationMacro ) :
Here is what fails when the param is an attachment :
On the source page I created this link (the param is named âlinkâ) :
[[lien de test>>doc:.DownloadNotificationMacro.WebHome||queryString=âlink=attach:Sandbox.TestPage3.watchlist_1.pngâ]]
Redirection brings me to âŠ/xwiki/bin/view/Sandbox/TestPage3/watchlist_1/png
The correct link is âŠ/xwiki/bin/download/Sandbox/TestPage3/watchlist_1.png
Several problems here (âviewâ instead of âdownloadâ, and the dot of the filename is replaced by a /)
I tried percent encoding, pasting the correct link, escaping the dot with an ,⊠but could not find a working solution. Maybe the use of $xwiki.getURL() is not the way to go in this particular case? I tried to read the documentation in order to find a better suited function, but I could not.
Thanks again for your help, and sorry for those novice questions.
Your query string param is incorrect. It should be a reference to an attachment, i.e. attachmentReference=Sandbox.TestPage3@watchlist_1.png.
You then need to convert the String into an AttachmentReference, using $set ($attachmentReference = $services.model.resolveAttachment($attachmentReferenceString))
You can then use $xwiki.getURL($attachmentReference) to get the URL
As a side note, I ran into one last issue that I resolved, I just wanted to document it :
as the path to the attachments contained a directory with dots (in the form of a version number x.y.z as the attachments are software versions stored in the extension release notes) the redirection failed because all the dots where transformed in /. So I escaped the dots inside the x.y.z directory with \ percent encoded
=> x%5C.y%5C.z
Maybe not the most elegant solution, but it works fine.
This is not correct. You shouldnât escape anything. The APIs that I linked do the escaping automatically. If not then thereâs a big bug that we need to fix and it needs to be reported. Thx
Actually I tried different things. Before reporting a potential bug, I prefer pasting my code as I am not so confident that I understood perfectly how to use the APIs :
If the reference is computed then you need to create an AttachmentReference object and serialize it with $services.model.serialize($attachmentReference).