Batch edit: allow removal of selected posts, prevent page parent lock.

git-svn-id: http://svn.automattic.com/wordpress/trunk@9036 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2008-09-30 10:30:56 +00:00
parent a25b5ddc09
commit e3cc331835
10 changed files with 116 additions and 55 deletions

View File

@ -532,11 +532,13 @@ input.readonly {
color: #448abd;
}
#tagchecklist span a {
#tagchecklist span a,
#bulk-titles div a {
background: url(../images/xit.gif) no-repeat;
}
#tagchecklist span a:hover {
#tagchecklist span a:hover,
#bulk-titles div a:hover {
background: url(../images/xit.gif) no-repeat -10px 0;
}

View File

@ -516,11 +516,13 @@ input.readonly {
color: #448abd;
}
#tagchecklist span a {
#tagchecklist span a,
#bulk-titles div a {
background: url(../images/xit.gif) no-repeat;
}
#tagchecklist span a:hover {
#tagchecklist span a:hover,
#bulk-titles div a:hover {
background: url(../images/xit.gif) no-repeat -10px 0;
}

View File

@ -36,10 +36,13 @@ if ( isset($_GET['action']) && ( -1 != $_GET['action'] || -1 != $_GET['action2']
case 'edit':
if ( isset($_GET['post']) ) {
check_admin_referer('bulk-pages');
$_GET['post_status'] = $_GET['_status'];
if ( -1 == $_GET['post_author'] )
unset($_GET['post_author']);
if ( -1 == $_GET['_status'] ) {
$_GET['post_status'] = null;
unset($_GET['_status'], $_GET['post_status']);
} else {
$_GET['post_status'] = $_GET['_status'];
}
$done = bulk_edit_posts($_GET);
}
@ -50,10 +53,10 @@ if ( isset($_GET['action']) && ( -1 != $_GET['action'] || -1 != $_GET['action2']
elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
$sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback);
if ( isset($done) ) {
$done['upd'] = count( $done['upd'] );
$done['skip'] = count( $done['skip'] );
$done['updated'] = count( $done['updated'] );
$done['skipped'] = count( $done['skipped'] );
$done['locked'] = count( $done['locked'] );
$sendback = add_query_arg( $done, $sendback );
unset($done);
}
wp_redirect($sendback);
exit();
@ -111,16 +114,21 @@ require_once('admin-header.php'); ?>
<div class="wrap">
<?php if ( isset($_GET['upd']) || isset($_GET['skip']) ) { ?>
<?php if ( isset($_GET['locked']) || isset($_GET['skipped']) || isset($_GET['updated']) ) { ?>
<div id="message" class="updated fade"><p>
<?php if ( (int) $_GET['upd'] ) {
printf( __ngettext( '%d page updated.', '%d pages updated.', $_GET['upd'] ), number_format_i18n( $_GET['upd'] ) );
unset($_GET['upd']);
<?php if ( (int) $_GET['updated'] ) {
printf( __ngettext( '%d page updated.', '%d pages updated.', $_GET['updated'] ), number_format_i18n( $_GET['updated'] ) );
unset($_GET['updated']);
}
if ( (int) $_GET['skip'] ) {
printf( __ngettext( ' %d page not updated. Somebody is editing it.', ' %d pages not updated. Somebody is editing them.', $_GET['skip'] ), number_format_i18n( $_GET['skip'] ) );
unset($_GET['skip']);
if ( (int) $_GET['skipped'] ) {
printf( __ngettext( ' %d page not updated, invalid parent page specified.', ' %d pages not updated, invalid parent page specified.', $_GET['skipped'] ), number_format_i18n( $_GET['skipped'] ) );
unset($_GET['skipped']);
}
if ( (int) $_GET['locked'] ) {
printf( __ngettext( ' %d page not updated, somebody is editing it.', ' %d pages not updated, somebody is editing them.', $_GET['locked'] ), number_format_i18n( $_GET['skipped'] ) );
unset($_GET['locked']);
} ?>
</p></div>
<?php } ?>

View File

@ -36,10 +36,13 @@ if ( isset($_GET['action']) && ( -1 != $_GET['action'] || -1 != $_GET['action2']
case 'edit':
if ( isset($_GET['post']) ) {
check_admin_referer('bulk-posts');
$_GET['post_status'] = $_GET['_status'];
if ( -1 == $_GET['post_author'] )
unset($_GET['post_author']);
if ( -1 == $_GET['_status'] ) {
$_GET['post_status'] = null;
unset($_GET['_status'], $_GET['post_status']);
} else {
$_GET['post_status'] = $_GET['_status'];
}
$done = bulk_edit_posts($_GET);
}
@ -51,10 +54,10 @@ if ( isset($_GET['action']) && ( -1 != $_GET['action'] || -1 != $_GET['action2']
elseif ( strpos($sendback, 'attachments.php') !== false ) $sendback = admin_url('attachments.php');
$sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback);
if ( isset($done) ) {
$done['upd'] = count( $done['upd'] );
$done['skip'] = count( $done['skip'] );
$done['updated'] = count( $done['updated'] );
$done['skipped'] = count( $done['skipped'] );
$done['locked'] = count( $done['locked'] );
$sendback = add_query_arg( $done, $sendback );
unset($done);
}
wp_redirect($sendback);
exit();
@ -100,26 +103,31 @@ else
</div></form>
</div></div>
<div class="wrap">
<?php
if ( isset($_GET['posted']) && $_GET['posted'] ) : $_GET['posted'] = (int) $_GET['posted']; ?>
<div id="message" class="updated fade"><p><strong><?php _e('Your post has been saved.'); ?></strong> <a href="<?php echo get_permalink( $_GET['posted'] ); ?>"><?php _e('View post'); ?></a> | <a href="<?php echo get_edit_post_link( $_GET['posted'] ); ?>"><?php _e('Edit post'); ?></a></p></div>
<?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('posted'), $_SERVER['REQUEST_URI']);
endif; ?>
<?php if ( isset($_GET['upd']) && (int) $_GET['upd'] ) { ?>
<?php if ( isset($_GET['locked']) || isset($_GET['skipped']) || isset($_GET['updated']) ) { ?>
<div id="message" class="updated fade"><p>
<?php printf( __ngettext( '%d post updated.', '%d posts updated.', $_GET['upd'] ), number_format_i18n( $_GET['upd'] ) );
unset($_GET['upd']);
<?php if ( (int) $_GET['updated'] ) {
printf( __ngettext( '%d page updated.', '%d pages updated.', $_GET['updated'] ), number_format_i18n( $_GET['updated'] ) );
unset($_GET['updated']);
}
if ( isset($_GET['skip']) && (int) $_GET['skip'] ) {
printf( __ngettext( ' %d post not updated. Somebody is editing it.', ' %d posts not updated. Somebody is editing them.', $_GET['skip'] ), number_format_i18n( $_GET['skip'] ) );
unset($_GET['skip']);
if ( (int) $_GET['skipped'] )
unset($_GET['skipped']);
if ( (int) $_GET['locked'] ) {
printf( __ngettext( ' %d page not updated, somebody is editing it.', ' %d pages not updated, somebody is editing them.', $_GET['locked'] ), number_format_i18n( $_GET['skipped'] ) );
unset($_GET['locked']);
} ?>
</p></div>
<?php } ?>
<div class="wrap">
<ul class="subsubsub">
<?php
if ( empty($locked_post_status) ) :

View File

@ -177,7 +177,9 @@ function edit_post( $post_data = null ) {
return $post_ID;
}
// updates all bulk edited posts/pages, adding (but not removing) tags and categories. Skips pages when they would be their own parent or child.
function bulk_edit_posts( $post_data = null ) {
global $wpdb;
if ( empty($post_data) )
$post_data = &$_POST;
@ -192,6 +194,12 @@ function bulk_edit_posts( $post_data = null ) {
$post_IDs = array_map( intval, (array) $post_data['post'] );
$reset = array( 'post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tags_input', 'post_category' );
foreach ( $reset as $field ) {
if ( isset($post_data[$field]) && ( '' == $post_data[$field] || -1 == $post_data[$field] ) )
unset($post_data[$field]);
}
if ( isset($post_data['post_category']) ) {
if ( is_array($post_data['post_category']) && ! empty($post_data['post_category']) )
$new_cats = array_map( absint, $post_data['post_category'] );
@ -200,28 +208,39 @@ function bulk_edit_posts( $post_data = null ) {
}
if ( isset($post_data['tags_input']) ) {
if ( ! empty($post_data['tags_input']) ) {
$new_tags = preg_replace( '/\s*,\s*/', ',', rtrim($post_data['tags_input'], ' ,') );
$new_tags = preg_replace( '/\s*,\s*/', ',', rtrim( trim($post_data['tags_input']), ' ,' ) );
$new_tags = explode(',', $new_tags);
} else {
unset($post_data['tags_input']);
}
if ( isset($post_data['post_parent']) && ($parent = (int) $post_data['post_parent']) ) {
$pages = $wpdb->get_results("SELECT ID, post_parent FROM $wpdb->posts WHERE post_type = 'page'");
$children = array();
for ( $i = 0; $i < 50 && $parent > 0; $i++ ) {
$children[] = $parent;
foreach ( $pages as $page ) {
if ( $page->ID == $parent ) {
$parent = $page->post_parent;
break;
}
}
}
}
$reset = array( 'post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private' );
foreach ( $reset as $field ) {
if ( isset($post_data[$field]) && '' == $post_data[$field] )
unset($post_data[$field]);
}
$updated = $skipped = array();
$updated = $skipped = $locked = array();
foreach ( $post_IDs as $post_ID ) {
if ( wp_check_post_lock( $post_ID ) ) {
if ( isset($children) && in_array($post_ID, $children) ) {
$skipped[] = $post_ID;
continue;
}
if ( wp_check_post_lock( $post_ID ) ) {
$locked[] = $post_ID;
continue;
}
if ( isset($new_cats) ) {
$cats = (array) wp_get_post_categories($post_ID);
$post_data['post_category'] = array_unique( array_merge($cats, $new_cats) );
@ -236,7 +255,7 @@ function bulk_edit_posts( $post_data = null ) {
$updated[] = wp_update_post( $post_data );
}
return array( 'upd' => $updated, 'skip' => $skipped );
return array( 'updated' => $updated, 'skipped' => $skipped, 'locked' => $locked );
}
// Default post information to use when populating the "Write Post" form.

View File

@ -693,7 +693,7 @@ function inline_edit_row( $type ) {
<div class="in">
<select name="post_parent">
<?php if ( $bulk ) { ?>
<option value=""><?php _e('- No Change -'); ?></option>
<option value="-1"><?php _e('- No Change -'); ?></option>
<?php } ?>
<option value="0"><?php _e('Main Page (no parent)'); ?></option>
<?php parent_dropdown(); ?>
@ -706,7 +706,7 @@ function inline_edit_row( $type ) {
<div class="in">
<select name="page_template">
<?php if ( $bulk ) { ?>
<option value=""><?php _e('- No Change -'); ?></option>
<option value="-1"><?php _e('- No Change -'); ?></option>
<?php } ?>
<option value="default"><?php _e('Default Template'); ?></option>
<?php page_template_dropdown() ?>
@ -784,7 +784,7 @@ function inline_edit_row( $type ) {
<div class="title"><?php _e('Author'); ?></div>
<div class="in">
<?php
$users_opt = array('include' => $authors, 'name' => 'post_author', 'class'=> 'authors');
$users_opt = array('include' => $authors, 'name' => 'post_author', 'class'=> 'authors', 'multi' => 1);
if ( $bulk ) $users_opt['show_option_none'] = __('- No Change -');
wp_dropdown_users( $users_opt ); ?>
</div>
@ -809,7 +809,7 @@ function inline_edit_row( $type ) {
<div class="in">
<select name="_status">
<?php if ( $bulk ) { ?>
<option value=""><?php _e('- No Change -'); ?></option>
<option value="-1"><?php _e('- No Change -'); ?></option>
<?php if ( $can_publish ) { ?>
<option value="private"><?php _e('Private') ?></option>
<?php } ?>

View File

@ -98,11 +98,17 @@ inlineEdit = {
if ( $(this).attr('checked') ) {
var id = $(this).val();
c = c == '' ? ' class="alternate"' : '';
te += '<div'+c+'>'+$('#inline_'+id+' .post_title').text()+'</div>';
te += '<div'+c+' id="ttle'+id+'"><a id="_'+id+'" class="ntdelbutton">X</a>'+$('#inline_'+id+' .post_title').text()+'</div>';
}
});
$('#bulk-titles').html(te);
$('#bulk-titles a').click(function() {
var id = $(this).attr('id').substr(1), r = inlineEdit.type+'-'+id;
$('table.widefat input[value="'+id+'"]').attr('checked', '');
$('#ttle'+id).remove();
});
// enable autocomplete for tags
if ( this.type == 'post' )

View File

@ -2310,6 +2310,19 @@ a.togbox {
padding: 1px 2px;
}
#bulk-titles div a {
cursor: pointer;
display: block;
float: left;
height: 10px;
margin: 3px 3px 0 -2px;
overflow: hidden;
position: relative;
text-indent: -9999px;
width: 10px;
}
/* Media library */
#wpbody-content #media-items .describe {
border-collapse: collapse;

View File

@ -244,7 +244,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'theme-preview', '/wp-admin/js/theme-preview.js', array( 'thickbox', 'jquery' ), '20080625' );
$scripts->add( 'inline-edit', '/wp-admin/js/inline-edit.js', array( 'jquery', 'jquery-form', 'suggest' ), '20080926' );
$scripts->add( 'inline-edit', '/wp-admin/js/inline-edit.js', array( 'jquery', 'jquery-form', 'suggest' ), '20080930' );
$scripts->localize( 'inline-edit', 'inlineEditL10n', array(
'edit' => __('Double-click to edit')
) );
@ -304,7 +304,7 @@ function wp_default_styles( &$styles ) {
$rtl_styles = array( 'global', 'colors', 'dashboard', 'ie', 'install', 'login', 'media', 'theme-editor', 'upload', 'widgets', 'press-this', 'press-this-ie' );
$styles->add( 'wp-admin', '/wp-admin/wp-admin.css', array(), '20080926' );
$styles->add( 'wp-admin', '/wp-admin/wp-admin.css', array(), '20080930' );
$styles->add_data( 'wp-admin', 'rtl', '/wp-admin/rtl.css' );
$styles->add( 'ie', '/wp-admin/css/ie.css' );

View File

@ -426,6 +426,7 @@ function setup_userdata($user_id = '') {
* <li>order - Default is 'ASC'. Can also be 'DESC'.</li>
* <li>include - User IDs to include.</li>
* <li>exclude - User IDs to exclude.</li>
* <li>multi - Default is 'false'. Whether to skip the ID attribute on the 'select' element.</li>
* <li>show - Default is 'display_name'. User table column to display.</li>
* <li>echo - Default is '1'. Whether to display or retrieve content.</li>
* <li>selected - Which User ID is selected.</li>
@ -444,7 +445,7 @@ function wp_dropdown_users( $args = '' ) {
$defaults = array(
'show_option_all' => '', 'show_option_none' => '',
'orderby' => 'display_name', 'order' => 'ASC',
'include' => '', 'exclude' => '',
'include' => '', 'exclude' => '', 'multi' => 0,
'show' => 'display_name', 'echo' => 1,
'selected' => 0, 'name' => 'user', 'class' => ''
);
@ -479,7 +480,9 @@ function wp_dropdown_users( $args = '' ) {
$output = '';
if ( !empty($users) ) {
$output = "<select name='$name' id='$name' class='$class'>\n";
$id = $multi ? "" : "id='$name'";
$output = "<select name='$name' $id class='$class'>\n";
if ( $show_option_all )
$output .= "\t<option value='0'>$show_option_all</option>\n";