From a55fd568d4872b722241e846cc96a5c42cc8bac9 Mon Sep 17 00:00:00 2001 From: azaozz Date: Fri, 30 Oct 2009 07:09:55 +0000 Subject: [PATCH] Trash undo for the uploader, props caesarsgrunt, see #4529 git-svn-id: http://svn.automattic.com/wordpress/trunk@12130 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-ajax.php | 12 ++- wp-admin/css/media-rtl.css | 6 -- wp-admin/css/media.css | 2 +- wp-admin/css/media.dev.css | 12 --- wp-admin/includes/media.php | 5 +- wp-includes/js/swfupload/handlers.dev.js | 125 +++++++++++++++-------- wp-includes/js/swfupload/handlers.js | 2 +- wp-includes/post.php | 6 ++ wp-includes/script-loader.php | 6 +- 9 files changed, 104 insertions(+), 72 deletions(-) diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 6445979b7c..3304aa0286 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -334,6 +334,7 @@ case 'delete-post' : die('0'); break; case 'trash-post' : +case 'untrash-post' : check_ajax_referer( "{$action}_$id" ); if ( !current_user_can( 'delete_post', $id ) ) die('-1'); @@ -341,10 +342,15 @@ case 'trash-post' : if ( !get_post( $id ) ) die('1'); - if ( wp_trash_post( $id ) ) - die('1'); + if ( 'trash-post' == $action ) + $done = wp_trash_post( $id ); else - die('0'); + $done = wp_untrash_post( $id ); + + if ( $done ) + die('1'); + + die('0'); break; case 'delete-page' : check_ajax_referer( "{$action}_$id" ); diff --git a/wp-admin/css/media-rtl.css b/wp-admin/css/media-rtl.css index 396b776569..fed8644426 100644 --- a/wp-admin/css/media-rtl.css +++ b/wp-admin/css/media-rtl.css @@ -48,12 +48,6 @@ button.dismiss { border-left-style: solid; } -.describe-toggle-on, -.describe-toggle-off { - float: left; - margin-right: 0; - margin-left: 20px; -} /* Specific to Uploader */ #media-upload .media-upload-form p { margin: 0 0 1em 1em; diff --git a/wp-admin/css/media.css b/wp-admin/css/media.css index 8034e004d8..2a88330e64 100644 --- a/wp-admin/css/media.css +++ b/wp-admin/css/media.css @@ -1 +1 @@ -div#media-upload-header{margin:0;padding:0 5px;font-weight:bold;position:relative;border-bottom-width:1px;border-bottom-style:solid;height:2.5em;}body#media-upload ul#sidemenu{font-weight:normal;margin:0 5px;position:absolute;left:0;bottom:-1px;}div#media-upload-error{margin:1em;font-weight:bold;}form{margin:1em;}#search-filter{text-align:right;}th{position:relative;}.media-upload-form label.form-help,td.help{font-family:"Lucida Grande","Bitstream Vera Sans",Verdana,Arial,sans-serif;font-style:italic;font-weight:normal;}.media-upload-form p.help{margin:0;padding:0;}.media-upload-form fieldset{width:100%;border:none;text-align:justify;margin:0 0 1em 0;padding:0;}.image-align-none-label{background:url(../images/align-none.png) no-repeat center left;}.image-align-left-label{background:url(../images/align-left.png) no-repeat center left;}.image-align-center-label{background:url(../images/align-center.png) no-repeat center left;}.image-align-right-label{background:url(../images/align-right.png) no-repeat center left;}tr.image-size td{width:460px;}tr.image-size div.image-size-item{float:left;width:25%;margin:0;}#library-form .progress,#gallery-form .progress,#flash-upload-ui,.insert-gallery,.describe.startopen,.describe.startclosed{display:none;}.media-item .thumbnail{max-width:128px;max-height:128px;}thead.media-item-info tr{background-color:transparent;}thead.media-item-info th,thead.media-item-info td{border:none;margin:0;}.form-table thead.media-item-info{border:8px solid #fff;}abbr.required{text-decoration:none;border:none;}.describe label{display:inline;}.describe td{vertical-align:middle;padding:0 5px 8px 0;}.describe td.A1{width:132px;}.describe input[type="text"],.describe textarea{width:460px;border-width:1px;border-style:solid;}.describe-toggle-on,.describe-toggle-off{display:block;line-height:36px;float:right;margin-right:20px;}.describe-toggle-off{display:none;}.hidden{height:0;width:0;overflow:hidden;border:none;}#media-upload p.ml-submit{padding:1em 0;}#media-upload p.help,#media-upload label.help{font-family:"Lucida Grande","Bitstream Vera Sans",Verdana,Arial,sans-serif;font-style:italic;font-weight:normal;}#media-upload tr.image-size td.field{text-align:center;}#media-upload #media-items{border-width:1px;border-style:solid;border-bottom:none;width:623px;}#media-upload .media-item{border-bottom-width:1px;border-bottom-style:solid;min-height:36px;width:100%;}#media-upload .ui-sortable .media-item{cursor:move;}.filename{line-height:36px;padding:0 10px;overflow:hidden;}#media-upload .describe{padding:5px;width:100%;clear:both;cursor:default;}#media-upload .slidetoggle{border-top-width:1px;border-top-style:solid;}#media-upload .describe th.label{padding-top:.2em;text-align:left;min-width:120px;}#media-upload tr.align td.field{text-align:center;}#media-upload tr.image-size{margin-bottom:1em;height:3em;}#media-upload #filter{width:623px;}#media-upload #filter .subsubsub{margin:8px 0;}#filter .tablenav select{border-style:solid;border-width:1px;padding:2px;vertical-align:top;width:auto;}#media-upload .del-attachment{display:none;margin:5px 0;}.menu_order{float:right;font-size:11px;margin:10px 10px 0;}.menu_order_input{border:1px solid #ddd;font-size:10px;padding:1px;width:23px;}.ui-sortable-helper{background-color:#fff;border:1px solid #aaa;opacity:.6;filter:alpha(opacity=60);}#media-upload th.order-head{width:20%;text-align:center;}#media-upload th.actions-head{width:25%;text-align:center;}#media-upload a.wp-post-thumbnail{margin:0 20px;}#media-items a.delete{display:block;float:right;}#media-upload .widefat{width:626px;border-style:solid solid none;}.sorthelper{height:37px;width:623px;display:block;}#gallery-settings th.label{width:160px;}#gallery-settings #basic th.label{padding:5px 5px 5px 0;}#gallery-settings .title{clear:both;padding:0 0 3px;font-size:1.6em;border-bottom:1px solid #DADADA;}h3.media-title{font-size:1.6em;}h4.media-sub-title{border-bottom:1px solid #DADADA;font-size:1.3em;margin:12px;padding:0 0 3px;}#gallery-settings .title,h3.media-title,h4.media-sub-title{font-family:Georgia,"Times New Roman",Times,serif;font-weight:normal;color:#5A5A5A;}#gallery-settings .describe td{vertical-align:middle;height:3em;}#gallery-settings .describe th.label{padding-top:.5em;text-align:left;}#gallery-settings .describe{padding:5px;width:615px;clear:both;cursor:default;}#gallery-settings .describe select{width:15em;}#gallery-settings .describe select option,#gallery-settings .describe td{padding:0;}#gallery-settings label,#gallery-settings legend{font-size:13px;color:#464646;margin-right:15px;}#gallery-settings .align .field label{margin:0 1.5em 0 0;}#gallery-settings p.ml-submit{border-top:1px solid #dfdfdf;}#gallery-settings select#columns{width:6em;}#sort-buttons{font-size:.8em;margin:3px 25px -8px 0;text-align:right;max-width:625px;}#sort-buttons a{text-decoration:none;}#sort-buttons #asc,#sort-buttons #showall{padding-left:5px;}#sort-buttons span{margin-right:25px;} \ No newline at end of file +div#media-upload-header{margin:0;padding:0 5px;font-weight:bold;position:relative;border-bottom-width:1px;border-bottom-style:solid;height:2.5em;}body#media-upload ul#sidemenu{font-weight:normal;margin:0 5px;position:absolute;left:0;bottom:-1px;}div#media-upload-error{margin:1em;font-weight:bold;}form{margin:1em;}#search-filter{text-align:right;}th{position:relative;}.media-upload-form label.form-help,td.help{font-family:"Lucida Grande","Bitstream Vera Sans",Verdana,Arial,sans-serif;font-style:italic;font-weight:normal;}.media-upload-form p.help{margin:0;padding:0;}.media-upload-form fieldset{width:100%;border:none;text-align:justify;margin:0 0 1em 0;padding:0;}.image-align-none-label{background:url(../images/align-none.png) no-repeat center left;}.image-align-left-label{background:url(../images/align-left.png) no-repeat center left;}.image-align-center-label{background:url(../images/align-center.png) no-repeat center left;}.image-align-right-label{background:url(../images/align-right.png) no-repeat center left;}tr.image-size td{width:460px;}tr.image-size div.image-size-item{float:left;width:25%;margin:0;}#library-form .progress,#gallery-form .progress,#flash-upload-ui,.insert-gallery,.describe.startopen,.describe.startclosed{display:none;}.media-item .thumbnail{max-width:128px;max-height:128px;}thead.media-item-info tr{background-color:transparent;}thead.media-item-info th,thead.media-item-info td{border:none;margin:0;}.form-table thead.media-item-info{border:8px solid #fff;}abbr.required{text-decoration:none;border:none;}.describe label{display:inline;}.describe td{vertical-align:middle;padding:0 5px 8px 0;}.describe td.A1{width:132px;}.describe input[type="text"],.describe textarea{width:460px;border-width:1px;border-style:solid;}.hidden{height:0;width:0;overflow:hidden;border:none;}#media-upload p.ml-submit{padding:1em 0;}#media-upload p.help,#media-upload label.help{font-family:"Lucida Grande","Bitstream Vera Sans",Verdana,Arial,sans-serif;font-style:italic;font-weight:normal;}#media-upload tr.image-size td.field{text-align:center;}#media-upload #media-items{border-width:1px;border-style:solid;border-bottom:none;width:623px;}#media-upload .media-item{border-bottom-width:1px;border-bottom-style:solid;min-height:36px;width:100%;}#media-upload .ui-sortable .media-item{cursor:move;}.filename{line-height:36px;padding:0 10px;overflow:hidden;}#media-upload .describe{padding:5px;width:100%;clear:both;cursor:default;}#media-upload .slidetoggle{border-top-width:1px;border-top-style:solid;}#media-upload .describe th.label{padding-top:.2em;text-align:left;min-width:120px;}#media-upload tr.align td.field{text-align:center;}#media-upload tr.image-size{margin-bottom:1em;height:3em;}#media-upload #filter{width:623px;}#media-upload #filter .subsubsub{margin:8px 0;}#filter .tablenav select{border-style:solid;border-width:1px;padding:2px;vertical-align:top;width:auto;}#media-upload .del-attachment{display:none;margin:5px 0;}.menu_order{float:right;font-size:11px;margin:10px 10px 0;}.menu_order_input{border:1px solid #ddd;font-size:10px;padding:1px;width:23px;}.ui-sortable-helper{background-color:#fff;border:1px solid #aaa;opacity:.6;filter:alpha(opacity=60);}#media-upload th.order-head{width:20%;text-align:center;}#media-upload th.actions-head{width:25%;text-align:center;}#media-upload a.wp-post-thumbnail{margin:0 20px;}#media-items a.delete{display:block;float:right;}#media-upload .widefat{width:626px;border-style:solid solid none;}.sorthelper{height:37px;width:623px;display:block;}#gallery-settings th.label{width:160px;}#gallery-settings #basic th.label{padding:5px 5px 5px 0;}#gallery-settings .title{clear:both;padding:0 0 3px;font-size:1.6em;border-bottom:1px solid #DADADA;}h3.media-title{font-size:1.6em;}h4.media-sub-title{border-bottom:1px solid #DADADA;font-size:1.3em;margin:12px;padding:0 0 3px;}#gallery-settings .title,h3.media-title,h4.media-sub-title{font-family:Georgia,"Times New Roman",Times,serif;font-weight:normal;color:#5A5A5A;}#gallery-settings .describe td{vertical-align:middle;height:3em;}#gallery-settings .describe th.label{padding-top:.5em;text-align:left;}#gallery-settings .describe{padding:5px;width:615px;clear:both;cursor:default;}#gallery-settings .describe select{width:15em;}#gallery-settings .describe select option,#gallery-settings .describe td{padding:0;}#gallery-settings label,#gallery-settings legend{font-size:13px;color:#464646;margin-right:15px;}#gallery-settings .align .field label{margin:0 1.5em 0 0;}#gallery-settings p.ml-submit{border-top:1px solid #dfdfdf;}#gallery-settings select#columns{width:6em;}#sort-buttons{font-size:.8em;margin:3px 25px -8px 0;text-align:right;max-width:625px;}#sort-buttons a{text-decoration:none;}#sort-buttons #asc,#sort-buttons #showall{padding-left:5px;}#sort-buttons span{margin-right:25px;} \ No newline at end of file diff --git a/wp-admin/css/media.dev.css b/wp-admin/css/media.dev.css index f3c06aeb95..3ae926ec50 100644 --- a/wp-admin/css/media.dev.css +++ b/wp-admin/css/media.dev.css @@ -134,18 +134,6 @@ abbr.required { border-style: solid; } -.describe-toggle-on, -.describe-toggle-off { - display: block; - line-height: 36px; - float: right; - margin-right: 20px; -} - -.describe-toggle-off { - display: none; -} - .hidden { height: 0; width: 0; diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index 5844e5c960..0449c5739a 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -1203,11 +1203,12 @@ function get_media_item( $attachment_id, $args = null ) { 'extra_rows' => array(), ); - $delete_href = wp_nonce_url("post.php?action=trash&post=$attachment_id", 'trash-post_' . $attachment_id); + $trash_href = wp_nonce_url("post.php?action=trash&post=$attachment_id", 'trash-post_' . $attachment_id); + $untrash_href = wp_nonce_url("post.php?action=untrash&post=$attachment_id", 'untrash-post_' . $attachment_id); if ( $send ) $send = ""; if ( $delete ) - $delete = current_user_can('delete_post', $attachment_id) ? "" . __('Move to Trash') . "" : ""; + $delete = current_user_can('delete_post', $attachment_id) ? "" . __('Move to Trash') . " " . __('Undo?') . "" : ""; if ( 'image' == $type && get_post_image_id($_GET['post_id']) != $attachment_id ) $thumbnail = "" . esc_html__( "Use as thumbnail" ) . ""; diff --git a/wp-includes/js/swfupload/handlers.dev.js b/wp-includes/js/swfupload/handlers.dev.js index 1580725021..fe335a2639 100644 --- a/wp-includes/js/swfupload/handlers.dev.js +++ b/wp-includes/js/swfupload/handlers.dev.js @@ -8,7 +8,7 @@ function fileQueued(fileObj) { // Get rid of unused form jQuery('.media-blank').remove(); // Collapse a single item - if ( jQuery('.type-form #media-items>*').length == 1 && jQuery('#media-items .hidden').length > 0 ) { + if ( jQuery('form.type-form #media-items').children().length == 1 && jQuery('.hidden', '#media-items').length > 0 ) { jQuery('.describe-toggle-on').show(); jQuery('.describe-toggle-off').hide(); jQuery('.slidetoggle').slideUp(200).siblings().removeClass('hidden'); @@ -16,7 +16,7 @@ function fileQueued(fileObj) { // Create a progress bar containing the filename jQuery('#media-items').append('
' + fileObj.name + '
'); // Display the progress div - jQuery('#media-item-' + fileObj.id + ' .progress').show(); + jQuery('.progress', '#media-item-' + fileObj.id).show(); // Disable submit and enable cancel jQuery('#insert-gallery').attr('disabled', 'disabled'); @@ -29,63 +29,99 @@ function uploadStart(fileObj) { function uploadProgress(fileObj, bytesDone, bytesTotal) { // Lengthen the progress bar - var w = jQuery('#media-items').width() - 2; - jQuery('#media-item-' + fileObj.id + ' .bar').width( w * bytesDone / bytesTotal ); - jQuery('#media-item-' + fileObj.id + ' .percent').html( Math.ceil(bytesDone / bytesTotal * 100) + '%' ); + var w = jQuery('#media-items').width() - 2, item = jQuery('#media-item-' + fileObj.id); + jQuery('.bar', item).width( w * bytesDone / bytesTotal ); + jQuery('.percent', item).html( Math.ceil(bytesDone / bytesTotal * 100) + '%' ); if ( bytesDone == bytesTotal ) - jQuery('#media-item-' + fileObj.id + ' .bar').html('' + swfuploadL10n.crunching + ''); + jQuery('.bar', item).html('' + swfuploadL10n.crunching + ''); } function prepareMediaItem(fileObj, serverData) { + var f = ( typeof shortform == 'undefined' ) ? 1 : 2, item = jQuery('#media-item-' + fileObj.id); // Move the progress bar to 100% - jQuery('#media-item-' + fileObj.id + ' .bar').remove(); - jQuery('#media-item-' + fileObj.id + ' .progress').hide(); + jQuery('.bar', item).remove(); + jQuery('.progress', item).hide(); - var f = ( typeof shortform == 'undefined' ) ? 1 : 2; // Old style: Append the HTML returned by the server -- thumbnail and form inputs if ( isNaN(serverData) || !serverData ) { - jQuery('#media-item-' + fileObj.id).append(serverData); + item.append(serverData); prepareMediaItemInit(fileObj); } // New style: server data is just the attachment ID, fetch the thumbnail and form html from the server else { - jQuery('#media-item-' + fileObj.id).load('async-upload.php', {attachment_id:serverData, fetch:f}, function(){prepareMediaItemInit(fileObj);updateMediaForm()}); + item.load('async-upload.php', {attachment_id:serverData, fetch:f}, function(){prepareMediaItemInit(fileObj);updateMediaForm()}); } } - -function prepareMediaItemInit(fileObj) { +function prepareMediaItemInit(fileObj) { + var item = jQuery('#media-item-' + fileObj.id); // Clone the thumbnail as a "pinkynail" -- a tiny image to the left of the filename - jQuery('#media-item-' + fileObj.id + ' .thumbnail').clone().attr('className', 'pinkynail toggle').prependTo('#media-item-' + fileObj.id); + jQuery('.thumbnail', item).clone().attr('className', 'pinkynail toggle').prependTo(item); // Replace the original filename with the new (unique) one assigned during upload - jQuery('#media-item-' + fileObj.id + ' .filename.original').replaceWith(jQuery('#media-item-' + fileObj.id + ' .filename.new')); + jQuery('.filename.original', item).replaceWith( jQuery('.filename.new', item) ); // Also bind toggle to the links - jQuery('#media-item-' + fileObj.id + ' a.toggle').click(function(){ - jQuery(this).siblings('.slidetoggle').slideToggle(150, function(){ + jQuery('a.toggle', item).click(function(){ + jQuery(this).siblings('.slidetoggle').slideToggle(350, function(){ var o = jQuery(this).offset(); - window.scrollTo(0, o.top-36); + window.scrollTo(0, o.top - 36); }); - jQuery(this).parent().children('.toggle').toggle(); + jQuery(this).siblings('.toggle').andSelf().toggle(); jQuery(this).siblings('a.toggle').focus(); return false; }); // Bind AJAX to the new Delete button - jQuery('#media-item-' + fileObj.id + ' a.delete').click(function(){ + jQuery('a.delete', item).click(function(){ // Tell the server to delete it. TODO: handle exceptions - jQuery.ajax({url:'admin-ajax.php',type:'post',success:deleteSuccess,error:deleteError,id:fileObj.id,data:{ - id : this.id.replace(/[^0-9]/g,''), - action : 'trash-post', - _ajax_nonce : this.href.replace(/^.*wpnonce=/,'')} - }); + jQuery.ajax({ + url: 'admin-ajax.php', + type: 'post', + success: deleteSuccess, + error: deleteError, + id: fileObj.id, + data: { + id : this.id.replace(/[^0-9]/g, ''), + action : 'trash-post', + _ajax_nonce : this.href.replace(/^.*wpnonce=/,'') + } + }); + return false; + }); + + // Bind AJAX to the new Undo button + jQuery('a.undo', item).click(function(){ + // Tell the server to untrash it. TODO: handle exceptions + jQuery.ajax({ + url: 'admin-ajax.php', + type: 'post', + id: fileObj.id, + data: { + id : this.id.replace(/[^0-9]/g,''), + action: 'untrash-post', + _ajax_nonce: this.href.replace(/^.*wpnonce=/,'') + }, + success: function(data, textStatus){ + var item = jQuery('#media-item-' + fileObj.id); + + if ( type = jQuery('#type-of-' + fileObj.id).val() ) + jQuery('#' + type + '-counter').text(jQuery('#' + type + '-counter').text()-0+1); + if ( item.hasClass('child-of-'+post_id) ) + jQuery('#attachments-count').text(jQuery('#attachments-count').text()-0+1); + + jQuery('.filename .trashnotice', item).remove(); + jQuery('a.undo', item).addClass('hidden'); + jQuery('a.describe-toggle-on, .menu_order_input', item).show(); + item.animate( {backgroundColor: '#fff'}, { queue: false, duration: 200, complete: function(){ jQuery(this).css({backgroundColor:''}); } }); + } + }); return false; }); // Open this item if it says to start open (e.g. to display an error) - jQuery('#media-item-' + fileObj.id + '.startopen').removeClass('startopen').slideToggle(500).parent().children('.toggle').toggle(); + jQuery('#media-item-' + fileObj.id + '.startopen').removeClass('startopen').slideToggle(500).siblings('.toggle').toggle(); } function itemAjaxError(id, html) { @@ -101,27 +137,28 @@ function deleteSuccess(data, textStatus) { if ( data == '0' ) return itemAjaxError(this.id, 'Could not be deleted. Has it been deleted already?'); - var item = jQuery('#media-item-' + this.id); + var id = this.id, item = jQuery('#media-item-' + id); // Decrement the counters. - if ( type = jQuery('#type-of-' + this.id).val() ) - jQuery('#' + type + '-counter').text(jQuery('#' + type + '-counter').text()-1); + if ( type = jQuery('#type-of-' + id).val() ) + jQuery('#' + type + '-counter').text( jQuery('#' + type + '-counter').text() - 1 ); if ( item.hasClass('child-of-'+post_id) ) - jQuery('#attachments-count').text(jQuery('#attachments-count').text()-1); + jQuery('#attachments-count').text( jQuery('#attachments-count').text() - 1 ); - if ( jQuery('.type-form #media-items>*').length == 1 && jQuery('#media-items .hidden').length > 0 ) { + if ( jQuery('form.type-form #media-items').children().length == 1 && jQuery('.hidden', '#media-items').length > 0 ) { jQuery('.toggle').toggle(); jQuery('.slidetoggle').slideUp(200).siblings().removeClass('hidden'); } // Vanish it. - jQuery('#media-item-' + this.id + ' .filename:empty').remove(); - jQuery('#media-item-' + this.id + ' .filename').append(' '+swfuploadL10n.deleted+'').siblings('a.toggle').remove(); - jQuery('#media-item-' + this.id).children('.describe').css({backgroundColor:'#fff'}).end() - .animate({backgroundColor:'#ffc0c0'}, {queue:false,duration:50}) - .animate({minHeight:0,height:36}, 400, null, function(){jQuery(this).children('.describe').remove()}) - .animate({backgroundColor:'#fff'}, 400) - .animate({height:0}, 800, null, function(){jQuery(this).remove();updateMediaForm();}); + jQuery('.toggle', item).toggle(); + jQuery('.slidetoggle', item).slideUp(200).siblings().removeClass('hidden'); + item.css( {backgroundColor:'#fff'} ).animate( {backgroundColor:'#ffc0c0'}, {queue:false, duration:500} ); + + jQuery('.filename:empty', item).remove(); + jQuery('.filename', item).append(' ' + swfuploadL10n.deleted + ' ').siblings('a.toggle').hide(); + jQuery('.filename', item).append( jQuery('a.undo', item).removeClass('hidden') ); + jQuery('.menu_order_input', item).hide(); return; } @@ -131,21 +168,21 @@ function deleteError(X, textStatus, errorThrown) { } function updateMediaForm() { + var one = jQuery('form.type-form #media-items').children(), items = jQuery('#media-items').children(); storeState(); // Just one file, no need for collapsible part - if ( jQuery('.type-form #media-items>*').length == 1 ) { - jQuery('#media-items .slidetoggle').slideDown(500).parent().eq(0).children('.toggle').toggle(); - jQuery('.type-form .slidetoggle').siblings().addClass('hidden'); + if ( one.length == 1 ) { + jQuery('.slidetoggle', one).slideDown(500).siblings().addClass('hidden').filter('.toggle').toggle(); } // Only show Save buttons when there is at least one file. - if ( jQuery('#media-items>*').not('.media-blank').length > 0 ) + if ( items.not('.media-blank').length > 0 ) jQuery('.savebutton').show(); else jQuery('.savebutton').hide(); // Only show Gallery button when there are at least two files. - if ( jQuery('#media-items>*').length > 1 ) + if ( items.length > 1 ) jQuery('.insert-gallery').show(); else jQuery('.insert-gallery').hide(); @@ -245,7 +282,7 @@ function swfuploadLoadFailed() { } function uploadError(fileObj, errorCode, message) { - + switch (errorCode) { case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL: wpFileError(fileObj, swfuploadL10n.missing_upload_url); diff --git a/wp-includes/js/swfupload/handlers.js b/wp-includes/js/swfupload/handlers.js index df2fd850eb..01053e7795 100644 --- a/wp-includes/js/swfupload/handlers.js +++ b/wp-includes/js/swfupload/handlers.js @@ -1 +1 @@ -function fileDialogStart(){jQuery("#media-upload-error").empty()}function fileQueued(a){jQuery(".media-blank").remove();if(jQuery(".type-form #media-items>*").length==1&&jQuery("#media-items .hidden").length>0){jQuery(".describe-toggle-on").show();jQuery(".describe-toggle-off").hide();jQuery(".slidetoggle").slideUp(200).siblings().removeClass("hidden")}jQuery("#media-items").append('
'+a.name+"
");jQuery("#media-item-"+a.id+" .progress").show();jQuery("#insert-gallery").attr("disabled","disabled");jQuery("#cancel-upload").attr("disabled","")}function uploadStart(a){return true}function uploadProgress(d,b,c){var a=jQuery("#media-items").width()-2;jQuery("#media-item-"+d.id+" .bar").width(a*b/c);jQuery("#media-item-"+d.id+" .percent").html(Math.ceil(b/c*100)+"%");if(b==c){jQuery("#media-item-"+d.id+" .bar").html(''+swfuploadL10n.crunching+"")}}function prepareMediaItem(b,a){jQuery("#media-item-"+b.id+" .bar").remove();jQuery("#media-item-"+b.id+" .progress").hide();var c=(typeof shortform=="undefined")?1:2;if(isNaN(a)||!a){jQuery("#media-item-"+b.id).append(a);prepareMediaItemInit(b)}else{jQuery("#media-item-"+b.id).load("async-upload.php",{attachment_id:a,fetch:c},function(){prepareMediaItemInit(b);updateMediaForm()})}}function prepareMediaItemInit(a){jQuery("#media-item-"+a.id+" .thumbnail").clone().attr("className","pinkynail toggle").prependTo("#media-item-"+a.id);jQuery("#media-item-"+a.id+" .filename.original").replaceWith(jQuery("#media-item-"+a.id+" .filename.new"));jQuery("#media-item-"+a.id+" a.toggle").click(function(){jQuery(this).siblings(".slidetoggle").slideToggle(150,function(){var b=jQuery(this).offset();window.scrollTo(0,b.top-36)});jQuery(this).parent().children(".toggle").toggle();jQuery(this).siblings("a.toggle").focus();return false});jQuery("#media-item-"+a.id+" a.delete").click(function(){jQuery.ajax({url:"admin-ajax.php",type:"post",success:deleteSuccess,error:deleteError,id:a.id,data:{id:this.id.replace(/[^0-9]/g,""),action:"trash-post",_ajax_nonce:this.href.replace(/^.*wpnonce=/,"")}});return false});jQuery("#media-item-"+a.id+".startopen").removeClass("startopen").slideToggle(500).parent().children(".toggle").toggle()}function itemAjaxError(c,b){var a=jQuery("#media-item-error"+c);a.html('
"+b+"
");jQuery("#dismiss-"+c).click(function(){jQuery(this).parents(".file-error").slideUp(200,function(){jQuery(this).empty()})})}function deleteSuccess(b,c){if(b=="-1"){return itemAjaxError(this.id,"You do not have permission. Has your session expired?")}if(b=="0"){return itemAjaxError(this.id,"Could not be deleted. Has it been deleted already?")}var a=jQuery("#media-item-"+this.id);if(type=jQuery("#type-of-"+this.id).val()){jQuery("#"+type+"-counter").text(jQuery("#"+type+"-counter").text()-1)}if(a.hasClass("child-of-"+post_id)){jQuery("#attachments-count").text(jQuery("#attachments-count").text()-1)}if(jQuery(".type-form #media-items>*").length==1&&jQuery("#media-items .hidden").length>0){jQuery(".toggle").toggle();jQuery(".slidetoggle").slideUp(200).siblings().removeClass("hidden")}jQuery("#media-item-"+this.id+" .filename:empty").remove();jQuery("#media-item-"+this.id+" .filename").append(' '+swfuploadL10n.deleted+"").siblings("a.toggle").remove();jQuery("#media-item-"+this.id).children(".describe").css({backgroundColor:"#fff"}).end().animate({backgroundColor:"#ffc0c0"},{queue:false,duration:50}).animate({minHeight:0,height:36},400,null,function(){jQuery(this).children(".describe").remove()}).animate({backgroundColor:"#fff"},400).animate({height:0},800,null,function(){jQuery(this).remove();updateMediaForm()});return}function deleteError(c,b,a){}function updateMediaForm(){storeState();if(jQuery(".type-form #media-items>*").length==1){jQuery("#media-items .slidetoggle").slideDown(500).parent().eq(0).children(".toggle").toggle();jQuery(".type-form .slidetoggle").siblings().addClass("hidden")}if(jQuery("#media-items>*").not(".media-blank").length>0){jQuery(".savebutton").show()}else{jQuery(".savebutton").hide()}if(jQuery("#media-items>*").length>1){jQuery(".insert-gallery").show()}else{jQuery(".insert-gallery").hide()}}function uploadSuccess(b,a){if(a.match("media-upload-error")){jQuery("#media-item-"+b.id).html(a);return}prepareMediaItem(b,a);updateMediaForm();if(jQuery("#media-item-"+b.id).hasClass("child-of-"+post_id)){jQuery("#attachments-count").text(1*jQuery("#attachments-count").text()+1)}}function uploadComplete(a){if(swfu.getStats().files_queued==0){jQuery("#cancel-upload").attr("disabled","disabled");jQuery("#insert-gallery").attr("disabled","")}}function wpQueueError(a){jQuery("#media-upload-error").show().text(a)}function wpFileError(b,a){jQuery("#media-item-"+b.id+" .filename").after('
"+a+"
").siblings(".toggle").remove();jQuery("#dismiss-"+b.id).click(function(){jQuery(this).parents(".media-item").slideUp(200,function(){jQuery(this).remove()})})}function fileQueueError(c,a,b){if(a==SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED){wpQueueError(swfuploadL10n.queue_limit_exceeded)}else{if(a==SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT){fileQueued(c);wpFileError(c,swfuploadL10n.file_exceeds_size_limit)}else{if(a==SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE){fileQueued(c);wpFileError(c,swfuploadL10n.zero_byte_file)}else{if(a==SWFUpload.QUEUE_ERROR.INVALID_FILETYPE){fileQueued(c);wpFileError(c,swfuploadL10n.invalid_filetype)}else{wpQueueError(swfuploadL10n.default_error)}}}}}function fileDialogComplete(b){try{if(b>0){this.startUpload()}}catch(a){this.debug(a)}}function switchUploader(b){var c=document.getElementById(swfu.customSettings.swfupload_element_id),a=document.getElementById(swfu.customSettings.degraded_element_id);if(b){c.style.display="block";a.style.display="none"}else{c.style.display="none";a.style.display="block"}}function swfuploadPreLoad(){if(!uploaderMode){switchUploader(1)}else{switchUploader(0)}}function swfuploadLoadFailed(){switchUploader(0);jQuery(".upload-html-bypass").hide()}function uploadError(b,c,a){switch(c){case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL:wpFileError(b,swfuploadL10n.missing_upload_url);break;case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:wpFileError(b,swfuploadL10n.upload_limit_exceeded);break;case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:wpQueueError(swfuploadL10n.http_error);break;case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:wpQueueError(swfuploadL10n.upload_failed);break;case SWFUpload.UPLOAD_ERROR.IO_ERROR:wpQueueError(swfuploadL10n.io_error);break;case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:wpQueueError(swfuploadL10n.security_error);break;case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:jQuery("#media-item-"+b.id).remove();break;default:wpFileError(b,swfuploadL10n.default_error)}}function cancelUpload(){swfu.cancelQueue()}var storeState;(function(a){storeState=function(){var c=getUserSetting("align")||"",b=getUserSetting("imgsize")||"";a('tr.align input[type="radio"]').click(function(){setUserSetting("align",a(this).val())}).filter(function(){if(a(this).val()==c){return true}return false}).attr("checked","checked");a('tr.image-size input[type="radio"]').click(function(){setUserSetting("imgsize",a(this).val())}).filter(function(){if(a(this).attr("disabled")||a(this).val()!=b){return false}return true}).attr("checked","checked");a("tr.url button").click(function(){var d=this.className||"";d=d.replace(/.*?(url[^ '"]+).*/,"$1");if(d){setUserSetting("urlbutton",d)}a(this).siblings(".urlfield").val(a(this).attr("title"))});a("tr.url .urlfield").each(function(){var d=getUserSetting("urlbutton");a(this).val(a(this).siblings("button."+d).attr("title"))})}})(jQuery); \ No newline at end of file +function fileDialogStart(){jQuery("#media-upload-error").empty()}function fileQueued(a){jQuery(".media-blank").remove();if(jQuery("form.type-form #media-items").children().length==1&&jQuery(".hidden","#media-items").length>0){jQuery(".describe-toggle-on").show();jQuery(".describe-toggle-off").hide();jQuery(".slidetoggle").slideUp(200).siblings().removeClass("hidden")}jQuery("#media-items").append('
'+a.name+"
");jQuery(".progress","#media-item-"+a.id).show();jQuery("#insert-gallery").attr("disabled","disabled");jQuery("#cancel-upload").attr("disabled","")}function uploadStart(a){return true}function uploadProgress(e,b,d){var a=jQuery("#media-items").width()-2,c=jQuery("#media-item-"+e.id);jQuery(".bar",c).width(a*b/d);jQuery(".percent",c).html(Math.ceil(b/d*100)+"%");if(b==d){jQuery(".bar",c).html(''+swfuploadL10n.crunching+"")}}function prepareMediaItem(c,a){var d=(typeof shortform=="undefined")?1:2,b=jQuery("#media-item-"+c.id);jQuery(".bar",b).remove();jQuery(".progress",b).hide();if(isNaN(a)||!a){b.append(a);prepareMediaItemInit(c)}else{b.load("async-upload.php",{attachment_id:a,fetch:d},function(){prepareMediaItemInit(c);updateMediaForm()})}}function prepareMediaItemInit(b){var a=jQuery("#media-item-"+b.id);jQuery(".thumbnail",a).clone().attr("className","pinkynail toggle").prependTo(a);jQuery(".filename.original",a).replaceWith(jQuery(".filename.new",a));jQuery("a.toggle",a).click(function(){jQuery(this).siblings(".slidetoggle").slideToggle(350,function(){var c=jQuery(this).offset();window.scrollTo(0,c.top-36)});jQuery(this).siblings(".toggle").andSelf().toggle();jQuery(this).siblings("a.toggle").focus();return false});jQuery("a.delete",a).click(function(){jQuery.ajax({url:"admin-ajax.php",type:"post",success:deleteSuccess,error:deleteError,id:b.id,data:{id:this.id.replace(/[^0-9]/g,""),action:"trash-post",_ajax_nonce:this.href.replace(/^.*wpnonce=/,"")}});return false});jQuery("a.undo",a).click(function(){jQuery.ajax({url:"admin-ajax.php",type:"post",id:b.id,data:{id:this.id.replace(/[^0-9]/g,""),action:"untrash-post",_ajax_nonce:this.href.replace(/^.*wpnonce=/,"")},success:function(d,e){var c=jQuery("#media-item-"+b.id);if(type=jQuery("#type-of-"+b.id).val()){jQuery("#"+type+"-counter").text(jQuery("#"+type+"-counter").text()-0+1)}if(c.hasClass("child-of-"+post_id)){jQuery("#attachments-count").text(jQuery("#attachments-count").text()-0+1)}jQuery(".filename .trashnotice",c).remove();jQuery("a.undo",c).addClass("hidden");jQuery("a.describe-toggle-on, .menu_order_input",c).show();c.animate({backgroundColor:"#fff"},{queue:false,duration:200,complete:function(){jQuery(this).css({backgroundColor:""})}})}});return false});jQuery("#media-item-"+b.id+".startopen").removeClass("startopen").slideToggle(500).siblings(".toggle").toggle()}function itemAjaxError(c,b){var a=jQuery("#media-item-error"+c);a.html('
"+b+"
");jQuery("#dismiss-"+c).click(function(){jQuery(this).parents(".file-error").slideUp(200,function(){jQuery(this).empty()})})}function deleteSuccess(b,d){if(b=="-1"){return itemAjaxError(this.id,"You do not have permission. Has your session expired?")}if(b=="0"){return itemAjaxError(this.id,"Could not be deleted. Has it been deleted already?")}var c=this.id,a=jQuery("#media-item-"+c);if(type=jQuery("#type-of-"+c).val()){jQuery("#"+type+"-counter").text(jQuery("#"+type+"-counter").text()-1)}if(a.hasClass("child-of-"+post_id)){jQuery("#attachments-count").text(jQuery("#attachments-count").text()-1)}if(jQuery("form.type-form #media-items").children().length==1&&jQuery(".hidden","#media-items").length>0){jQuery(".toggle").toggle();jQuery(".slidetoggle").slideUp(200).siblings().removeClass("hidden")}jQuery(".toggle",a).toggle();jQuery(".slidetoggle",a).slideUp(200).siblings().removeClass("hidden");a.css({backgroundColor:"#fff"}).animate({backgroundColor:"#ffc0c0"},{queue:false,duration:500});jQuery(".filename:empty",a).remove();jQuery(".filename",a).append(' '+swfuploadL10n.deleted+" ").siblings("a.toggle").hide();jQuery(".filename",a).append(jQuery("a.undo",a).removeClass("hidden"));jQuery(".menu_order_input",a).hide();return}function deleteError(c,b,a){}function updateMediaForm(){var b=jQuery("form.type-form #media-items").children(),a=jQuery("#media-items").children();storeState();if(b.length==1){jQuery(".slidetoggle",b).slideDown(500).siblings().addClass("hidden").filter(".toggle").toggle()}if(a.not(".media-blank").length>0){jQuery(".savebutton").show()}else{jQuery(".savebutton").hide()}if(a.length>1){jQuery(".insert-gallery").show()}else{jQuery(".insert-gallery").hide()}}function uploadSuccess(b,a){if(a.match("media-upload-error")){jQuery("#media-item-"+b.id).html(a);return}prepareMediaItem(b,a);updateMediaForm();if(jQuery("#media-item-"+b.id).hasClass("child-of-"+post_id)){jQuery("#attachments-count").text(1*jQuery("#attachments-count").text()+1)}}function uploadComplete(a){if(swfu.getStats().files_queued==0){jQuery("#cancel-upload").attr("disabled","disabled");jQuery("#insert-gallery").attr("disabled","")}}function wpQueueError(a){jQuery("#media-upload-error").show().text(a)}function wpFileError(b,a){jQuery("#media-item-"+b.id+" .filename").after('
"+a+"
").siblings(".toggle").remove();jQuery("#dismiss-"+b.id).click(function(){jQuery(this).parents(".media-item").slideUp(200,function(){jQuery(this).remove()})})}function fileQueueError(c,a,b){if(a==SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED){wpQueueError(swfuploadL10n.queue_limit_exceeded)}else{if(a==SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT){fileQueued(c);wpFileError(c,swfuploadL10n.file_exceeds_size_limit)}else{if(a==SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE){fileQueued(c);wpFileError(c,swfuploadL10n.zero_byte_file)}else{if(a==SWFUpload.QUEUE_ERROR.INVALID_FILETYPE){fileQueued(c);wpFileError(c,swfuploadL10n.invalid_filetype)}else{wpQueueError(swfuploadL10n.default_error)}}}}}function fileDialogComplete(b){try{if(b>0){this.startUpload()}}catch(a){this.debug(a)}}function switchUploader(b){var c=document.getElementById(swfu.customSettings.swfupload_element_id),a=document.getElementById(swfu.customSettings.degraded_element_id);if(b){c.style.display="block";a.style.display="none"}else{c.style.display="none";a.style.display="block"}}function swfuploadPreLoad(){if(!uploaderMode){switchUploader(1)}else{switchUploader(0)}}function swfuploadLoadFailed(){switchUploader(0);jQuery(".upload-html-bypass").hide()}function uploadError(b,c,a){switch(c){case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL:wpFileError(b,swfuploadL10n.missing_upload_url);break;case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:wpFileError(b,swfuploadL10n.upload_limit_exceeded);break;case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:wpQueueError(swfuploadL10n.http_error);break;case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:wpQueueError(swfuploadL10n.upload_failed);break;case SWFUpload.UPLOAD_ERROR.IO_ERROR:wpQueueError(swfuploadL10n.io_error);break;case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:wpQueueError(swfuploadL10n.security_error);break;case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:jQuery("#media-item-"+b.id).remove();break;default:wpFileError(b,swfuploadL10n.default_error)}}function cancelUpload(){swfu.cancelQueue()}var storeState;(function(a){storeState=function(){var c=getUserSetting("align")||"",b=getUserSetting("imgsize")||"";a('tr.align input[type="radio"]').click(function(){setUserSetting("align",a(this).val())}).filter(function(){if(a(this).val()==c){return true}return false}).attr("checked","checked");a('tr.image-size input[type="radio"]').click(function(){setUserSetting("imgsize",a(this).val())}).filter(function(){if(a(this).attr("disabled")||a(this).val()!=b){return false}return true}).attr("checked","checked");a("tr.url button").click(function(){var d=this.className||"";d=d.replace(/.*?(url[^ '"]+).*/,"$1");if(d){setUserSetting("urlbutton",d)}a(this).siblings(".urlfield").val(a(this).attr("title"))});a("tr.url .urlfield").each(function(){var d=getUserSetting("urlbutton");a(this).val(a(this).siblings("button."+d).attr("title"))})}})(jQuery); \ No newline at end of file diff --git a/wp-includes/post.php b/wp-includes/post.php index 968b0dfee2..f1fc878e52 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -1251,6 +1251,9 @@ function wp_trash_post($post_id = 0) { if ( !$post = wp_get_single_post($post_id, ARRAY_A) ) return $post; + if ( $post['post_status'] == 'trash' ) + return false; + do_action('trash_post', $post_id); add_post_meta($post_id,'_wp_trash_meta_status', $post['post_status']); @@ -1278,6 +1281,9 @@ function wp_untrash_post($post_id = 0) { if ( !$post = wp_get_single_post($post_id, ARRAY_A) ) return $post; + if ( $post['post_status'] != 'trash' ) + return false; + do_action('untrash_post', $post_id); $post_status = get_post_meta($post_id, '_wp_trash_meta_status', true); diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 5a6b7ed407..545d40098a 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -183,7 +183,7 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'swfupload-all', '/wp-includes/js/swfupload/swfupload-all.js', array(), '2201'); } - $scripts->add( 'swfupload-handlers', "/wp-includes/js/swfupload/handlers$suffix.js", array('swfupload-all', 'jquery'), '2201-20090818'); + $scripts->add( 'swfupload-handlers', "/wp-includes/js/swfupload/handlers$suffix.js", array('swfupload-all', 'jquery'), '2201-20091029'); $max_upload_size = ( (int) ( $max_up = @ini_get('upload_max_filesize') ) < (int) ( $max_post = @ini_get('post_max_size') ) ) ? $max_up : $max_post; if ( empty($max_upload_size) ) $max_upload_size = __('not configured'); @@ -204,7 +204,7 @@ function wp_default_scripts( &$scripts ) { 'upload_stopped' => __('Upload stopped.'), 'dismiss' => __('Dismiss'), 'crunching' => __('Crunching…'), - 'deleted' => __('Moved to Trash'), + 'deleted' => __('moved to the trash.'), 'l10n_print_after' => 'try{convertEntities(swfuploadL10n);}catch(e){};' ) ); @@ -433,7 +433,7 @@ function wp_default_styles( &$styles ) { $styles->add_data( 'colors-classic', 'rtl', true ); $styles->add( 'global', "/wp-admin/css/global$suffix.css", array(), '20090630' ); - $styles->add( 'media', "/wp-admin/css/media$suffix.css", array(), '20091023' ); + $styles->add( 'media', "/wp-admin/css/media$suffix.css", array(), '20091029' ); $styles->add( 'widgets', "/wp-admin/css/widgets$suffix.css", array(), '20090603' ); $styles->add( 'dashboard', "/wp-admin/css/dashboard$suffix.css", array(), '20090514' ); $styles->add( 'install', "/wp-admin/css/install$suffix.css", array(), '20090514' );