From ae20d06e942c136e88dc97dd1796de29c8a0cd20 Mon Sep 17 00:00:00 2001 From: azaozz Date: Thu, 3 Dec 2009 01:43:49 +0000 Subject: [PATCH] Fix errors when bulk actions executed on empty list, props nacin, see #11184 git-svn-id: http://svn.automattic.com/wordpress/trunk@12317 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/categories.php | 23 ++++++++++++++--------- wp-admin/edit-link-categories.php | 9 +++++---- wp-admin/edit-tags.php | 9 +++++++-- wp-admin/js/inline-edit-post.dev.js | 6 +++++- wp-admin/js/inline-edit-post.js | 2 +- wp-admin/link-manager.php | 5 +++-- wp-admin/plugins.php | 7 ++++--- wp-includes/script-loader.php | 2 +- 8 files changed, 40 insertions(+), 23 deletions(-) diff --git a/wp-admin/categories.php b/wp-admin/categories.php index bd62b634a4..ee0af34df5 100644 --- a/wp-admin/categories.php +++ b/wp-admin/categories.php @@ -34,17 +34,20 @@ case 'addcat': break; case 'delete': + if ( !isset( $_GET['cat_ID'] ) ) { + wp_redirect('categories.php'); + exit; + } + $cat_ID = (int) $_GET['cat_ID']; check_admin_referer('delete-category_' . $cat_ID); if ( !current_user_can('manage_categories') ) wp_die(__('Cheatin’ uh?')); - $cat_name = get_cat_name($cat_ID); - // Don't delete the default cats. if ( $cat_ID == get_option('default_category') ) - wp_die(sprintf(__("Can’t delete the %s category: this is the default one"), $cat_name)); + wp_die( sprintf( __("Can’t delete the %s category: this is the default one"), get_cat_name($cat_ID) ) ); wp_delete_category($cat_ID); @@ -59,18 +62,20 @@ case 'bulk-delete': if ( !current_user_can('manage_categories') ) wp_die( __('You are not allowed to delete categories.') ); - foreach ( (array) $_GET['delete'] as $cat_ID ) { - $cat_name = get_cat_name($cat_ID); + $cats = (array) $_GET['delete']; + $default_cat = get_option('default_category'); + foreach ( $cats as $cat_ID ) { + $cat_ID = (int) $cat_ID; - // Don't delete the default cats. - if ( $cat_ID == get_option('default_category') ) - wp_die(sprintf(__("Can’t delete the %s category: this is the default one"), $cat_name)); + // Don't delete the default cat. + if ( $cat_ID == $default_cat ) + wp_die( sprintf( __("Can’t delete the %s category: this is the default one"), get_cat_name($cat_ID) ) ); wp_delete_category($cat_ID); } wp_safe_redirect( wp_get_referer() ); - exit(); + exit; break; case 'edit': diff --git a/wp-admin/edit-link-categories.php b/wp-admin/edit-link-categories.php index 97c1391f1d..90dcce6646 100644 --- a/wp-admin/edit-link-categories.php +++ b/wp-admin/edit-link-categories.php @@ -18,13 +18,14 @@ if ( isset($_GET['action']) && isset($_GET['delete']) ) { wp_die(__('Cheatin’ uh?')); if ( 'delete' == $doaction ) { - foreach( (array) $_GET['delete'] as $cat_ID ) { - $cat_name = get_term_field('name', $cat_ID, 'link_category'); - $default_cat_id = get_option('default_link_category'); + $cats = (array) $_GET['delete']; + $default_cat_id = get_option('default_link_category'); + foreach( $cats as $cat_ID ) { + $cat_ID = (int) $cat_ID; // Don't delete the default cats. if ( $cat_ID == $default_cat_id ) - wp_die(sprintf(__("Can’t delete the %s category: this is the default one"), $cat_name)); + wp_die( sprintf( __("Can’t delete the %s category: this is the default one"), get_term_field('name', $cat_ID, 'link_category') ) ); wp_delete_term($cat_ID, 'link_category', array('default' => $default_cat_id)); } diff --git a/wp-admin/edit-tags.php b/wp-admin/edit-tags.php index eaf860d6eb..c611c9f37c 100644 --- a/wp-admin/edit-tags.php +++ b/wp-admin/edit-tags.php @@ -44,6 +44,11 @@ case 'addtag': break; case 'delete': + if ( !isset( $_GET['tag_ID'] ) ) { + wp_redirect("edit-tags.php?taxonomy=$taxonomy"); + exit; + } + $tag_ID = (int) $_GET['tag_ID']; check_admin_referer('delete-tag_' . $tag_ID); @@ -70,8 +75,8 @@ case 'bulk-delete': if ( !current_user_can('manage_categories') ) wp_die(__('Cheatin’ uh?')); - $tags = $_GET['delete_tags']; - foreach( (array) $tags as $tag_ID ) { + $tags = (array) $_GET['delete_tags']; + foreach( $tags as $tag_ID ) { wp_delete_term( $tag_ID, $taxonomy); } diff --git a/wp-admin/js/inline-edit-post.dev.js b/wp-admin/js/inline-edit-post.dev.js index f954d38a72..f1380ee675 100644 --- a/wp-admin/js/inline-edit-post.dev.js +++ b/wp-admin/js/inline-edit-post.dev.js @@ -74,7 +74,7 @@ inlineEditPost = { }, setBulk : function() { - var te = '', type = this.type, tax; + var te = '', type = this.type, tax, c = true; this.revert(); $('#bulk-edit td').attr('colspan', $('.widefat:first thead th:visible').length); @@ -83,12 +83,16 @@ inlineEditPost = { $('tbody th.check-column input[type="checkbox"]').each(function(i){ if ( $(this).attr('checked') ) { + c = false; var id = $(this).val(), theTitle; theTitle = $('#inline_'+id+' .post_title').text() || inlineEditL10n.notitle; te += '
X'+theTitle+'
'; } }); + if ( c ) + return this.revert(); + $('#bulk-titles').html(te); $('#bulk-titles a').click(function() { var id = $(this).attr('id').substr(1); diff --git a/wp-admin/js/inline-edit-post.js b/wp-admin/js/inline-edit-post.js index 9ff5ea3cee..f8fd54bad9 100644 --- a/wp-admin/js/inline-edit-post.js +++ b/wp-admin/js/inline-edit-post.js @@ -1 +1 @@ -(function($){inlineEditPost={init:function(){var t=this,qeRow=$("#inline-edit"),bulkRow=$("#bulk-edit");t.type=$("table.widefat").hasClass("page")?"page":"post";t.what="#"+t.type+"-";qeRow.keyup(function(e){if(e.which==27){return inlineEditPost.revert()}});bulkRow.keyup(function(e){if(e.which==27){return inlineEditPost.revert()}});$("a.cancel",qeRow).click(function(){return inlineEditPost.revert()});$("a.save",qeRow).click(function(){return inlineEditPost.save(this)});$("td",qeRow).keydown(function(e){if(e.which==13){return inlineEditPost.save(this)}});$("a.cancel",bulkRow).click(function(){return inlineEditPost.revert()});$("#inline-edit .inline-edit-private input[value=private]").click(function(){var pw=$("input.inline-edit-password-input");if($(this).attr("checked")){pw.val("").attr("disabled","disabled")}else{pw.attr("disabled","")}});$("a.editinline").live("click",function(){inlineEditPost.edit(this);return false});$("#bulk-title-div").parents("fieldset").after($("#inline-edit fieldset.inline-edit-categories").clone()).siblings("fieldset:last").prepend($("#inline-edit label.inline-edit-tags").clone());$("span.catshow").click(function(){$(".inline-editor ul.cat-checklist").addClass("cat-hover");$(".inline-editor span.cathide").show();$(this).hide()});$("span.cathide").click(function(){$(".inline-editor ul.cat-checklist").removeClass("cat-hover");$(".inline-editor span.catshow").show();$(this).hide()});$('select[name="_status"] option[value="future"]',bulkRow).remove();$("#doaction, #doaction2").click(function(e){var n=$(this).attr("id").substr(2);if($('select[name="'+n+'"]').val()=="edit"){e.preventDefault();t.setBulk()}else{if($("form#posts-filter tr.inline-editor").length>0){t.revert()}}});$("#post-query-submit").click(function(e){if($("form#posts-filter tr.inline-editor").length>0){t.revert()}})},toggle:function(el){var t=this;$(t.what+t.getId(el)).css("display")=="none"?t.revert():t.edit(el)},setBulk:function(){var te="",type=this.type,tax;this.revert();$("#bulk-edit td").attr("colspan",$(".widefat:first thead th:visible").length);$("table.widefat tbody").prepend($("#bulk-edit"));$("#bulk-edit").addClass("inline-editor").show();$('tbody th.check-column input[type="checkbox"]').each(function(i){if($(this).attr("checked")){var id=$(this).val(),theTitle;theTitle=$("#inline_"+id+" .post_title").text()||inlineEditL10n.notitle;te+='
X'+theTitle+"
"}});$("#bulk-titles").html(te);$("#bulk-titles a").click(function(){var id=$(this).attr("id").substr(1);$('table.widefat input[value="'+id+'"]').attr("checked","");$("#ttle"+id).remove()});if(type=="post"){tax="post_tag";$('tr.inline-editor textarea[name="tags_input"]').suggest("admin-ajax.php?action=ajax-tag-search&tax="+tax,{delay:500,minchars:2,multiple:true,multipleSep:", "})}},edit:function(id){var t=this,fields,editRow,rowData,cats,status,pageOpt,f,pageLevel,nextPage,pageLoop=true,nextLevel,tax;t.revert();if(typeof(id)=="object"){id=t.getId(id)}fields=["post_title","post_name","post_author","_status","jj","mm","aa","hh","mn","ss","post_password"];if(t.type=="page"){fields.push("post_parent","menu_order","page_template")}if(t.type=="post"){fields.push("tags_input")}editRow=$("#inline-edit").clone(true);$("td",editRow).attr("colspan",$(".widefat:first thead th:visible").length);if($(t.what+id).hasClass("alternate")){$(editRow).addClass("alternate")}$(t.what+id).hide().after(editRow);rowData=$("#inline_"+id);if(!$(':input[name="post_author"] option[value='+$(".post_author",rowData).text()+"]",editRow).val()){$(':input[name="post_author"]',editRow).prepend('")}for(f=0;f0){pageLevel=pageOpt[0].className.split("-")[1];nextPage=pageOpt;while(pageLoop){nextPage=nextPage.next("option");if(nextPage.length==0){break}nextLevel=nextPage[0].className.split("-")[1];if(nextLevel<=pageLevel){pageLoop=false}else{nextPage.remove();nextPage=pageOpt}}pageOpt.remove()}$(editRow).attr("id","edit-"+id).addClass("inline-editor").show();$(".ptitle",editRow).focus();if(t.type=="post"){tax="post_tag";$('tr.inline-editor textarea[name="tags_input"]').suggest("admin-ajax.php?action=ajax-tag-search&tax="+tax,{delay:500,minchars:2,multiple:true,multipleSep:", "})}return false},save:function(id){var params,fields,page=$(".post_status_page").val()||"";if(typeof(id)=="object"){id=this.getId(id)}$("table.widefat .inline-edit-save .waiting").show();params={action:"inline-save",post_type:this.type,post_ID:id,edit_date:"true",post_status:page};fields=$("#edit-"+id+" :input").serialize();params=fields+"&"+$.param(params);$.post("admin-ajax.php",params,function(r){$("table.widefat .inline-edit-save .waiting").hide();if(r){if(-1!=r.indexOf("]*?>/g,"");$("#edit-"+id+" .inline-edit-save").append(''+r+"")}}else{$("#edit-"+id+" .inline-edit-save").append(''+inlineEditL10n.error+"")}},"html");return false},revert:function(){var id;if(id=$("table.widefat tr.inline-editor").attr("id")){$("table.widefat .inline-edit-save .waiting").hide();if("bulk-edit"==id){$("table.widefat #bulk-edit").removeClass("inline-editor").hide();$("#bulk-titles").html("");$("#inlineedit").append($("#bulk-edit"))}else{$("#"+id).remove();id=id.substr(id.lastIndexOf("-")+1);$(this.what+id).show()}}return false},getId:function(o){var id=o.tagName=="TR"?o.id:$(o).parents("tr").attr("id"),parts=id.split("-");return parts[parts.length-1]}};$(document).ready(function(){inlineEditPost.init()})})(jQuery); \ No newline at end of file +(function(a){inlineEditPost={init:function(){var c=this,d=a("#inline-edit"),b=a("#bulk-edit");c.type=a("table.widefat").hasClass("page")?"page":"post";c.what="#"+c.type+"-";d.keyup(function(f){if(f.which==27){return inlineEditPost.revert()}});b.keyup(function(f){if(f.which==27){return inlineEditPost.revert()}});a("a.cancel",d).click(function(){return inlineEditPost.revert()});a("a.save",d).click(function(){return inlineEditPost.save(this)});a("td",d).keydown(function(f){if(f.which==13){return inlineEditPost.save(this)}});a("a.cancel",b).click(function(){return inlineEditPost.revert()});a("#inline-edit .inline-edit-private input[value=private]").click(function(){var e=a("input.inline-edit-password-input");if(a(this).attr("checked")){e.val("").attr("disabled","disabled")}else{e.attr("disabled","")}});a("a.editinline").live("click",function(){inlineEditPost.edit(this);return false});a("#bulk-title-div").parents("fieldset").after(a("#inline-edit fieldset.inline-edit-categories").clone()).siblings("fieldset:last").prepend(a("#inline-edit label.inline-edit-tags").clone());a("span.catshow").click(function(){a(".inline-editor ul.cat-checklist").addClass("cat-hover");a(".inline-editor span.cathide").show();a(this).hide()});a("span.cathide").click(function(){a(".inline-editor ul.cat-checklist").removeClass("cat-hover");a(".inline-editor span.catshow").show();a(this).hide()});a('select[name="_status"] option[value="future"]',b).remove();a("#doaction, #doaction2").click(function(f){var g=a(this).attr("id").substr(2);if(a('select[name="'+g+'"]').val()=="edit"){f.preventDefault();c.setBulk()}else{if(a("form#posts-filter tr.inline-editor").length>0){c.revert()}}});a("#post-query-submit").click(function(f){if(a("form#posts-filter tr.inline-editor").length>0){c.revert()}})},toggle:function(c){var b=this;a(b.what+b.getId(c)).css("display")=="none"?b.revert():b.edit(c)},setBulk:function(){var e="",d=this.type,b,f=true;this.revert();a("#bulk-edit td").attr("colspan",a(".widefat:first thead th:visible").length);a("table.widefat tbody").prepend(a("#bulk-edit"));a("#bulk-edit").addClass("inline-editor").show();a('tbody th.check-column input[type="checkbox"]').each(function(g){if(a(this).attr("checked")){f=false;var h=a(this).val(),c;c=a("#inline_"+h+" .post_title").text()||inlineEditL10n.notitle;e+='
X'+c+"
"}});if(f){return this.revert()}a("#bulk-titles").html(e);a("#bulk-titles a").click(function(){var c=a(this).attr("id").substr(1);a('table.widefat input[value="'+c+'"]').attr("checked","");a("#ttle"+c).remove()});if(d=="post"){b="post_tag";a('tr.inline-editor textarea[name="tags_input"]').suggest("admin-ajax.php?action=ajax-tag-search&tax="+b,{delay:500,minchars:2,multiple:true,multipleSep:", "})}},edit:function(b){var o=this,j,d,g,n,i,h,k,m,l,c=true,p,e;o.revert();if(typeof(b)=="object"){b=o.getId(b)}j=["post_title","post_name","post_author","_status","jj","mm","aa","hh","mn","ss","post_password"];if(o.type=="page"){j.push("post_parent","menu_order","page_template")}if(o.type=="post"){j.push("tags_input")}d=a("#inline-edit").clone(true);a("td",d).attr("colspan",a(".widefat:first thead th:visible").length);if(a(o.what+b).hasClass("alternate")){a(d).addClass("alternate")}a(o.what+b).hide().after(d);g=a("#inline_"+b);if(!a(':input[name="post_author"] option[value='+a(".post_author",g).text()+"]",d).val()){a(':input[name="post_author"]',d).prepend('")}for(k=0;k0){m=h[0].className.split("-")[1];l=h;while(c){l=l.next("option");if(l.length==0){break}p=l[0].className.split("-")[1];if(p<=m){c=false}else{l.remove();l=h}}h.remove()}a(d).attr("id","edit-"+b).addClass("inline-editor").show();a(".ptitle",d).focus();if(o.type=="post"){e="post_tag";a('tr.inline-editor textarea[name="tags_input"]').suggest("admin-ajax.php?action=ajax-tag-search&tax="+e,{delay:500,minchars:2,multiple:true,multipleSep:", "})}return false},save:function(e){var d,b,c=a(".post_status_page").val()||"";if(typeof(e)=="object"){e=this.getId(e)}a("table.widefat .inline-edit-save .waiting").show();d={action:"inline-save",post_type:this.type,post_ID:e,edit_date:"true",post_status:c};b=a("#edit-"+e+" :input").serialize();d=b+"&"+a.param(d);a.post("admin-ajax.php",d,function(f){a("table.widefat .inline-edit-save .waiting").hide();if(f){if(-1!=f.indexOf("]*?>/g,"");a("#edit-"+e+" .inline-edit-save").append(''+f+"")}}else{a("#edit-"+e+" .inline-edit-save").append(''+inlineEditL10n.error+"")}},"html");return false},revert:function(){var b;if(b=a("table.widefat tr.inline-editor").attr("id")){a("table.widefat .inline-edit-save .waiting").hide();if("bulk-edit"==b){a("table.widefat #bulk-edit").removeClass("inline-editor").hide();a("#bulk-titles").html("");a("#inlineedit").append(a("#bulk-edit"))}else{a("#"+b).remove();b=b.substr(b.lastIndexOf("-")+1);a(this.what+b).show()}}return false},getId:function(c){var d=c.tagName=="TR"?c.id:a(c).parents("tr").attr("id"),b=d.split("-");return b[b.length-1]}};a(document).ready(function(){inlineEditPost.init()})})(jQuery); \ No newline at end of file diff --git a/wp-admin/link-manager.php b/wp-admin/link-manager.php index 076134df5c..e818e392aa 100644 --- a/wp-admin/link-manager.php +++ b/wp-admin/link-manager.php @@ -18,13 +18,14 @@ if ( isset($_GET['action']) && isset($_GET['linkcheck']) ) { wp_die( __('You do not have sufficient permissions to edit the links for this blog.') ); if ( 'delete' == $doaction ) { - foreach ( (array) $_GET['linkcheck'] as $link_id ) { + $bulklinks = (array) $_GET['linkcheck']; + foreach ( $bulklinks as $link_id ) { $link_id = (int) $link_id; wp_delete_link($link_id); } - wp_redirect( wp_get_referer() ); + wp_safe_redirect( wp_get_referer() ); exit; } } elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) { diff --git a/wp-admin/plugins.php b/wp-admin/plugins.php index 8d06964360..2dbec819ef 100644 --- a/wp-admin/plugins.php +++ b/wp-admin/plugins.php @@ -64,7 +64,7 @@ if ( !empty($action) ) { check_admin_referer('bulk-manage-plugins'); - $plugins = (array) $_POST['checked']; + $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); $plugins = array_filter($plugins, create_function('$plugin', 'return !is_plugin_active($plugin);') ); //Only activate plugins which are not already active. if ( empty($plugins) ) { wp_redirect("plugins.php?plugin_status=$status&paged=$page"); @@ -115,7 +115,7 @@ if ( !empty($action) ) { check_admin_referer('bulk-manage-plugins'); - $plugins = (array) $_POST['checked']; + $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array(); $plugins = array_filter($plugins, 'is_plugin_active'); //Do not deactivate plugins which are already deactivated. if ( empty($plugins) ) { wp_redirect("plugins.php?plugin_status=$status&paged=$page"); @@ -138,7 +138,8 @@ if ( !empty($action) ) { check_admin_referer('bulk-manage-plugins'); - $plugins = (array) $_REQUEST['checked']; //$_POST = from the plugin form; $_GET = from the FTP details screen. + //$_POST = from the plugin form; $_GET = from the FTP details screen. + $plugins = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array(); $plugins = array_filter($plugins, create_function('$plugin', 'return !is_plugin_active($plugin);') ); //Do not allow to delete Activated plugins. if ( empty($plugins) ) { wp_redirect("plugins.php?plugin_status=$status&paged=$page"); diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index f362077933..a8b4528514 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -342,7 +342,7 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'theme-preview', "/wp-admin/js/theme-preview$suffix.js", array( 'thickbox', 'jquery' ), '20090319' ); $scripts->add_data( 'theme-preview', 'group', 1 ); - $scripts->add( 'inline-edit-post', "/wp-admin/js/inline-edit-post$suffix.js", array( 'jquery', 'suggest' ), '20091016' ); + $scripts->add( 'inline-edit-post', "/wp-admin/js/inline-edit-post$suffix.js", array( 'jquery', 'suggest' ), '20091202' ); $scripts->add_data( 'inline-edit-post', 'group', 1 ); $scripts->localize( 'inline-edit-post', 'inlineEditL10n', array( 'error' => __('Error while saving the changes.'),