From d2a8f064aa4a5d2bf563dd851d1d4a184a79dd93 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Mon, 22 Apr 2013 03:08:51 +0000 Subject: [PATCH] Post locks: - Show 'Saving revision...' while autosaving after a post has been taken over. Change to 'Your latest changes were saved as a revision.' when autosave completes. - Make sure a user exists before using $user->display_name. - Add 'post_lock_text' action for extending the message text. git-svn-id: http://core.svn.wordpress.org/trunk@24042 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/css/wp-admin.css | 15 ++++++++++++--- wp-admin/includes/misc.php | 7 ++----- wp-admin/includes/post.php | 11 ++++++++--- wp-admin/js/post.js | 15 +++++++++++++-- wp-includes/js/autosave.js | 2 ++ 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/wp-admin/css/wp-admin.css b/wp-admin/css/wp-admin.css index 441bcee58e..4629c795ec 100644 --- a/wp-admin/css/wp-admin.css +++ b/wp-admin/css/wp-admin.css @@ -3399,6 +3399,7 @@ td.plugin-title p { width: 450px; margin-left: -225px; background: #fff; + line-height: 1.5; z-index: 1000005; } @@ -3425,14 +3426,22 @@ td.plugin-title p { #notification-dialog .post-locked-avatar { float: left; - margin-right: 20px; + margin: 0 20px 20px 0; } -#notification-dialog .currently-editing { - margin-bottom: 20px; +#notification-dialog .wp-tab-first { outline: 0; } +#notification-dialog .locked-saving img { + float: left; + margin-right: 3px; +} + +#notification-dialog-wrap.saving .locked-saving, +#notification-dialog-wrap.saved .locked-saved { + display: inline; +} /*------------------------------------------------------------------------------ 11.1 - Custom Fields diff --git a/wp-admin/includes/misc.php b/wp-admin/includes/misc.php index f954c5b6fa..a1a4680a4d 100644 --- a/wp-admin/includes/misc.php +++ b/wp-admin/includes/misc.php @@ -574,12 +574,11 @@ function wp_check_locked_posts( $response, $data, $screen_id ) { $post_id = (int) substr( $key, 5 ); if ( current_user_can( 'edit_post', $post_id ) && ( $user_id = wp_check_post_lock( $post_id ) ) && ( $user = get_userdata( $user_id ) ) ) { - $send = array(); + $send = array( 'text' => sprintf( __( '%s is currently editing' ), $user->display_name ) ); if ( ( $avatar = get_avatar( $user->ID, 18 ) ) && preg_match( "|src='([^']+)'|", $avatar, $matches ) ) $send['avatar_src'] = $matches[1]; - $send['text'] = sprintf( __( '%s is currently editing' ), $user->display_name ); $checked[$key] = $send; } } @@ -608,9 +607,7 @@ function wp_refresh_post_lock( $response, $data, $screen_id ) { if ( !current_user_can('edit_post', $post_id) ) return $response; - if ( $user_id = wp_check_post_lock( $post_id ) ) { - $user = get_userdata( $user_id ); - + if ( ( $user_id = wp_check_post_lock( $post_id ) ) && ( $user = get_userdata( $user_id ) ) ) { $error = array( 'text' => sprintf( __( '%s has taken over and is currently editing.' ), $user->display_name ) ); diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 07509f9058..40e9fa57f4 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -1197,8 +1197,7 @@ function _admin_notice_post_locked() { if ( ! $post = get_post() ) return; - if ( $user = wp_check_post_lock( $post->ID ) ) { - $user = get_userdata( $user ); + if ( ( $user_id = wp_check_post_lock( $post->ID ) ) && ( $user = get_userdata( $user_id ) ) ) { $locked = apply_filters( 'show_post_locked_dialog', true, $post, $user ); } else { $locked = false; @@ -1229,6 +1228,7 @@ function _admin_notice_post_locked() {
ID, 64 ); ?>

display_name ) ); ?>

+

@@ -1249,7 +1249,12 @@ function _admin_notice_post_locked() { ?>

-

+

+
+ + +

+

').attr( 'src', received.lock_error.avatar_src.replace(/&/g, '&') ); wrap.find('div.post-locked-avatar').empty().append( avatar ); } - wrap.show().find('p.currently-editing').text( received.lock_error.text ).focus(); + wrap.show().find('.currently-editing').text( received.lock_error.text ); + wrap.find('.wp-tab-first').focus(); } } else if ( received.new_lock ) { $('#active_post_lock').val( received.new_lock ); diff --git a/wp-includes/js/autosave.js b/wp-includes/js/autosave.js index fdc92f1698..dae969ba78 100644 --- a/wp-includes/js/autosave.js +++ b/wp-includes/js/autosave.js @@ -227,6 +227,7 @@ function autosave_loading() { } function autosave_enable_buttons() { + jQuery(document).trigger('autosave-enable-buttons'); if ( ! wp.heartbeat.connectionLost ) { // delay that a bit to avoid some rare collisions while the DOM is being updated. setTimeout(function(){ @@ -238,6 +239,7 @@ function autosave_enable_buttons() { } function autosave_disable_buttons() { + jQuery(document).trigger('autosave-disable-buttons'); jQuery('#submitpost').find(':button, :submit').prop('disabled', true); // Re-enable 5 sec later. Just gives autosave a head start to avoid collisions. setTimeout( autosave_enable_buttons, 5000 );