Improvement to the free PDF Viewer Macro (use Attachment Picker)

Hello,

I’dont know if this is the correct place in the forum so please move it if its not the correct place.

My “proposal” is to update the free PDF Viewer macro and change the selection of the file to use the org.xwiki.model.reference.AttachmentReference as a picker instead of having users to manually insert the filename and optionally the document reference.

This will hugely improve the Quality of Live of the free macro, and yes of course it may reduce the incentive to buy the Pro extension as the ease of use is the main argument for that.
But right now that great free PDF Viewer macro feels like artificially weakened. Currently I don’t fully understand what the status of extensions is, for which also a “Pro” version is available. - Can somebody explain that to me? Are such extensions still developed further? Are the developments of such extensions limited to not “bite into” the Pro extensions? That is why im posting it in the forum and not yet to Jira as I first want to understand that.
I personally understand the goals behind the Pro extensions but I personally feel against limiting the free ones. I think my modification can make the free extensions quite a bit more user friendly, that is why I want to post it here.

current issue with usability
Currently users have to manually insert the correct filename of the PDF and if they want to reference to an PDF that is saved on another page, they have to include the WebHome reference of that. In our organisation nearly no user understands how to use the PDF Viewer Macro, and even the ones that do understand how to use it, dislike the inconvenience.

desired usability
For our environment I searched for an better and much more user friendly way and found a solution quite quickly: As XWiki offers the Attachment picker (org.xwiki.model.reference.AttachmentReference) which makes referencing the files much more user friendly.

possible solution (quick and dirty)
If you wan’t to try the modifications yourself (DO THIS ONLY IN A TEST ENVIRONMENT! It will possibly break stuff!)

  1. Go to /xwiki/bin/edit/XWiki/PDFViewerMacro?editor=object&force=1
  2. Modify the Object " XWiki.WikiMacroParameterClass" and change the “file” parameter to the type “org.xwiki.model.reference.AttachmentReference”
  3. Modify the “XWiki.WikiMacroClass” with inserting the following code after line 12:
## modification START
  #set($filepath = $file.split("@"))
  #if($filepath.size() == 1)
    #set($docname = $doc)
    #set($file = $filepath[0])
  #end
  #if($filepath.size() == 2)
    #set($docname = $filepath[0])
    #set($file = $filepath[1])
  #end
## modification END

explanation of the modification
The modification simply changes the normal “file” parameter to use the attachment picker when editing with WYSIWYG instead of being a simple text box that users have to insert the filename into. If you pick a file that is within the current page, the value of that parameter (and variable) is still only the filename. As it des not contain the “@” character it won’t get split further. The $docname variable gets changed to current document name. The whole remaining untouched code of the macro will use these variables further.

If the file you selected with the picker (for example with simply searching for the name) is saved within another page, the attachment picker sets the value of that parameter to Example.Page.Webhome@yourfile.pdf . That string will then get split by the @ into the $docname and $file variables. The whole remaining untouched code of the macro will use these variables further. You don’t have to additionally select/insert a reference to the WebHome of that location.

Theoretically, with that modification the whole “docname” parameter of the macro can be eliminated and the code slimmed. But that would probably kill compatibility.

It is still not perfect as it is possible to select files other than PDF (just like it is currently possible to insert wrong text), but with that small modification, the macro is much more easy to use.
The perfect picker probably would be something like the image picker when selecting an existing image in WYSIWYG, the one that shows the whole document tree and the documents and their attachments. But currently im not advanced enough to understand how that is done.

Hi,

The projects hosted on XWiki Contrib GitHub organization are maintained by the XWiki community, not by the XWiki Development team (that works on the XWiki project itself hosted on the XWiki GitHub organization). Anyone is welcome to contribute to these projects, following the rules indicated on http://contrib.xwiki.org/xwiki/bin/view/Main/WebHome .

XWiki SAS, the main sponsor of the XWiki product development, has forked a few of these contributed projects and developed them further into Pro extensions, but this doesn’t prevent anyone from taking over the development / maintenance of the free versions that remained in XWiki Contrib. Note that the code of the Pro versions is still open (also licensed as LGPL, in the XWiki SAS GitHub organization). Those that buy a Pro license are actually buying professional support from XWiki SAS, and the money are used to found XWiki product development. For more info check XWiki Pro Apps FAQ - XWiki .

Thus, to answer you question: the free versions of the Pro extensions are not maintained by the XWiki Development team nor XWiki SAS, but they could be maintained by someone from the XWiki community, someone like you :slight_smile: Check http://contrib.xwiki.org/xwiki/bin/view/Main/WebHome on how to start contributing.

Hope this helps,
Marius

1 Like