From 4e4560341019ed53286c0ba5463a71bc13a3dbdf Mon Sep 17 00:00:00 2001
From: ryan
Date: Tue, 4 Mar 2008 00:05:30 +0000
Subject: [PATCH] Post edit collision detection fixes from mdawaffe. fixes
#6043
git-svn-id: http://svn.automattic.com/wordpress/trunk@7146 1a063a9b-81f0-0310-95a4-ce76da25c4cd
---
wp-admin/admin-ajax.php | 4 +---
wp-admin/edit-form-advanced.php | 1 +
wp-admin/edit-page-form.php | 1 +
wp-admin/includes/post.php | 4 ++++
wp-admin/page.php | 2 +-
wp-admin/post.php | 2 +-
wp-admin/wp-admin.css | 4 ++++
wp-includes/js/autosave.js | 6 ++++--
8 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php
index c209f05d58..fee91f81b7 100644
--- a/wp-admin/admin-ajax.php
+++ b/wp-admin/admin-ajax.php
@@ -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;
diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php
index a8e9774e8e..c90e692a6c 100644
--- a/wp-admin/edit-form-advanced.php
+++ b/wp-admin/edit-form-advanced.php
@@ -151,6 +151,7 @@ if ( ( 'edit' == $action) && current_user_can('delete_post', $post_ID) )
post_modified), mysql2date(get_option('time_format'), $post->post_modified)); ?>
+
diff --git a/wp-admin/edit-page-form.php b/wp-admin/edit-page-form.php
index 91b89fb2a4..b2353d43b6 100644
--- a/wp-admin/edit-page-form.php
+++ b/wp-admin/edit-page-form.php
@@ -129,6 +129,7 @@ if ( ('edit' == $action) && current_user_can('delete_page', $post_ID) )
post_modified), mysql2date(get_option('time_format'), $post->post_modified)); ?>
+
diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php
index c10511ab1a..000269597c 100644
--- a/wp-admin/includes/post.php
+++ b/wp-admin/includes/post.php
@@ -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;
}
diff --git a/wp-admin/page.php b/wp-admin/page.php
index 6c558bd73c..04cbcc1368 100644
--- a/wp-admin/page.php
+++ b/wp-admin/page.php
@@ -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( "'", "\'", "" );
add_action('admin_notices', create_function( '', "echo '$message';" ) );
} else {
diff --git a/wp-admin/post.php b/wp-admin/post.php
index b9635e1654..d47ead3110 100644
--- a/wp-admin/post.php
+++ b/wp-admin/post.php
@@ -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( "'", "\'", "" );
add_action('admin_notices', create_function( '', "echo '$message';" ) );
} else {
diff --git a/wp-admin/wp-admin.css b/wp-admin/wp-admin.css
index b8a4ccf7cb..45945fbaac 100644
--- a/wp-admin/wp-admin.css
+++ b/wp-admin/wp-admin.css
@@ -1215,6 +1215,10 @@ html, body {
border-bottom: 1px solid #ccc;
}
+.submitbox #autosave .error {
+ color: #333;
+}
+
/* Categories */
#categorydiv #category-adder {
diff --git a/wp-includes/js/autosave.js b/wp-includes/js/autosave.js
index 3f1f1e2652..b96fcc783d 100644
--- a/wp-includes/js/autosave.js
+++ b/wp-includes/js/autosave.js
@@ -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,