From 49686be2abc529f73624ff4edfc504edf34d4d85 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Mon, 14 Oct 2019 19:56:06 +0000 Subject: [PATCH] Uploads: Retry to post-process images after HTTP 500 and HTTP 502 errors. Props mikeschroder, azaozz. Fixes #47872. Built from https://develop.svn.wordpress.org/trunk@46506 git-svn-id: http://core.svn.wordpress.org/trunk@46303 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/plupload/handlers.js | 10 +++++----- wp-includes/js/plupload/handlers.min.js | 2 +- wp-includes/js/plupload/wp-plupload.js | 10 +++++----- wp-includes/js/plupload/wp-plupload.min.js | 2 +- wp-includes/version.php | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/wp-includes/js/plupload/handlers.js b/wp-includes/js/plupload/handlers.js index fbf1012f9c..0e8280ba46 100644 --- a/wp-includes/js/plupload/handlers.js +++ b/wp-includes/js/plupload/handlers.js @@ -427,7 +427,7 @@ jQuery( document ).ready( function( $ ) { }); // Attempt to create image sub-sizes when an image was uploaded successfully - // but the server responded with HTTP 500 error. + // but the server responded with an HTTP 500 or 502 error. tryAgain = function( up, error ) { var file = error.file; var times; @@ -465,7 +465,7 @@ jQuery( document ).ready( function( $ ) { } }); - if ( error.message && error.status !== 500 ) { + if ( error.message && error.status !== 500 && error.status !== 502 ) { wpQueueError( error.message ); } else { wpQueueError( pluploadL10n.http_error_image ); @@ -505,7 +505,7 @@ jQuery( document ).ready( function( $ ) { } }).fail( function( jqXHR ) { // If another HTTP 500 error, try try again... - if ( jqXHR.status === 500 ) { + if ( jqXHR.status === 500 || jqXHR.status === 502 ) { tryAgain( up, error ); return; } @@ -582,8 +582,8 @@ jQuery( document ).ready( function( $ ) { var isImage = error.file && error.file.type && error.file.type.indexOf( 'image/' ) === 0; var status = error && error.status; - // If the file is an image and the error is HTTP 500 try to create sub-sizes again. - if ( status === 500 && isImage ) { + // If the file is an image and the error is HTTP 500 or 502 try to create sub-sizes again. + if ( ( status === 500 || status === 502 ) && isImage ) { tryAgain( up, error ); return; } diff --git a/wp-includes/js/plupload/handlers.min.js b/wp-includes/js/plupload/handlers.min.js index 69582c165d..2d4a3fa40c 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")),r.append(this.browser))}this.uploader.refresh()}}),u.queue=new wp.media.model.Attachments([],{query:!1}),u.errors=new Backbone.Collection,e.Uploader=u)}(wp,jQuery); \ No newline at end of file +window.wp=window.wp||{},function(e,l){var u;"undefined"!=typeof _wpPluploadSettings&&(u=function(e){var n,t,i,d,p=this,r={container:"container",browser:"browse_button",dropzone:"drop_element"},s={};if(this.supports={upload:u.browser.supported},this.supported=this.supports.upload,this.supported){for(t in this.plupload=l.extend(!0,{multipart_params:{}},u.defaults),this.container=document.body,l.extend(!0,this,e),this)l.isFunction(this[t])&&(this[t]=l.proxy(this[t],this));for(t in r)this[t]&&(this[t]=l(this[t]).first(),this[t].length?(this[t].prop("id")||this[t].prop("id","__wp-uploader-id-"+u.uuid++),this.plupload[r[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,r,a){var e,o;if(r&&r.responseHeaders)if((o=r.responseHeaders.match(/x-wp-upload-attachment-id:\s*(\d+)/i))&&o[1]){if(o=o[1],(e=s[a.id])&&4').css({position:"fixed",top:"-1000px",left:"-1000px",height:0,width:0}).attr("id","wp-uploader-browser-"+this.uploader.id).appendTo("body")),r.append(this.browser))}this.uploader.refresh()}}),u.queue=new wp.media.model.Attachments([],{query:!1}),u.errors=new Backbone.Collection,e.Uploader=u)}(wp,jQuery); \ No newline at end of file diff --git a/wp-includes/version.php b/wp-includes/version.php index c995d1dcd0..925a40416a 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.3-beta3-46489'; +$wp_version = '5.3-beta3-46506'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.