Changes for page View File Macro

Last modified by Yana Oksner on 2025/07/18 12:19

From version 1.1
edited by Yana Oksner
on 2023/11/13 11:24
Change comment: Install extension [com.xwiki.pro:xwiki-pro-macros/1.9.2]
To version 3.1
edited by Yana Oksner
on 2024/02/23 13:49
Change comment: Install extension [com.xwiki.pro:xwiki-pro-macros/1.15.0]

Summary

Details

XWiki.WikiMacroClass[0]
Macro code
... ... @@ -2,25 +2,24 @@
2 2  #macro (executeMacro)
3 3   #set($hasPDFViewer = $xwiki.exists("XWiki.PDFViewerMacro"))
4 4   #set($officeExtensions = [ 'ppt', 'pptx', 'odp', 'doc', 'docx', 'odt', 'xls', 'xlsx', 'ods' ])
5 - #set($filename = $xcontext.macro.params.get('att--filename'))
6 - #if(!$filename)
7 - #set($filename = $xcontext.macro.params.get('name'))
5 + #set($unescapedFilename = $xcontext.macro.params.get('att--filename'))
6 + #if(!$unescapedFilename)
7 + #set($unescapedFilename = $xcontext.macro.params.get('name'))
8 8   #end
9 - #set($extension = $filename.substring($mathtool.add($filename.lastIndexOf('.'), 1)).toLowerCase())
9 + #set($extension = $unescapedFilename.substring($mathtool.add($unescapedFilename.lastIndexOf('.'), 1)).toLowerCase())
10 + #set($escapedFilename = $services.rendering.escape($unescapedFilename, $xwiki.currentContentSyntaxId))
10 10   #if($extension == 'pdf' && $hasPDFViewer)
11 11  
12 - {{pdfviewer file="${filename}" /}}
13 + {{pdfviewer file="$escapedFilename" /}}
13 13   #elseif($officeExtensions.contains($extension))
14 14  
15 - {{office reference="attach:${filename}" /}}
16 - #elseif($doc.getAttachment($filename))
17 - [[attach:${filename}]]
16 + {{office reference="attach:$escapedFilename" /}}
17 + #elseif($doc.getAttachment($unescapedFilename))
18 + [[attach:$escapedFilename]]
18 18   #end
19 19  #end
20 20  {{/velocity}}
21 21  
22 -{{include reference="Licenses.Code.VelocityMacros"/}}
23 -
24 24  {{velocity}}
25 25  ## We need to check if there is a valid license because the macro is registered even if the user doesn't have view right
26 26  ## on the macro definition page. See XWIKI-14828: Rendering macros defined in wiki pages are available to users that
... ... @@ -28,8 +28,6 @@
28 28  #if ($services.licensing.licensor.hasLicensureForEntity($xcontext.macro.doc.documentReference))
29 29   #executeMacro
30 30  #else
31 - {{error}}
32 - #getMissingLicenseMessage('proMacros.extension.name')
33 - {{/error}}
30 + {{missingLicenseMessage extensionName="proMacros.extension.name"/}}
34 34  #end
35 35  {{/velocity}}
XWiki.WikiMacroParameterClass[0]
Parameter mandatory
... ... @@ -1,0 +1,1 @@
1 +Yes