Modifications pour le document VelocityMacros

Modifié par Florent Charton le 2026/03/13 11:04

Depuis la version 5.1
modifié par Florent Charton
sur 2026/03/13 11:04
Commentaire de modification : Install extension [org.xwiki.platform:xwiki-platform-ckeditor-ui/17.10.4]
À la version 2.1
modifié par Florent Charton
sur 2024/08/08 18:44
Commentaire de modification : Install extension [org.xwiki.platform:xwiki-platform-ckeditor-ui/15.10.11]

Résumé

Détails

Propriétés de la Page
Contenu
... ... @@ -23,10 +23,9 @@
23 23   ## directly in the current page, e.g. when CKEditor is used in-line (no iframe). We still need to send back the
24 24   ## required style sheets and JavaScript files because some of them might not be available in the target page, e.g.
25 25   ## when a macro is inserted and it needs resource files not available on every page.
26 - #template('display_macros.vm')
27 - #initRequiredSkinExtensions()
26 + #ckeditor_initRequiredSkinExtensions()
28 28   #set ($output = "#ckeditor_getRenderedContent($source)$!html")
29 - #sendRequiredSkinExtensions()
28 + #set ($discard = $response.setHeader('X-XWIKI-HTML-HEAD', "#ckeditor_getRequiredSkinExtensions()"))
30 30   #else
31 31   ## Returns a full HTML page, including the HEAD tag with the style sheets and possibly the JavaScript includes.
32 32   ## This is needed when the edited content is loaded in an iframe, which is the case when CKEditor replaces a text
... ... @@ -35,6 +35,11 @@
35 35   #end
36 36   #else
37 37   #set ($output = $services.wysiwyg.fromAnnotatedXHTML($text, $sourceSyntax.toIdString()))
37 + #if ("$!output" == '' && $output != '')
38 + ## $output is null, probably because $services.wysiwyg.fromAnnotatedXHTML() is not available (before 10.10RC1)
39 + #set ($xdom = $services.rendering.parse($text, 'xhtml/1.0'))
40 + #set ($output = $services.rendering.render($xdom, $sourceSyntax.toIdString()))
41 + #end
38 38   #end
39 39   #if ("$!output" != '' || $output == '')
40 40   $output##
... ... @@ -47,6 +47,19 @@
47 47  #macro (ckeditor_renderContentSheet $source)
48 48   ## The $source variable is used inside the content sheet.
49 49   #set ($output = $services.wysiwyg.render('CKEditor.ContentSheet'))
54 + #if ("$!output" == '' && $output != '')
55 + ## $output is null, probably because $services.wysiwyg.render() is not available (before 7.4.1)
56 + #set ($output = $xwiki.getDocument('CKEditor.ContentSheet').getRenderedContent())
57 + #set ($skinExtensionHooks = {
58 + 'ssx': 'CssSkinExtensionPlugin',
59 + 'ssfx': 'CssSkinFileExtensionPlugin',
60 + 'ssrx': 'CssResourceSkinExtensionPlugin'
61 + })
62 + #foreach ($entry in $skinExtensionHooks.entrySet())
63 + #set ($output = $output.replace("<!-- com.xpn.xwiki.plugin.skinx.$entry.value -->",
64 + $xwiki.get($entry.key).importString))
65 + #end
66 + #end
50 50   ## Unescape {{ which happened in CKEditor.ContentSheet for protecting the {{html}} macro.
51 51   $!output.replace('&amp;#123;&amp;#123;', '{{')##
52 52  #end
... ... @@ -55,11 +55,25 @@
55 55   ## Make sure the edited content is rendered for view because this is a WYSIWYG editor.
56 56   #set ($macro.previousDisplayMode = $xcontext.displayMode)
57 57   #set ($discard = $xcontext.setDisplayMode('view'))
75 + #if ($xcontext.displayMode != 'view')
76 + ## Before XWiki 14.0-rc-1, 13.4.7, 13.10.3 and 12.10.12 there's no API to get the current display mode so we can't
77 + ## restore the previous display mode properly. We assume the previous display mode is 'edit' because the WYSIWYG
78 + ## editor is used.
79 + #set ($macro.previousDisplayMode = 'edit')
80 + #end
58 58   #set ($restricted = "$!source.restricted" == 'true')
59 59   #if ($source.html)
60 60   #set ($html = $services.wysiwyg.parseAndRender($source.html, $source.syntax, $source.documentReference, $restricted))
84 + #if ("$!html" == '' && $html != '')
85 + ## Before XWiki 11.9RC1 (see XWIKI-16737)
86 + #set ($html = $services.wysiwyg.parseAndRender($source.html, $source.syntax.toIdString()))
87 + #end
61 61   #else
62 62   #set ($html = $services.wysiwyg.toAnnotatedXHTML($source.content, $source.syntax, $source.documentReference, $restricted))
90 + #if ("$!html" == '' && $html != '')
91 + ## Before XWiki 11.9RC1 (see XWIKI-16737)
92 + #set ($html = $services.wysiwyg.toAnnotatedXHTML($source.content, $source.syntax.toIdString()))
93 + #end
63 63   #end
64 64   #if ("$!html" == '')
65 65   ## Prevent Firefox from inserting bogus whitespace when the text area is empty.
... ... @@ -137,12 +137,6 @@
137 137   #if ($source.restricted == 'true' && !$services.security.authorization.hasAccess('edit', $source.documentReference))
138 138   #set ($parameters.attributes.data-upload-disabled = 'true')
139 139   #end
140 - ## We use the velocity template context to convey the startupFocus parameter to CKEditor.
141 - #if ($wysiwygEditorConfig.startupFocus)
142 - #set ($parameters.attributes.data-startup-focus = 'true')
143 - ## We make sure to clear this context so that it doesn't interfere with CKEditors opened later.
144 - #set ($wysiwygEditorConfig.startupFocus = false)
145 - #end
146 146   ##
147 147   <textarea
148 148   #foreach ($entry in $parameters.attributes.entrySet())
... ... @@ -155,7 +155,7 @@
155 155  
156 156  #macro (displayCKEditorConfigProperty $configDoc $propName $action)
157 157   <dt>
158 - <label for="CKEditor.ConfigClass_$escapetool.xml($configDoc.getObject("CKEditor.ConfigClass").getNumber())_${propName}">$configDoc.displayPrettyName($propName)</label>
183 + <label>$configDoc.displayPrettyName($propName)</label>
159 159   <span class="xHint">$escapetool.xml($services.localization.render("CKEditor.ConfigClass_${propName}.hint"))</span>
160 160   </dt>
161 161   <dd>#displayCKEditorConfigPropertyValue($configDoc $propName $action)</dd>
... ... @@ -198,11 +198,12 @@
198 198   </dl>
199 199  #end
200 200  
201 -#**
202 - * Deprecated. Use #initRequiredSkinExtensions() from display_macros.vm instead.
203 -*#
204 204  #macro (ckeditor_initRequiredSkinExtensions)
205 205   #set ($requiredSkinExtensions = $collectiontool.orderedMap)
228 + #if ("$!requiredSkinExtensions" == '')
229 + ## For XWiki versions older than 12.1RC1 fallback on the old $collectionstool (available since 4.0M1).
230 + #set ($requiredSkinExtensions = $collectionstool.orderedMap)
231 + #end
206 206   ## Save the import string for each skin extension plugin in order to be able to remove the always used extensions
207 207   ## (they are aready available on the edit page so there's no need to load them).
208 208   #foreach ($pluginName in ['ssrx', 'ssfx', 'ssx', 'linkx', 'jsrx', 'jsfx', 'jsx'])
... ... @@ -210,9 +210,6 @@
210 210   #end
211 211  #end
212 212  
213 -#**
214 - * Deprecated. Use #getRequiredSkinExtensions() from display_macros.vm instead.
215 -*#
216 216  #macro (ckeditor_getRequiredSkinExtensions)
217 217   #foreach ($entry in $requiredSkinExtensions.entrySet())
218 218   #set ($importString = $xwiki.get($entry.key).importString)
... ... @@ -220,4 +220,20 @@
220 220   $!stringtool.removeStart($importString, $entry.value).trim()##
221 221   #end
222 222  #end
246 +
247 +#macro (ckeditor_defineSortTool $sortToolVariable)
248 + #set ($checkedExtension = "org.xwiki.commons:xwiki-commons-velocity")
249 + ## Because of an API collision, $collectionstool has been replaced by $collectiontool in XCOMMONS-1861
250 + #if ($services.extension.core.getCoreExtension($checkedExtension).id.version.compareTo("12.1-SNAPSHOT") >= 0)
251 + #setVariable ($sortToolVariable, $collectiontool)
252 + ## With the upgrade of Velocity $sorttool has been replaced by $collectionstool (XCOMMONS-1296)
253 + #elseif ($services.extension.core.getCoreExtension($checkedExtension).id.version.compareTo("12.0-SNAPSHOT") >= 0)
254 + #setVariable ($sortToolVariable, $collectionstool)
255 + ## Old API for sorting was $sorttool
256 + #else
257 + #setVariable ($sortToolVariable, $sorttool)
258 + #end
259 +#end
260 +
261 +#ckeditor_defineSortTool("$resolvedSortTool")
223 223  {{/velocity}}