Modifications pour le document VelocityMacros
Modifié par Florent Charton le 2026/03/13 11:04
Depuis la version 4.1
modifié par Florent Charton
sur 2025/08/19 15:16
sur 2025/08/19 15:16
Commentaire de modification :
Install extension [org.xwiki.platform:xwiki-platform-ckeditor-ui/17.4.3]
À la version 1.1
modifié par superadmin
sur 2022/06/20 08:49
sur 2022/06/20 08:49
Commentaire de modification :
Install extension [org.xwiki.contrib:application-ckeditor-ui/1.63.1]
Résumé
-
Propriétés de la Page (2 modifications, 0 ajouts, 0 suppressions)
Détails
- Propriétés de la Page
-
- Auteur du document
-
... ... @@ -1,1 +1,1 @@ 1 - xwiki:XWiki.fcharton1 +XWiki.superadmin - Contenu
-
... ... @@ -10,8 +10,7 @@ 10 10 #if ($toHTML) 11 11 #set ($source = { 12 12 'documentReference': $doc.documentReference, 13 - 'syntax': $sourceSyntax, 14 - 'restricted' : $request.wysiwygRestricted 13 + 'syntax': $sourceSyntax 15 15 }) 16 16 #if ($fromHTML) 17 17 #set ($source.html = $text) ... ... @@ -34,6 +34,11 @@ 34 34 #end 35 35 #else 36 36 #set ($output = $services.wysiwyg.fromAnnotatedXHTML($text, $sourceSyntax.toIdString())) 36 + #if ("$!output" == '' && $output != '') 37 + ## $output is null, probably because $services.wysiwyg.fromAnnotatedXHTML() is not available (before 10.10RC1) 38 + #set ($xdom = $services.rendering.parse($text, 'xhtml/1.0')) 39 + #set ($output = $services.rendering.render($xdom, $sourceSyntax.toIdString())) 40 + #end 37 37 #end 38 38 #if ("$!output" != '' || $output == '') 39 39 $output## ... ... @@ -46,6 +46,19 @@ 46 46 #macro (ckeditor_renderContentSheet $source) 47 47 ## The $source variable is used inside the content sheet. 48 48 #set ($output = $services.wysiwyg.render('CKEditor.ContentSheet')) 53 + #if ("$!output" == '' && $output != '') 54 + ## $output is null, probably because $services.wysiwyg.render() is not available (before 7.4.1) 55 + #set ($output = $xwiki.getDocument('CKEditor.ContentSheet').getRenderedContent()) 56 + #set ($skinExtensionHooks = { 57 + 'ssx': 'CssSkinExtensionPlugin', 58 + 'ssfx': 'CssSkinFileExtensionPlugin', 59 + 'ssrx': 'CssResourceSkinExtensionPlugin' 60 + }) 61 + #foreach ($entry in $skinExtensionHooks.entrySet()) 62 + #set ($output = $output.replace("<!-- com.xpn.xwiki.plugin.skinx.$entry.value -->", 63 + $xwiki.get($entry.key).importString)) 64 + #end 65 + #end 49 49 ## Unescape {{ which happened in CKEditor.ContentSheet for protecting the {{html}} macro. 50 50 $!output.replace('&#123;&#123;', '{{')## 51 51 #end ... ... @@ -54,11 +54,24 @@ 54 54 ## Make sure the edited content is rendered for view because this is a WYSIWYG editor. 55 55 #set ($macro.previousDisplayMode = $xcontext.displayMode) 56 56 #set ($discard = $xcontext.setDisplayMode('view')) 57 - #set ($restricted = "$!source.restricted" == 'true') 74 + #if ($xcontext.displayMode != 'view') 75 + ## 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 76 + ## restore the previous display mode properly. We assume the previous display mode is 'edit' because the WYSIWYG 77 + ## editor is used. 78 + #set ($macro.previousDisplayMode = 'edit') 79 + #end 58 58 #if ($source.html) 59 - #set ($html = $services.wysiwyg.parseAndRender($source.html, $source.syntax, $source.documentReference, $restricted)) 81 + #set ($html = $services.wysiwyg.parseAndRender($source.html, $source.syntax, $source.documentReference)) 82 + #if ("$!html" == '' && $html != '') 83 + ## Before XWiki 11.9RC1 (see XWIKI-16737) 84 + #set ($html = $services.wysiwyg.parseAndRender($source.html, $source.syntax.toIdString())) 85 + #end 60 60 #else 61 - #set ($html = $services.wysiwyg.toAnnotatedXHTML($source.content, $source.syntax, $source.documentReference, $restricted)) 87 + #set ($html = $services.wysiwyg.toAnnotatedXHTML($source.content, $source.syntax, $source.documentReference)) 88 + #if ("$!html" == '' && $html != '') 89 + ## Before XWiki 11.9RC1 (see XWIKI-16737) 90 + #set ($html = $services.wysiwyg.toAnnotatedXHTML($source.content, $source.syntax.toIdString())) 91 + #end 62 62 #end 63 63 #if ("$!html" == '') 64 64 ## Prevent Firefox from inserting bogus whitespace when the text area is empty. ... ... @@ -74,6 +74,10 @@ 74 74 #set ($discard = $xwiki.linkx.use($url, {'type': 'text/css', 'rel': 'stylesheet'})) 75 75 #end 76 76 107 +#macro (importCKEditorCSS $path $evaluate) 108 + #ckeditor_importCSS('org.xwiki.contrib' 'application-ckeditor-webjar' $path $evaluate) 109 +#end 110 + 77 77 #macro (importCKEditorResources) 78 78 #set ($discard = $xwiki.ssx.use('CKEditor.EditSheet')) 79 79 ## Add the version of each JavaScript dependency of CKEditor Integration to the URL used to load the CKEditor in order ... ... @@ -80,7 +80,7 @@ 80 80 ## to make sure the browser cache is invalidated when one of these versions changes (e.g. when we upgrade XWiki or one 81 81 ## of these dependencies but the CKEditor version remains the same). 82 82 #set ($discard = $xwiki.jsx.use('CKEditor.EditSheet', { 83 - 'v': $services.extension.installed.getInstalledExtension('org.xwiki. platform:xwiki-platform-ckeditor-ui',117 + 'v': $services.extension.installed.getInstalledExtension('org.xwiki.contrib:application-ckeditor-ui', 84 84 "wiki:$xcontext.database").version.value, 85 85 'xwiki-version': $services.extension.core.getCoreExtension( 86 86 'org.xwiki.platform:xwiki-platform-tree-webjar').version.value, ... ... @@ -89,7 +89,8 @@ 89 89 'bs3typeahead-version': $services.extension.installed.getInstalledExtension('org.webjars.npm:bootstrap-3-typeahead', 90 90 "wiki:$xcontext.database").version.value 91 91 })) 92 - #ckeditor_importCSS('org.xwiki.platform' 'xwiki-platform-ckeditor-plugins' 'webjar.bundle.min.css' true) 126 + #importCKEditorCSS('plugins/xwiki-resource/resourcePicker.min.css' true) 127 + #importCKEditorCSS('plugins/xwiki-macro/macroWizard.min.css' true) 93 93 ## Tree styles needed for the document/attachment tree picker. 94 94 #set ($discard = $xwiki.linkx.use($services.webjars.url('org.xwiki.platform:xwiki-platform-tree-webjar', 'tree.min.css', 95 95 {'evaluate': true}), {'type': 'text/css', 'rel': 'stylesheet'})) ... ... @@ -99,55 +99,40 @@ 99 99 100 100 #macro (ckeditor $parameters) 101 101 #importCKEditorResources 102 - ## 137 + #set ($sourceDocumentReference = $parameters.attributes.get('data-sourceDocumentReference')) 138 + ## Use the current document as source document, if possible, because it may contain unsaved changes (e.g. changes 139 + ## coming from a template specified in the URL or from other URL parameters). This is important for instance in order 140 + ## to ensure that for new (unsaved) documents we use the syntax that has been copied from the template and not the 141 + ## default wiki syntax. 142 + #if (!$sourceDocumentReference || $sourceDocumentReference.equals($tdoc.documentReference)) 143 + #set ($sourceDocument = $tdoc) 144 + #set ($sourceDocumentReference = $tdoc.documentReference) 145 + #else 146 + #set ($sourceDocument = $xwiki.getDocument($sourceDocumentReference)) 147 + #end 103 103 #set ($escapedName = $escapetool.xml($parameters.attributes.name)) 104 104 <input value="$!escapedName" name="RequiresHTMLConversion" type="hidden"/> 105 - ## 106 - #set ($syntaxId = $parameters.attributes.get('data-syntax')) 107 - <input value="$!escapetool.xml($syntaxId)" name="$!{escapedName}_syntax" type="hidden"/> 108 - ## 150 + <input value="$!escapetool.xml($sourceDocument.syntax.toIdString())" name="$!{escapedName}_syntax" type="hidden"/> 109 109 ## Chrome doesn't cache the enabled/disabled state of the form fields so we must store this state in the value of 110 110 ## another form field. For instance, the enabled/disabled state of the RequiresHTMLConversion hidden input 111 111 ## determines which editor mode (WYSIWYG vs. Source) is loaded initially. 112 112 ## See CKEDITOR-34: Wiki syntax gets escaped when you click "Back" in the browser 113 113 <input value="" name="$!{escapedName}_cache" type="hidden" class="cache"/> 114 - ## 115 115 #set ($discard = $parameters.attributes.putAll({ 116 116 'class': "$!parameters.attributes.get('class') ckeditor-textarea loading", 117 - 'spellcheck': false 158 + 'spellcheck': false, 159 + 'data-sourceDocumentSyntax': $sourceDocument.syntax.toIdString() 118 118 })) 119 - ## 120 - #set ($sourceDocumentReference = $parameters.attributes.get('data-sourceDocumentReference')) 121 - #if (!$sourceDocumentReference) 122 - #set ($sourceDocumentReference = $tdoc.documentReference) 123 - #end 124 - #set ($source = { 125 - 'documentReference': $sourceDocumentReference, 126 - 'syntax': $syntaxId, 127 - 'content': $parameters.content, 128 - 'restricted': $parameters.attributes.data-restricted 129 - }) 130 - ## 131 - ## Disable the file upload and drag & drop when the current user doesn't have edit right on the source document, if 132 - ## the source is restricted. This is the case for instance when an user with comment right adds a comment to a page 133 - ## they don't have edit right on. They are allowed to add the comment but they can't upload files because that 134 - ## requires edit right. We check if the source is in restricted mode because in some cases (such as for Change Request 135 - ## Application) we want to allow file upload even if the current user doesn't have edit right on the source document. 136 - #if ($source.restricted == 'true' && !$services.security.authorization.hasAccess('edit', $source.documentReference)) 137 - #set ($parameters.attributes.data-upload-disabled = 'true') 138 - #end 139 - ## We use the velocity template context to convey the startupFocus parameter to CKEditor. 140 - #if ($wysiwygEditorConfig.startupFocus) 141 - #set ($parameters.attributes.data-startup-focus = 'true') 142 - ## We make sure to clear this context so that it doesn't interfere with CKEditors opened later. 143 - #set ($wysiwygEditorConfig.startupFocus = false) 144 - #end 145 - ## 146 146 <textarea 147 147 #foreach ($entry in $parameters.attributes.entrySet()) 148 148 $entry.key="$!escapetool.xml($entry.value)" 149 149 #end 150 150 ## We render the content sheet at the end because the edited content can overwrite the variables used by this macro. 166 + #set ($source = { 167 + 'documentReference': $sourceDocumentReference, 168 + 'syntax': $sourceDocument.syntax, 169 + 'content': $parameters.content 170 + }) 151 151 #set ($content = "#ckeditor_renderContentSheet($source)") 152 152 >$!escapetool.xml($content)</textarea> 153 153 #end ... ... @@ -154,7 +154,7 @@ 154 154 155 155 #macro (displayCKEditorConfigProperty $configDoc $propName $action) 156 156 <dt> 157 - <label for="CKEditor.ConfigClass_$escapetool.xml($configDoc.getObject("CKEditor.ConfigClass").getNumber())_${propName}">$configDoc.displayPrettyName($propName)</label>177 + <label>$configDoc.displayPrettyName($propName)</label> 158 158 <span class="xHint">$escapetool.xml($services.localization.render("CKEditor.ConfigClass_${propName}.hint"))</span> 159 159 </dt> 160 160 <dd>#displayCKEditorConfigPropertyValue($configDoc $propName $action)</dd> ... ... @@ -172,7 +172,10 @@ 172 172 #end 173 173 174 174 #macro (displayCKEditorConfigPropertyValue $configDoc $propName $action) 175 - #unwrapXPropertyDisplay($configDoc.display($propName, $action)) 195 + #set ($output = $configDoc.display($propName, $action)) 196 + #set ($output = $stringtool.removeStart($output, '{{html clean="false" wiki="false"}}')) 197 + #set ($output = $stringtool.removeEnd($output, '{{/html}}')) 198 + $output 176 176 #end 177 177 178 178 #macro (displayCKEditorConfig $configDoc $action) ... ... @@ -199,6 +199,10 @@ 199 199 200 200 #macro (ckeditor_initRequiredSkinExtensions) 201 201 #set ($requiredSkinExtensions = $collectiontool.orderedMap) 225 + #if ("$!requiredSkinExtensions" == '') 226 + ## For XWiki versions older than 12.1RC1 fallback on the old $collectionstool (available since 4.0M1). 227 + #set ($requiredSkinExtensions = $collectionstool.orderedMap) 228 + #end 202 202 ## Save the import string for each skin extension plugin in order to be able to remove the always used extensions 203 203 ## (they are aready available on the edit page so there's no need to load them). 204 204 #foreach ($pluginName in ['ssrx', 'ssfx', 'ssx', 'linkx', 'jsrx', 'jsfx', 'jsx']) ... ... @@ -213,4 +213,20 @@ 213 213 $!stringtool.removeStart($importString, $entry.value).trim()## 214 214 #end 215 215 #end 243 + 244 +#macro (ckeditor_defineSortTool $sortToolVariable) 245 + #set ($checkedExtension = "org.xwiki.commons:xwiki-commons-velocity") 246 + ## Because of an API collision, $collectionstool has been replaced by $collectiontool in XCOMMONS-1861 247 + #if ($services.extension.core.getCoreExtension($checkedExtension).id.version.compareTo("12.1-SNAPSHOT") >= 0) 248 + #setVariable ($sortToolVariable, $collectiontool) 249 + ## With the upgrade of Velocity $sorttool has been replaced by $collectionstool (XCOMMONS-1296) 250 + #elseif ($services.extension.core.getCoreExtension($checkedExtension).id.version.compareTo("12.0-SNAPSHOT") >= 0) 251 + #setVariable ($sortToolVariable, $collectionstool) 252 + ## Old API for sorting was $sorttool 253 + #else 254 + #setVariable ($sortToolVariable, $sorttool) 255 + #end 256 +#end 257 + 258 +#ckeditor_defineSortTool("$resolvedSortTool") 216 216 {{/velocity}}