Changes for page Attachments
Last modified by Ludovic Dubost on 2024/07/22 15:50
From version 4.1
edited by Ludovic Dubost
on 2017/02/07 23:57
on 2017/02/07 23:57
Change comment:
Install extension [org.xwiki.platform:xwiki-platform-attachment-ui-8.4.4]
To version 11.1
edited by Ludovic Dubost
on 2020/07/30 11:14
on 2020/07/30 11:14
Change comment:
Install extension [org.xwiki.platform:xwiki-platform-attachment-ui/12.3]
Summary
-
Page properties (1 modified, 0 added, 0 removed)
-
Objects (6 modified, 1 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -1,17 +1,21 @@ 1 1 {{velocity output="false"}} 2 +#set ($translationPrefix = 'xe.attachmentSelector') 3 + 2 2 #if ($request.xaction == 'postUpload') 3 3 #set ($targetDocument = $xwiki.getDocument($request.get('docname'))) 4 4 #set ($targetAttachDocument = $xwiki.getDocument($request.get('targetdocname'))) 5 5 6 6 #set ($fieldname = $request.get('fieldname')) 9 + #set ($comment = $services.localization.render("${translationPrefix}.postUpload.comment", [$fieldname])) 7 7 #set ($docAction = $request.get('docAction')) 8 8 #set ($attachmentList = $targetAttachDocument.getAttachmentList()) 9 9 #if ($attachmentList && $attachmentList.size() > 0) 10 - #set ($sortedAttachments = $ sorttool.sort($attachmentList, 'date:desc'))13 + #set ($sortedAttachments = $collectiontool.sort($attachmentList, 'date:desc')) 11 11 #set ($lastAttachment = $sortedAttachments.get(0)) 12 12 #end 13 13 $response.sendRedirect($targetDocument.getURL($docAction, $escapetool.url({ 14 14 $fieldname: $lastAttachment.filename, 18 + 'comment': $comment, 15 15 'form_token': $request.form_token 16 16 }))) 17 17 #stop ... ... @@ -22,7 +22,6 @@ 22 22 ## 23 23 ## Macros 24 24 ## 25 -#set ($translationPrefix = 'xe.attachmentSelector') 26 26 #set ($attachmentPickerDocName = 'XWiki.AttachmentSelector') 27 27 28 28 $xwiki.ssx.use($attachmentPickerDocName) ... ... @@ -46,7 +46,7 @@ 46 46 #attachmentPicker_displayUploadForm($targetDocument, $targetAttachDocument, $options) 47 47 #end 48 48 #attachmentPicker_displayAttachmentGalleryEmptyValue($targetDocument, $targetAttachDocument, $options, $currentValue) 49 - #set ($sortedAttachments = $ sorttool.sort($targetAttachDocument.getAttachmentList(), "${options.sortAttachmentsBy}") )52 + #set ($sortedAttachments = $collectiontool.sort($targetAttachDocument.getAttachmentList(), "${options.sortAttachmentsBy}") ) 50 50 #foreach ($attachment in $sortedAttachments) 51 51 #set ($extension = $attachment.getFilename()) 52 52 #set ($extension = $extension.substring($mathtool.add($extension.lastIndexOf('.'), 1)).toLowerCase()) ... ... @@ -102,14 +102,19 @@ 102 102 *# 103 103 #macro (attachmentPicker_displayAttachmentDetails $attachment $options) 104 104 #if ($attachment) 108 + ## Compute the attachment reference because there's no getter. 109 + #set ($attachmentReference = $services.model.createAttachmentReference($attachment.document.documentReference, 110 + $attachment.filename)) 111 + #set ($attachmentStringReference = $services.model.serialize($attachmentReference, 'default')) 105 105 #if ($attachment.isImage() && $options.displayImage) 106 - #set ($attachmentDocument = $attachment.getDocument()) 107 -[[[[image:${attachmentDocument.fullName}@${attachment.filename}||width=180]]>>attach:${attachmentDocument.fullName}@${attachment.filename}||rel="lightbox[attachments]"]] 113 + ## We add the version to the query string in order to invalidate the cache when an image attachment is replaced. 114 + #set ($queryString = $escapetool.url({'version': $attachment.version})) 115 + [[[[image:${attachmentStringReference}||width=180 queryString="$queryString"]]>>attach:$attachmentStringReference]] 108 108 #else 109 109 * (% class="mime" %){{html wiki=false clean=false}}#mimetypeimg($attachment.getMimeType().toLowerCase() $attachment.getFilename().toLowerCase()){{/html}}(%%) (% class="filename" %)$attachment.getFilename()(% %) 110 - * v$attachment.getVersion() (#dynamicsize($attachment. filesize))118 + * v$attachment.getVersion() (#dynamicsize($attachment.longSize)) 111 111 * $services.localization.render('core.viewers.attachments.author', [$!{xwiki.getUserName($attachment.author, false)}]) $services.localization.render('core.viewers.attachments.date', [$!{xwiki.formatDate($attachment.date, 'dd/MM/yyyy hh:mm')}]) 112 - * (% class="buttonwrapper" %)[[${services.localization.render("${translationPrefix}.actions.download")}>>attach:${attachment .getDocument()}@${attachment.filename}||title="$services.localization.render("${translationPrefix}.actions.download")" rel="__blank" class="button"]](%%)120 + * (% class="buttonwrapper" %)[[${services.localization.render("${translationPrefix}.actions.download")}>>attach:${attachmentStringReference}||title="$services.localization.render("${translationPrefix}.actions.download")" rel="__blank" class="button"]](%%) 113 113 #end 114 114 #end 115 115 #end ... ... @@ -157,7 +157,7 @@ 157 157 #if (${options.rawfilter} != '') 158 158 <span class="xHint">$escapetool.xml($services.localization.render("${translationPrefix}.upload.hint", [${options.rawfilter}]))</span> 159 159 #end 160 - <input type="file" name="filepath" id="attachfile" class=" attachment" size="30"title="$!{escapetool.xml($options.rawfilter)}"/>168 + <input type="file" name="filepath" id="attachfile" class="noitems" title="$!{escapetool.xml($options.rawfilter)}"/> 161 161 <input type="hidden" name="xredirect" value="$xwiki.getDocument($attachmentPickerDocName).getURL('get', "xaction=postUpload&docAction=$!{escapetool.url($options.get('docAction'))}&targetdocname=$!{escapetool.url($targetAttachDocument.fullName)}&docname=$!{escapetool.url($targetDocument.fullName)}&fieldname=$!{escapetool.url($options.get('classname'))}_$!{escapetool.url($options.get('object'))}_$!{escapetool.url($options.get('property'))}&form_token=$!{services.csrf.getToken()}")" /> 162 162 <input type="hidden" name="docname" value="$!{escapetool.xml($targetDocument.fullName)}" /> 163 163 <input type="hidden" name="classname" value="$!{escapetool.xml($options.get('classname'))}" /> ... ... @@ -165,6 +165,27 @@ 165 165 <input type="hidden" name="property" value="$!{escapetool.xml($options.get('property'))}" /> 166 166 <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" /> 167 167 </div> 176 + #if ("$!currentValue" != '' && $currentValue != $options.defaultValue) 177 + <div> 178 + <label> 179 + <input type="checkbox" name="filename" value="$!escapetool.xml($currentValue)" 180 + />$services.localization.render('attachmentSelector.replace', 181 + ["<strong>$!escapetool.xml($currentValue)</strong>"]) 182 + </label> 183 + <span class="xHint">$escapetool.xml($services.localization.render('attachmentSelector.replace.hint'))</span> 184 + </div> 185 + #end 186 + #if ($xwiki.hasEditComment() && $options.versionSummary) 187 + <div> 188 + #if ($xwiki.isEditCommentFieldHidden()) 189 + <input type="hidden" name="comment" value="$!escapetool.xml($request.comment)" /> 190 + #else 191 + <label for="commentinput">$services.localization.render('core.comment')</label> 192 + <input type="text" name="comment" id="commentinput" value="$!escapetool.xml($request.comment)" 193 + title="$services.localization.render('core.comment.tooltip')" /> 194 + #end 195 + </div> 196 + #end 168 168 <div class="buttons"> 169 169 <span class="buttonwrapper"> 170 170 <input type="submit" name="action_upload" class="button " value='$services.localization.render("${translationPrefix}.upload.submit")' title='$services.localization.render("${translationPrefix}.upload.submit")'/> ... ... @@ -208,11 +208,6 @@ 208 208 209 209 {{velocity}} 210 210 #if ($request.docname) 211 - ###if ($request.xpage == 'plain') 212 - ## ## IE6 + XHR + gzip compression = BOOM! 213 - ## ## This disables the automatic gzip compression 214 - ## $response.setContentType('multipart/formdata') 215 - ###end 216 216 #set ($targetDocument = $xwiki.getDocument($request.docname)) 217 217 #if ($request.targetdocname) 218 218 ## Use the target document if it exists. ... ... @@ -261,7 +261,7 @@ 261 261 #end 262 262 #set ($options = { 263 263 'classname' : ${request.get('classname')}, 264 - 'object' : $!{m athtool.toInteger($request.object)},288 + 'object' : $!{numbertool.toNumber($request.object).intValue()}, 265 265 'property' : ${request.property}, 266 266 'displayImage' : ${displayImage}, 267 267 'docAction' : ${docAction}, ... ... @@ -268,13 +268,14 @@ 268 268 'defaultValue' : "$!{request.defaultValue}", 269 269 'rawfilter': "$!{rawfilter}", 270 270 'filter': ${filter}, 271 - 'sortAttachmentsBy': ${sortAttachmentsBy} 295 + 'sortAttachmentsBy': ${sortAttachmentsBy}, 296 + 'versionSummary': $request.versionSummary.equals('true') 272 272 }) 273 273 $!targetDocument.use($targetDocument.getObject($options.classname, $options.object))## 274 274 #attachmentPicker_displayAttachmentGallery($targetDocument, $targetAttachDocument, $options) 275 275 276 276 (% class="gallery_buttons buttons" %)((( 277 - (% class="buttonwrapper secondary" %)[[$services.localization.render("${translationPrefix}.cancel")>>$targetDocument||class="button secondary" id="attachment-picker-close"]] 302 + (% class="buttonwrapper secondary" %)[[$services.localization.render("${translationPrefix}.cancel")>>${targetDocument}||class="button secondary" id="attachment-picker-close"]] 278 278 ))) 279 279 #end 280 280 {{/velocity}}
- XWiki.JavaScriptExtension[0]
-
- Code
-
... ... @@ -40,7 +40,7 @@ 40 40 * and saves the underlying form (if any) so that any unsaved changes won't be lost. 41 41 */ 42 42 filterFormUpload : function() { 43 - this.gallery.select('.uploadAttachment input .attachment').each(function(fileInput) {43 + this.gallery.select('.uploadAttachment input[type="file"]').each(function(fileInput) { 44 44 fileInput.__allowedExtensions = fileInput.title.toLowerCase().replace(/\s*[,|; ]\s*/g, " ").strip(); 45 45 if (fileInput.__allowedExtensions != '') { 46 46 fileInput.__allowedExtensions = fileInput.__allowedExtensions.split(" "); ... ... @@ -52,7 +52,7 @@ 52 52 event.stop(); 53 53 var uploadForm = event.element(); 54 54 var hasErrors = false; 55 - uploadForm.select('input .attachment').each(function(fileInput) {55 + uploadForm.select('input[type="file"]').each(function(fileInput) { 56 56 if (fileInput.value == '') { 57 57 new XWiki.widgets.Notification("$services.localization.render('xe.attachmentSelector.upload.error.noFile')", 'error'); 58 58 hasErrors = true; ... ... @@ -68,7 +68,7 @@ 68 68 uploadForm.submit(); 69 69 } else { 70 70 // FIXME This fails in HTML5, will deal with it later: 71 - // this.property.down('input').value = uploadForm.down(' .attachment').value;71 + // this.property.down('input').value = uploadForm.down('input[type="file"]').value; 72 72 // uploadForm.xredirect.value = window.location.pathname; 73 73 document.observe('xwiki:document:saved', function() { 74 74 new XWiki.widgets.Notification("$services.localization.render('xe.attachmentSelector.upload.inProgress')", 'inprogress'); ... ... @@ -117,6 +117,11 @@ 117 117 if (this.gallery.down('.gallery_emptyChoice')) { 118 118 this.gallery.down('.gallery_emptyChoice').addClassName('current'); 119 119 } 120 + // Disable the replace feature because there's no selection. 121 + var fileNameInput = this.gallery.down('input[type="checkbox"][name="filename"]'); 122 + fileNameInput.disabled = true; 123 + // Empty the displayed selected file name. 124 + fileNameInput.up('label').down('strong').update(''); 120 120 if (!this.directSave) { 121 121 this.property.down('input').value = this.defaultValue; 122 122 } ... ... @@ -270,11 +270,7 @@ 270 270 ); 271 271 dialog.shortcuts.close.keys = []; 272 272 dialog.showDialog(); 273 - if (window.browser.isIE6x) { 274 - dialog.dialog.down().setStyle({position: "absolute"}); 275 - } else { 276 - dialog.dialog.down().setStyle({position: "fixed"}); 277 - } 278 + dialog.dialog.down().setStyle({position: "fixed"}); 278 278 dialog.dialog.setStyle({top: document.viewport.getScrollOffsets().top + "px", position: "absolute"}); 279 279 dialog.dialogBox.setStyle({overflow: "hidden", width: "80%", margin: "0 10%"}); 280 280 new Ajax.Updater(loading.up(), url, {
- XWiki.StyleSheetExtension[0]
-
- Code
-
... ... @@ -34,19 +34,11 @@ 34 34 position: relative; 35 35 width: ${boxSize}px; 36 36 } 37 -/* Broken IE6 box model, add the border width to the total width. */ 38 -* html .gallery_attachmentbox { 39 - width: ${mathtool.add($boxSize, 2)}px; 40 -} 41 41 .gallery .current { 42 42 background-color: $theme.highlightColor; 43 43 border-width: 3px; 44 44 margin: 3px; 45 45 } 46 -/* Broken IE6 box model, add the border width to the total width. */ 47 -* html .gallery .current { 48 - width: ${mathtool.add($boxSize, 6)}px; 49 -} 50 50 .gallery .current .gallery_attachmenttitle { 51 51 font-weight: bold; 52 52 } ... ... @@ -161,24 +161,29 @@ 161 161 background-repeat: no-repeat; 162 162 padding-left: 16px; 163 163 } 164 -.gallery_upload f orm {165 - height: ${imgSize}px;156 +.gallery_upload .gallery_attachmentframe { 157 + height: auto; 166 166 } 167 -.gallery_upload .xHint {168 - text-transform:none !important;159 +.gallery_upload_input { 160 + margin-bottom: 10px; 169 169 } 170 -.gallery_upload input.attachment { 171 - font-size: 83.3%; 172 - margin: 0; /* Overrides viewers/attachments.css */ 173 - padding: 0; /* Overrides viewers/attachments.css */ 162 +.gallery_upload input[type="file"] { 163 + font-size: 86%; 174 174 width: ${mathtool.sub($uploadBoxSize, $mathtool.mul($boxPadding, 2))}px; 175 175 } 176 176 .gallery_upload .buttonwrapper { 177 177 margin: 0; 178 178 } 179 -.gallery_upload .button { 180 - font-size: .65em; 169 +.gallery_upload .button, 170 +.gallery_upload label { 171 + font-size: 86%; 181 181 } 173 +.gallery_upload input[type="checkbox"] { 174 + vertical-align: text-bottom; 175 +} 176 +.gallery_upload label[for="commentinput"] { 177 + margin-top: 10px; 178 +} 182 182 183 183 /* ------------------------------------ */ 184 184 /* Buttons on top: */
- XWiki.WikiMacroClass[0]
-
- Cached
-
... ... @@ -1,0 +1,1 @@ 1 +No - Asynchronous rendering
-
... ... @@ -1,0 +1,1 @@ 1 +No - Macro code
-
... ... @@ -32,7 +32,7 @@ 32 32 #end 33 33 #set ($classname = "$!{xcontext.macro.params.classname}") 34 34 #set ($property = "$!{xcontext.macro.params.property}") 35 -#set ($object = $m athtool.toInteger("$!{xcontext.macro.params.object}"))35 +#set ($object = $numbertool.toNumber("$!{xcontext.macro.params.object}").intValue()) 36 36 #if ("$!{object}" != $!{xcontext.macro.params.object}) 37 37 #set ($object = ${doc.getObject($classname).number}) 38 38 #if ("$!{object}" == '') ... ... @@ -123,7 +123,24 @@ 123 123 ## 1. Edit the current page 124 124 ## 2. View the target attachment page. (can be the same page) 125 125 #macro (attachmentPicker_displayButton) 126 - #if ($hasEdit && $targetPermView)(% class="buttonwrapper" %)[[${buttontext}>>${xcontext.macro.doc.fullName}||queryString="#if ($hasTargetDoc)targetdocname=${escapetool.url($targetdoc.fullName)}&#{end}docname=${escapetool.url($doc.fullName)}&classname=${classname}&property=${property}&object=${object}&savemode=${savemode}&defaultValue=$escapetool.url($defaultValue)&filter=$!{filter}&displayImage=${displayImage}" class="attachment-picker-start button" title="${buttontext}"]](%%)#end 126 + #if ($hasEdit && $targetPermView) 127 + #set ($queryString = { 128 + 'docname': $doc.fullName, 129 + 'classname': $classname, 130 + 'property': $property, 131 + 'object': $object, 132 + 'savemode': $savemode, 133 + 'defaultValue': $defaultValue, 134 + 'filter': $filter, 135 + 'displayImage': $displayImage, 136 + 'versionSummary': $xcontext.macro.params.versionSummary.equals('true') 137 + }) 138 + #if ($hasTargetDoc) 139 + #set ($queryString.targetdocname = $targetdoc.fullName) 140 + #end 141 + (% class="buttonwrapper" %)[[$buttontext>>${xcontext.macro.doc.fullName}||queryString="$escapetool.url($queryString)" 142 + class="attachment-picker-start button" title="$buttontext"]](%%)## 143 + #end 127 127 #end 128 128 {{/velocity}} 129 129 - Default category
-
... ... @@ -1,0 +1,1 @@ 1 +Development
- XWiki.WikiMacroParameterClass[0]
-
- Parameter type
-
... ... @@ -1,0 +1,1 @@ 1 +org.xwiki.model.reference.DocumentReference
- XWiki.WikiMacroParameterClass[10]
-
- Parameter type
-
... ... @@ -1,0 +1,1 @@ 1 +org.xwiki.model.reference.AttachmentReference
- XWiki.WikiMacroParameterClass[18]
-
- Parameter type
-
... ... @@ -1,0 +1,1 @@ 1 +org.xwiki.model.reference.DocumentReference
- XWiki.WikiMacroParameterClass[19]
-
- Parameter default value
-
... ... @@ -1,0 +1,1 @@ 1 +false - Parameter description
-
... ... @@ -1,0 +1,1 @@ 1 +Whether to allow the user to enter a version summary that will be recorded in the history. An automatic message is used when no version summary is provided or if the version summary input is not displayed. - Parameter mandatory
-
... ... @@ -1,0 +1,1 @@ 1 +No - Parameter name
-
... ... @@ -1,0 +1,1 @@ 1 +versionSummary