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
This commit is contained in:
Andrew Ozz 2013-04-22 03:08:51 +00:00
parent 2a4474f4de
commit d2a8f064aa
5 changed files with 37 additions and 13 deletions

View File

@ -3399,6 +3399,7 @@ td.plugin-title p {
width: 450px; width: 450px;
margin-left: -225px; margin-left: -225px;
background: #fff; background: #fff;
line-height: 1.5;
z-index: 1000005; z-index: 1000005;
} }
@ -3425,14 +3426,22 @@ td.plugin-title p {
#notification-dialog .post-locked-avatar { #notification-dialog .post-locked-avatar {
float: left; float: left;
margin-right: 20px; margin: 0 20px 20px 0;
} }
#notification-dialog .currently-editing { #notification-dialog .wp-tab-first {
margin-bottom: 20px;
outline: 0; 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 11.1 - Custom Fields

View File

@ -574,12 +574,11 @@ function wp_check_locked_posts( $response, $data, $screen_id ) {
$post_id = (int) substr( $key, 5 ); $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 ) ) ) { 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 ) ) if ( ( $avatar = get_avatar( $user->ID, 18 ) ) && preg_match( "|src='([^']+)'|", $avatar, $matches ) )
$send['avatar_src'] = $matches[1]; $send['avatar_src'] = $matches[1];
$send['text'] = sprintf( __( '%s is currently editing' ), $user->display_name );
$checked[$key] = $send; $checked[$key] = $send;
} }
} }
@ -608,9 +607,7 @@ function wp_refresh_post_lock( $response, $data, $screen_id ) {
if ( !current_user_can('edit_post', $post_id) ) if ( !current_user_can('edit_post', $post_id) )
return $response; return $response;
if ( $user_id = wp_check_post_lock( $post_id ) ) { if ( ( $user_id = wp_check_post_lock( $post_id ) ) && ( $user = get_userdata( $user_id ) ) ) {
$user = get_userdata( $user_id );
$error = array( $error = array(
'text' => sprintf( __( '%s has taken over and is currently editing.' ), $user->display_name ) 'text' => sprintf( __( '%s has taken over and is currently editing.' ), $user->display_name )
); );

View File

@ -1197,8 +1197,7 @@ function _admin_notice_post_locked() {
if ( ! $post = get_post() ) if ( ! $post = get_post() )
return; return;
if ( $user = wp_check_post_lock( $post->ID ) ) { if ( ( $user_id = wp_check_post_lock( $post->ID ) ) && ( $user = get_userdata( $user_id ) ) ) {
$user = get_userdata( $user );
$locked = apply_filters( 'show_post_locked_dialog', true, $post, $user ); $locked = apply_filters( 'show_post_locked_dialog', true, $post, $user );
} else { } else {
$locked = false; $locked = false;
@ -1229,6 +1228,7 @@ function _admin_notice_post_locked() {
<div class="post-locked-message"> <div class="post-locked-message">
<div class="post-locked-avatar"><?php echo get_avatar( $user->ID, 64 ); ?></div> <div class="post-locked-avatar"><?php echo get_avatar( $user->ID, 64 ); ?></div>
<p class="currently-editing wp-tab-first" tabindex="0"><?php esc_html_e( sprintf( __( 'This content is currently locked. If you take over, %s will be blocked from continuing to edit.' ), $user->display_name ) ); ?></p> <p class="currently-editing wp-tab-first" tabindex="0"><?php esc_html_e( sprintf( __( 'This content is currently locked. If you take over, %s will be blocked from continuing to edit.' ), $user->display_name ) ); ?></p>
<?php do_action( 'post_lock_text', $post ); ?>
<p> <p>
<a class="button" href="<?php echo esc_url( wp_get_referer() ); ?>"><?php _e('Go back'); ?></a> <a class="button" href="<?php echo esc_url( wp_get_referer() ); ?>"><?php _e('Go back'); ?></a>
<a class="button<?php echo $tab_last; ?>" href="<?php echo esc_url( $preview_link ); ?>"><?php _e('Preview'); ?></a> <a class="button<?php echo $tab_last; ?>" href="<?php echo esc_url( $preview_link ); ?>"><?php _e('Preview'); ?></a>
@ -1249,7 +1249,12 @@ function _admin_notice_post_locked() {
?> ?>
<div class="post-taken-over"> <div class="post-taken-over">
<div class="post-locked-avatar"></div> <div class="post-locked-avatar"></div>
<p class="currently-editing wp-tab-first" tabindex="0"></p> <p class="wp-tab-first" tabindex="0">
<span class="currently-editing"></span><br>
<span class="locked-saving hidden"><img src="images/wpspin_light-2x.gif" width="16" height="16" /> <?php _e('Saving revision...'); ?></span>
<span class="locked-saved hidden"><?php _e('Your latest changes were saved as a revision.'); ?></span>
</p>
<?php do_action( 'post_lock_text', $post ); ?>
<p><a class="button button-primary wp-tab-last" href="<?php echo esc_url( admin_url('edit.php') ); ?>"><?php _e('Go to All Posts'); ?></a></p> <p><a class="button button-primary wp-tab-last" href="<?php echo esc_url( admin_url('edit.php') ); ?>"><?php _e('Go to All Posts'); ?></a></p>
</div> </div>
<?php <?php

View File

@ -277,15 +277,26 @@ $(document).on( 'heartbeat-tick.refresh-lock', function( e, data ) {
wrap = $('#notification-dialog-wrap'); wrap = $('#notification-dialog-wrap');
if ( wrap.length && ! wrap.is(':visible') ) { if ( wrap.length && ! wrap.is(':visible') ) {
if ( typeof autosave == 'function' ) if ( typeof autosave == 'function' ) {
$(document).on('autosave-disable-buttons.post-lock', function() {
wrap.addClass('saving');
}).on('autosave-enable-buttons.post-lock', function() {
wrap.removeClass('saving').addClass('saved');
window.onbeforeunload = null;
});
// Save the latest changes and disable
autosave(); autosave();
autosave = function(){};
}
if ( received.lock_error.avatar_src ) { if ( received.lock_error.avatar_src ) {
avatar = $('<img class="avatar avatar-64 photo" width="64" height="64" />').attr( 'src', received.lock_error.avatar_src.replace(/&amp;/g, '&') ); avatar = $('<img class="avatar avatar-64 photo" width="64" height="64" />').attr( 'src', received.lock_error.avatar_src.replace(/&amp;/g, '&') );
wrap.find('div.post-locked-avatar').empty().append( avatar ); 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 ) { } else if ( received.new_lock ) {
$('#active_post_lock').val( received.new_lock ); $('#active_post_lock').val( received.new_lock );

View File

@ -227,6 +227,7 @@ function autosave_loading() {
} }
function autosave_enable_buttons() { function autosave_enable_buttons() {
jQuery(document).trigger('autosave-enable-buttons');
if ( ! wp.heartbeat.connectionLost ) { if ( ! wp.heartbeat.connectionLost ) {
// delay that a bit to avoid some rare collisions while the DOM is being updated. // delay that a bit to avoid some rare collisions while the DOM is being updated.
setTimeout(function(){ setTimeout(function(){
@ -238,6 +239,7 @@ function autosave_enable_buttons() {
} }
function autosave_disable_buttons() { function autosave_disable_buttons() {
jQuery(document).trigger('autosave-disable-buttons');
jQuery('#submitpost').find(':button, :submit').prop('disabled', true); jQuery('#submitpost').find(':button, :submit').prop('disabled', true);
// Re-enable 5 sec later. Just gives autosave a head start to avoid collisions. // Re-enable 5 sec later. Just gives autosave a head start to avoid collisions.
setTimeout( autosave_enable_buttons, 5000 ); setTimeout( autosave_enable_buttons, 5000 );