Post edit collision detection fixes from mdawaffe. fixes #6043

git-svn-id: http://svn.automattic.com/wordpress/trunk@7146 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-03-04 00:05:30 +00:00
parent 08ed4d3b40
commit 4e45603410
8 changed files with 17 additions and 7 deletions

View File

@ -472,8 +472,6 @@ case 'autosave' : // The name of this action is hardcoded in edit_post()
check_ajax_referer( 'autosave', 'autosavenonce' );
global $current_user;
$_POST['post_content'] = $_POST['content'];
$_POST['post_excerpt'] = $_POST['excerpt'];
$_POST['post_status'] = 'draft';
$_POST['post_category'] = explode(",", $_POST['catslist']);
$_POST['tags_input'] = explode(",", $_POST['tags_input']);
@ -521,7 +519,7 @@ case 'autosave' : // The name of this action is hardcoded in edit_post()
die(__('You are not allowed to edit this post.'));
}
if ( $do_autosave ) {
$id = wp_update_post($_POST);
$id = edit_post();
$data = $message;
} else {
$id = $post->ID;

View File

@ -151,6 +151,7 @@ if ( ( 'edit' == $action) && current_user_can('delete_post', $post_ID) )
<br class="clear" />
<?php if ($post_ID): ?>
<?php printf(__('Last edited on %1$s at %2$s'), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified)); ?>
<br class="clear" />
<?php endif; ?>
<span id="autosave"></span>
</p>

View File

@ -129,6 +129,7 @@ if ( ('edit' == $action) && current_user_can('delete_page', $post_ID) )
<br class="clear" />
<?php if ($post_ID): ?>
<?php printf(__('Last edited on %1$s at %2$s'), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified)); ?>
<br class="clear" />
<?php endif; ?>
<span id="autosave"></span>
</p>

View File

@ -113,6 +113,8 @@ function edit_post() {
// Now that we have an ID we can fix any attachment anchor hrefs
_fix_attachment_links( $post_ID );
wp_set_post_lock( $post_ID, $GLOBALS['current_user']->ID );
return $post_ID;
}
@ -321,6 +323,8 @@ function wp_write_post() {
// Now that we have an ID we can fix any attachment anchor hrefs
_fix_attachment_links( $post_ID );
wp_set_post_lock( $post_ID, $GLOBALS['current_user']->ID );
return $post_ID;
}

View File

@ -60,7 +60,7 @@ case 'edit':
if ( $last = wp_check_post_lock( $post->ID ) ) {
$last_user = get_userdata( $last );
$last_user_name = $last_user ? $last_user->display_name : __('Somebody');
$message = sprintf( __( '%s is currently editing this page' ), wp_specialchars( $last_user_name ) );
$message = sprintf( __( 'Warning: %s is currently editing this page' ), wp_specialchars( $last_user_name ) );
$message = str_replace( "'", "\'", "<div class='error'><p>$message</p></div>" );
add_action('admin_notices', create_function( '', "echo '$message';" ) );
} else {

View File

@ -69,7 +69,7 @@ case 'edit':
if ( $last = wp_check_post_lock( $post->ID ) ) {
$last_user = get_userdata( $last );
$last_user_name = $last_user ? $last_user->display_name : __('Somebody');
$message = sprintf( __( '%s is currently editing this post' ), wp_specialchars( $last_user_name ) );
$message = sprintf( __( 'Warning: %s is currently editing this post' ), wp_specialchars( $last_user_name ) );
$message = str_replace( "'", "\'", "<div class='error'><p>$message</p></div>" );
add_action('admin_notices', create_function( '', "echo '$message';" ) );
} else {

View File

@ -1215,6 +1215,10 @@ html, body {
border-bottom: 1px solid #ccc;
}
.submitbox #autosave .error {
color: #333;
}
/* Categories */
#categorydiv #category-adder {

View File

@ -1,5 +1,6 @@
var autosaveLast = '';
var autosavePeriodical;
var autosaveOldMessage = '';
jQuery(function($) {
autosaveLast = $('#post #title').val()+$('#post #content').val();
@ -17,7 +18,6 @@ jQuery(function($) {
// called when autosaving pre-existing post
function autosave_saved(response) {
var oldMessage = jQuery('#autosave').html();
var res = wpAjax.parseAjaxResponse(response, 'autosave'); // parse the ajax response
var message = '';
@ -39,7 +39,7 @@ function autosave_saved(response) {
}
}
if ( message ) { jQuery('#autosave').html(message); } // update autosave message
else if ( oldMessage && res ) { jQuery('#autosave').html( oldMessage ); }
else if ( autosaveOldMessage && res ) { jQuery('#autosave').html( autosaveOldMessage ); }
autosave_enable_buttons(); // re-enable disabled form buttons
return res;
}
@ -180,6 +180,8 @@ var autosave = function() {
post_data['autosave'] = 0;
}
autosaveOldMessage = jQuery('#autosave').html();
jQuery.ajax({
data: post_data,
beforeSend: doAutoSave ? autosave_loading : null,