From 86317e3e85fcc73d99bd694030ca7e4792bc6123 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Fri, 3 Jul 2020 23:15:03 +0000 Subject: [PATCH] Media: Show an error message when a `.heic` file is uploaded that this type of files cannot be displayed in a web browser and suggesting to convert to JPEG. The message is shown by using filters, plugins that want to handle uploading of `.heic` files can remove it. Props mattheweppelsheimer, mikeschroder, jeffr0, andraganescu, desrosj, azaozz. Fixes #42775. Built from https://develop.svn.wordpress.org/trunk@48288 git-svn-id: http://core.svn.wordpress.org/trunk@48057 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/admin-filters.php | 1 + wp-includes/default-filters.php | 1 + wp-includes/functions.php | 1 + wp-includes/js/plupload/handlers.js | 5 +++++ wp-includes/js/plupload/handlers.min.js | 2 +- wp-includes/js/plupload/wp-plupload.js | 9 +++++++++ wp-includes/js/plupload/wp-plupload.min.js | 2 +- wp-includes/media.php | 19 +++++++++++++++++-- wp-includes/script-loader.php | 1 + wp-includes/version.php | 2 +- 10 files changed, 38 insertions(+), 5 deletions(-) diff --git a/wp-admin/includes/admin-filters.php b/wp-admin/includes/admin-filters.php index 7f9e09e0ed..345a6114af 100644 --- a/wp-admin/includes/admin-filters.php +++ b/wp-admin/includes/admin-filters.php @@ -15,6 +15,7 @@ add_action( 'activity_box_end', 'wp_dashboard_quota' ); // Media hooks. add_action( 'attachment_submitbox_misc_actions', 'attachment_submitbox_metadata' ); +add_filter( 'plupload_init', 'wp_show_heic_upload_error' ); add_action( 'media_upload_image', 'wp_media_upload_handler' ); add_action( 'media_upload_audio', 'wp_media_upload_handler' ); diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 2fd1d33b69..dc51908604 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -534,6 +534,7 @@ add_filter( 'the_content', 'do_shortcode', 11 ); // AFTER wpautop(). add_action( 'wp_playlist_scripts', 'wp_playlist_scripts' ); add_action( 'customize_controls_enqueue_scripts', 'wp_plupload_default_settings' ); add_action( 'plugins_loaded', '_wp_add_additional_image_sizes', 0 ); +add_filter( 'plupload_default_settings', 'wp_show_heic_upload_error' ); // Nav menu. add_filter( 'nav_menu_item_id', '_nav_menu_item_id_use_once', 10, 2 ); diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 4fea38c7fa..5a2abd808c 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -3046,6 +3046,7 @@ function wp_get_mime_types() { 'bmp' => 'image/bmp', 'tiff|tif' => 'image/tiff', 'ico' => 'image/x-icon', + 'heic' => 'image/heic', // Video formats. 'asf|asx' => 'video/x-ms-asf', 'wmv' => 'video/x-ms-wmv', diff --git a/wp-includes/js/plupload/handlers.js b/wp-includes/js/plupload/handlers.js index 1edfc5cf42..884d8596fc 100644 --- a/wp-includes/js/plupload/handlers.js +++ b/wp-includes/js/plupload/handlers.js @@ -568,6 +568,11 @@ jQuery( document ).ready( function( $ ) { uploadStart(); plupload.each( files, function( file ) { + if ( file.type === 'image/heic' && up.settings.heic_upload_error ) { + // Show error but do not block uploading. + wpQueueError( pluploadL10n.unsupported_image ) + } + fileQueued( file ); }); diff --git a/wp-includes/js/plupload/handlers.min.js b/wp-includes/js/plupload/handlers.min.js index fee9795d24..f927a21c92 100644 --- a/wp-includes/js/plupload/handlers.min.js +++ b/wp-includes/js/plupload/handlers.min.js @@ -1 +1 @@ -var uploader,uploader_init,topWin=window.dialogArguments||opener||parent||top;function fileQueued(e){jQuery(".media-blank").remove();var a=jQuery("#media-items").children(),r=post_id||0;1==a.length&&a.removeClass("open").find(".slidetoggle").slideUp(200),jQuery('
').attr("id","media-item-"+e.id).addClass("child-of-"+r).append('
0%
',jQuery('
').text(" "+e.name)).appendTo(jQuery("#media-items")),jQuery("#insert-gallery").prop("disabled",!0)}function uploadStart(){try{void 0!==topWin.tb_remove&&topWin.jQuery("#TB_overlay").unbind("click",topWin.tb_remove)}catch(e){}return!0}function uploadProgress(e,a){var r=jQuery("#media-item-"+a.id);jQuery(".bar",r).width(200*a.loaded/a.size),jQuery(".percent",r).html(a.percent+"%")}function fileUploading(e,a){var r=104857600;rr&&setTimeout(function(){a.status<3&&0===a.loaded&&(wpFileError(a,pluploadL10n.big_upload_failed.replace("%1$s",'').replace("%2$s","")),e.stop(),e.removeFile(a),e.start())},1e4)}function updateMediaForm(){var e=jQuery("#media-items").children();1==e.length?(e.addClass("open").find(".slidetoggle").show(),jQuery(".insert-gallery").hide()):1(\d+)<\/pre>$/,"$1"),/media-upload-error|error-div/.test(a))?r.html(a):(r.find(".percent").html(pluploadL10n.crunching),prepareMediaItem(e,a),updateMediaForm(),post_id&&r.hasClass("child-of-"+post_id)&&jQuery("#attachments-count").text(1*jQuery("#attachments-count").text()+1))}function setResize(e){e?window.resize_width&&window.resize_height?uploader.settings.resize={enabled:!0,width:window.resize_width,height:window.resize_height,quality:100}:uploader.settings.multipart_params.image_resize=!0:delete uploader.settings.multipart_params.image_resize}function prepareMediaItem(e,a){var r="undefined"==typeof shortform?1:2,i=jQuery("#media-item-"+e.id);2==r&&2

'+e+"

")}function wpFileError(e,a){itemAjaxError(e.id,a)}function itemAjaxError(e,a){var r=jQuery("#media-item-"+e),i=r.find(".filename").text();r.data("last-err")!=e&&r.html('
'+pluploadL10n.dismiss+""+pluploadL10n.error_uploading.replace("%s",jQuery.trim(i))+" "+a+"
").data("last-err",e)}function deleteSuccess(e){var a,r,i;return"-1"==e?itemAjaxError(this.id,"You do not have permission. Has your session expired?"):"0"==e?itemAjaxError(this.id,"Could not be deleted. Has it been deleted already?"):(r=this.id,i=jQuery("#media-item-"+r),(a=jQuery("#type-of-"+r).val())&&jQuery("#"+a+"-counter").text(jQuery("#"+a+"-counter").text()-1),post_id&&i.hasClass("child-of-"+post_id)&&jQuery("#attachments-count").text(jQuery("#attachments-count").text()-1),1==jQuery("form.type-form #media-items").children().length&&0 '+pluploadL10n.deleted+" ").siblings("a.toggle").hide(),jQuery(".filename",i).append(jQuery("a.undo",i).removeClass("hidden")),void jQuery(".menu_order_input",i).hide())}function deleteError(){}function uploadComplete(){jQuery("#insert-gallery").prop("disabled",!1)}function switchUploader(e){e?(deleteUserSetting("uploader"),jQuery(".media-upload-form").removeClass("html-uploader"),"object"==typeof uploader&&uploader.refresh()):(setUserSetting("uploader","1"),jQuery(".media-upload-form").addClass("html-uploader"))}function uploadError(e,a,r,i){var t=104857600;switch(a){case plupload.FAILED:wpFileError(e,pluploadL10n.upload_failed);break;case plupload.FILE_EXTENSION_ERROR:wpFileExtensionError(i,e,pluploadL10n.invalid_filetype);break;case plupload.FILE_SIZE_ERROR:uploadSizeError(i,e);break;case plupload.IMAGE_FORMAT_ERROR:wpFileError(e,pluploadL10n.not_an_image);break;case plupload.IMAGE_MEMORY_ERROR:wpFileError(e,pluploadL10n.image_memory_exceeded);break;case plupload.IMAGE_DIMENSIONS_ERROR:wpFileError(e,pluploadL10n.image_dimensions_exceeded);break;case plupload.GENERIC_ERROR:wpQueueError(pluploadL10n.upload_failed);break;case plupload.IO_ERROR:tt?wpFileError(e,pluploadL10n.big_upload_failed.replace("%1$s",'').replace("%2$s","")):wpQueueError(pluploadL10n.io_error);break;case plupload.HTTP_ERROR:wpQueueError(pluploadL10n.http_error);break;case plupload.INIT_ERROR:jQuery(".media-upload-form").addClass("html-uploader");break;case plupload.SECURITY_ERROR:wpQueueError(pluploadL10n.security_error);break;default:wpFileError(e,pluploadL10n.default_error)}}function uploadSizeError(e,a){var r,i;r=pluploadL10n.file_exceeds_size_limit.replace("%s",a.name),i=jQuery("
").attr({id:"media-item-"+a.id,class:"media-item error"}).append(jQuery("

").text(r)),jQuery("#media-items").append(i),e.removeFile(a)}function wpFileExtensionError(e,a,r){jQuery("#media-items").append('

'+r+"

"),e.removeFile(a)}jQuery(document).ready(function(d){var o,l={};d(".media-upload-form").bind("click.uploader",function(e){var a,r,i=d(e.target);i.is('input[type="radio"]')?(a=i.closest("tr")).hasClass("align")?setUserSetting("align",i.val()):a.hasClass("image-size")&&setUserSetting("imgsize",i.val()):i.is("button.button")?(r=(r=e.target.className||"").match(/url([^ '"]+)/))&&r[1]&&(setUserSetting("urlbutton",r[1]),i.siblings(".urlfield").val(i.data("link-url"))):i.is("a.dismiss")?i.parents(".media-item").fadeOut(200,function(){d(this).remove()}):i.is(".upload-flash-bypass a")||i.is("a.uploader-html")?(d("#media-items, p.submit, span.big-file-warning").css("display","none"),switchUploader(0),e.preventDefault()):i.is(".upload-html-bypass a")?(d("#media-items, p.submit, span.big-file-warning").css("display",""),switchUploader(1),e.preventDefault()):i.is("a.describe-toggle-on")?(i.parent().addClass("open"),i.siblings(".slidetoggle").fadeIn(250,function(){var e,a,r=d(window).scrollTop(),i=d(window).height(),t=d(this).offset().top,o=d(this).height();i&&t&&o&&(a=r+i)<(e=t+o)&&(e-a').attr("id","media-item-"+e.id).addClass("child-of-"+r).append('
0%
',jQuery('
').text(" "+e.name)).appendTo(jQuery("#media-items")),jQuery("#insert-gallery").prop("disabled",!0)}function uploadStart(){try{void 0!==topWin.tb_remove&&topWin.jQuery("#TB_overlay").unbind("click",topWin.tb_remove)}catch(e){}return!0}function uploadProgress(e,a){var r=jQuery("#media-item-"+a.id);jQuery(".bar",r).width(200*a.loaded/a.size),jQuery(".percent",r).html(a.percent+"%")}function fileUploading(e,a){var r=104857600;rr&&setTimeout(function(){a.status<3&&0===a.loaded&&(wpFileError(a,pluploadL10n.big_upload_failed.replace("%1$s",'').replace("%2$s","")),e.stop(),e.removeFile(a),e.start())},1e4)}function updateMediaForm(){var e=jQuery("#media-items").children();1==e.length?(e.addClass("open").find(".slidetoggle").show(),jQuery(".insert-gallery").hide()):1(\d+)<\/pre>$/,"$1"),/media-upload-error|error-div/.test(a))?r.html(a):(r.find(".percent").html(pluploadL10n.crunching),prepareMediaItem(e,a),updateMediaForm(),post_id&&r.hasClass("child-of-"+post_id)&&jQuery("#attachments-count").text(1*jQuery("#attachments-count").text()+1))}function setResize(e){e?window.resize_width&&window.resize_height?uploader.settings.resize={enabled:!0,width:window.resize_width,height:window.resize_height,quality:100}:uploader.settings.multipart_params.image_resize=!0:delete uploader.settings.multipart_params.image_resize}function prepareMediaItem(e,a){var r="undefined"==typeof shortform?1:2,i=jQuery("#media-item-"+e.id);2==r&&2

'+e+"

")}function wpFileError(e,a){itemAjaxError(e.id,a)}function itemAjaxError(e,a){var r=jQuery("#media-item-"+e),i=r.find(".filename").text();r.data("last-err")!=e&&r.html('
'+pluploadL10n.dismiss+""+pluploadL10n.error_uploading.replace("%s",jQuery.trim(i))+" "+a+"
").data("last-err",e)}function deleteSuccess(e){var a,r,i;return"-1"==e?itemAjaxError(this.id,"You do not have permission. Has your session expired?"):"0"==e?itemAjaxError(this.id,"Could not be deleted. Has it been deleted already?"):(r=this.id,i=jQuery("#media-item-"+r),(a=jQuery("#type-of-"+r).val())&&jQuery("#"+a+"-counter").text(jQuery("#"+a+"-counter").text()-1),post_id&&i.hasClass("child-of-"+post_id)&&jQuery("#attachments-count").text(jQuery("#attachments-count").text()-1),1==jQuery("form.type-form #media-items").children().length&&0 '+pluploadL10n.deleted+" ").siblings("a.toggle").hide(),jQuery(".filename",i).append(jQuery("a.undo",i).removeClass("hidden")),void jQuery(".menu_order_input",i).hide())}function deleteError(){}function uploadComplete(){jQuery("#insert-gallery").prop("disabled",!1)}function switchUploader(e){e?(deleteUserSetting("uploader"),jQuery(".media-upload-form").removeClass("html-uploader"),"object"==typeof uploader&&uploader.refresh()):(setUserSetting("uploader","1"),jQuery(".media-upload-form").addClass("html-uploader"))}function uploadError(e,a,r,i){var t=104857600;switch(a){case plupload.FAILED:wpFileError(e,pluploadL10n.upload_failed);break;case plupload.FILE_EXTENSION_ERROR:wpFileExtensionError(i,e,pluploadL10n.invalid_filetype);break;case plupload.FILE_SIZE_ERROR:uploadSizeError(i,e);break;case plupload.IMAGE_FORMAT_ERROR:wpFileError(e,pluploadL10n.not_an_image);break;case plupload.IMAGE_MEMORY_ERROR:wpFileError(e,pluploadL10n.image_memory_exceeded);break;case plupload.IMAGE_DIMENSIONS_ERROR:wpFileError(e,pluploadL10n.image_dimensions_exceeded);break;case plupload.GENERIC_ERROR:wpQueueError(pluploadL10n.upload_failed);break;case plupload.IO_ERROR:tt?wpFileError(e,pluploadL10n.big_upload_failed.replace("%1$s",'').replace("%2$s","")):wpQueueError(pluploadL10n.io_error);break;case plupload.HTTP_ERROR:wpQueueError(pluploadL10n.http_error);break;case plupload.INIT_ERROR:jQuery(".media-upload-form").addClass("html-uploader");break;case plupload.SECURITY_ERROR:wpQueueError(pluploadL10n.security_error);break;default:wpFileError(e,pluploadL10n.default_error)}}function uploadSizeError(e,a){var r,i;r=pluploadL10n.file_exceeds_size_limit.replace("%s",a.name),i=jQuery("
").attr({id:"media-item-"+a.id,class:"media-item error"}).append(jQuery("

").text(r)),jQuery("#media-items").append(i),e.removeFile(a)}function wpFileExtensionError(e,a,r){jQuery("#media-items").append('

'+r+"

"),e.removeFile(a)}jQuery(document).ready(function(d){var o,l={};d(".media-upload-form").bind("click.uploader",function(e){var a,r,i=d(e.target);i.is('input[type="radio"]')?(a=i.closest("tr")).hasClass("align")?setUserSetting("align",i.val()):a.hasClass("image-size")&&setUserSetting("imgsize",i.val()):i.is("button.button")?(r=(r=e.target.className||"").match(/url([^ '"]+)/))&&r[1]&&(setUserSetting("urlbutton",r[1]),i.siblings(".urlfield").val(i.data("link-url"))):i.is("a.dismiss")?i.parents(".media-item").fadeOut(200,function(){d(this).remove()}):i.is(".upload-flash-bypass a")||i.is("a.uploader-html")?(d("#media-items, p.submit, span.big-file-warning").css("display","none"),switchUploader(0),e.preventDefault()):i.is(".upload-html-bypass a")?(d("#media-items, p.submit, span.big-file-warning").css("display",""),switchUploader(1),e.preventDefault()):i.is("a.describe-toggle-on")?(i.parent().addClass("open"),i.siblings(".slidetoggle").fadeIn(250,function(){var e,a,r=d(window).scrollTop(),i=d(window).height(),t=d(this).offset().top,o=d(this).height();i&&t&&o&&(a=r+i)<(e=t+o)&&(e-a').css({position:"fixed",top:"-1000px",left:"-1000px",height:0,width:0}).attr("id","wp-uploader-browser-"+this.uploader.id).appendTo("body")),a.append(this.browser))}this.uploader.refresh()}}),l.queue=new wp.media.model.Attachments([],{query:!1}),l.errors=new Backbone.Collection,e.Uploader=l)}(wp,jQuery); \ No newline at end of file +window.wp=window.wp||{},function(e,u){var l;"undefined"!=typeof _wpPluploadSettings&&(l=function(e){var n,t,i,p,d=this,a={container:"container",browser:"browse_button",dropzone:"drop_element"},s={};if(this.supports={upload:l.browser.supported},this.supported=this.supports.upload,this.supported){for(t in this.plupload=u.extend(!0,{multipart_params:{}},l.defaults),this.container=document.body,u.extend(!0,this,e),this)u.isFunction(this[t])&&(this[t]=u.proxy(this[t],this));for(t in a)this[t]&&(this[t]=u(this[t]).first(),this[t].length?(this[t].prop("id")||this[t].prop("id","__wp-uploader-id-"+l.uuid++),this.plupload[a[t]]=this[t].prop("id")):delete this[t]);(this.browser&&this.browser.length||this.dropzone&&this.dropzone.length)&&(this.uploader=new plupload.Uploader(this.plupload),delete this.plupload,this.param(this.params||{}),delete this.params,n=function(t,a,r){var e,o;if(a&&a.responseHeaders)if((o=a.responseHeaders.match(/x-wp-upload-attachment-id:\s*(\d+)/i))&&o[1]){if(o=o[1],(e=s[r.id])&&4').css({position:"fixed",top:"-1000px",left:"-1000px",height:0,width:0}).attr("id","wp-uploader-browser-"+this.uploader.id).appendTo("body")),a.append(this.browser))}this.uploader.refresh()}}),l.queue=new wp.media.model.Attachments([],{query:!1}),l.errors=new Backbone.Collection,e.Uploader=l)}(wp,jQuery); \ No newline at end of file diff --git a/wp-includes/media.php b/wp-includes/media.php index 5fe27ba113..18cc3d6d30 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -3599,8 +3599,10 @@ function wp_plupload_default_settings() { * * @param array $params Default Plupload parameters array. */ - $params = apply_filters( 'plupload_default_params', $params ); - $params['_wpnonce'] = wp_create_nonce( 'media-form' ); + $params = apply_filters( 'plupload_default_params', $params ); + + $params['_wpnonce'] = wp_create_nonce( 'media-form' ); + $defaults['multipart_params'] = $params; $settings = array( @@ -4686,3 +4688,16 @@ function _wp_add_additional_image_sizes() { // 2x large size. add_image_size( '2048x2048', 2048, 2048 ); } + +/** + * Callback to enable showig of the user error when uploading .heic images. + * + * @since 5.5.0 + * + * @param array[] $plupload_settings The settings for Plupload.js. + * @return array[] Modified settings for Plupload.js. + */ +function wp_show_heic_upload_error( $plupload_settings ) { + $plupload_settings['heic_upload_error'] = true; + return $plupload_settings; +} diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 63e5d08a7f..30a4090b37 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -846,6 +846,7 @@ function wp_default_scripts( $scripts ) { 'deleted' => __( 'moved to the Trash.' ), /* translators: %s: File name. */ 'error_uploading' => __( '“%s” has failed to upload.' ), + 'unsupported_image' => __( 'This image cannot be displayed in a web browser. For best results convert it to JPEG before uploading.' ), ); $scripts->add( 'moxiejs', "/wp-includes/js/plupload/moxie$suffix.js", array(), '1.3.5' ); diff --git a/wp-includes/version.php b/wp-includes/version.php index a740d534f2..a64ff3b090 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.5-alpha-48287'; +$wp_version = '5.5-alpha-48288'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.