Ticket #23697: 23697-2.patch
File 23697-2.patch, 9.3 KB (added by , 12 years ago) |
---|
-
wp-admin/css/wp-admin.css
diff --git wp-admin/css/wp-admin.css wp-admin/css/wp-admin.css index ccf1f8b..c2b461d 100644
td.plugin-title p { 3407 3407 border-style: solid; 3408 3408 } 3409 3409 3410 #notification-dialog { 3411 position: fixed; 3412 top: 30%; 3413 left: 30%; 3414 right: 30%; 3415 padding: 20px; 3416 background: #fff; 3417 z-index: 1000005; 3418 } 3419 3420 #notification-dialog-wrap { 3421 position: fixed; 3422 top: 0; 3423 left: 0; 3424 right: 0; 3425 bottom: 0; 3426 background-color: rgba(0, 0, 0, 0.5); 3427 z-index: 1000000; 3428 } 3429 3430 .post-locked-avatar { 3431 float: left; 3432 margin-right: 20px; 3433 } 3434 3435 .currently-editing { 3436 margin-bottom: 20px; 3437 } 3438 3410 3439 3411 3440 /*------------------------------------------------------------------------------ 3412 3441 11.1 - Custom Fields -
wp-admin/includes/ajax-actions.php
diff --git wp-admin/includes/ajax-actions.php wp-admin/includes/ajax-actions.php index 0c57781..78796fb 100644
function wp_ajax_autosave() { 1057 1057 $_POST['post_status'] = 'draft'; 1058 1058 1059 1059 if ( $last = wp_check_post_lock( $post->ID ) ) { 1060 // This will change after we have per-user autosaves 1060 1061 $do_autosave = $do_lock = false; 1061 1062 1062 1063 $last_user = get_userdata( $last ); … … function wp_ajax_autosave() { 1064 1065 $data = __( 'Autosave disabled.' ); 1065 1066 1066 1067 $supplemental['disable_autosave'] = 'disable'; 1067 $alert .= sprintf( __( '%s is currently editing this article. If you update it, you will overwrite the changes.' ), esc_html( $last_user_name ) );1068 1068 } 1069 1069 1070 1070 if ( 'page' == $post->post_type ) { … … function wp_ajax_autosave() { 1094 1094 $id = $post->ID; 1095 1095 } 1096 1096 1097 if ( $do_lock && empty( $_POST['auto_draft'] ) && $id && is_numeric( $id ) ) {1098 $lock_result = wp_set_post_lock( $id );1099 $supplemental['active-post-lock'] = implode( ':', $lock_result );1100 }1101 1102 1097 if ( $nonce_age == 2 ) { 1103 1098 $supplemental['replace-autosavenonce'] = wp_create_nonce('autosave'); 1104 1099 $supplemental['replace-getpermalinknonce'] = wp_create_nonce('getpermalink'); … … function wp_ajax_wp_remove_post_lock() { 1777 1772 if ( $active_lock[1] != get_current_user_id() ) 1778 1773 wp_die( 0 ); 1779 1774 1780 $new_lock = ( time() - apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2) + 5 ) . ':' . $active_lock[1];1775 $new_lock = ( time() - apply_filters( 'wp_check_post_lock_window', 120 ) + 5 ) . ':' . $active_lock[1]; 1781 1776 update_post_meta( $post_id, '_edit_lock', $new_lock, implode( ':', $active_lock ) ); 1782 1777 wp_die( 1 ); 1783 1778 } -
wp-admin/includes/misc.php
diff --git wp-admin/includes/misc.php wp-admin/includes/misc.php index b1ee77a..4722dd5 100644
function wp_check_locked_posts( $response, $data ) { 586 586 return $response; 587 587 } 588 588 add_filter( 'heartbeat_received', 'wp_check_locked_posts', 10, 2 ); 589 590 /** 591 * Check lock status on the New/Edit Post screen and refresh the lock 592 * 593 * @since 3.6 594 */ 595 function wp_refresh_post_lock( $response, $data, $screen_id ) { 596 if ( 'post' == $screen_id && array_key_exists( 'wp-refresh-post-lock', $data ) ) { 597 $received = $data['wp-refresh-post-lock']; 598 $send = array(); 599 600 if ( !$post_id = absint( $received['post_id'] ) ) 601 return $response; 602 603 if ( !current_user_can('edit_post', $post_id) ) 604 return $response; 605 606 if ( $user_id = wp_check_post_lock( $post_id ) ) { 607 $user = get_userdata( $user_id ); 608 $send['lock_error'] = '<div class="post-locked-avatar">' . get_avatar( $user->ID, 64 ) . '</div>' . 609 '<p>' . sprintf( __( '%s has taken over and is currently editing.' ), $user->display_name ) . '</p>'; 610 } else { 611 if ( $new_lock = wp_set_post_lock( $post_id ) ) 612 $send['new_lock'] = implode( ':', $new_lock ); 613 } 614 615 $response['wp-refresh-post-lock'] = $send; 616 } 617 618 return $response; 619 } 620 add_filter( 'heartbeat_received', 'wp_refresh_post_lock', 10, 3 ); -
wp-admin/includes/post.php
diff --git wp-admin/includes/post.php wp-admin/includes/post.php index ff06525..6f66de4 100644
function wp_check_post_lock( $post_id ) { 1162 1162 $time = $lock[0]; 1163 1163 $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true ); 1164 1164 1165 $time_window = apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2);1165 $time_window = apply_filters( 'wp_check_post_lock_window', 120 ); 1166 1166 1167 1167 if ( $time && $time > time() - $time_window && $user != get_current_user_id() ) 1168 1168 return $user; … … function wp_set_post_lock( $post_id ) { 1192 1192 } 1193 1193 1194 1194 /** 1195 * Outputs the notice message to say that someone else is editing this post at the moment.1195 * Outputs the HTML for the notice to say that someone else is editing or has taken over editing of this post. 1196 1196 * 1197 1197 * @since 2.8.5 1198 1198 * @return none 1199 1199 */ 1200 1200 function _admin_notice_post_locked() { 1201 $post = get_post(); 1202 $lock = explode( ':', get_post_meta( $post->ID, '_edit_lock', true ) ); 1203 $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true ); 1204 $last_user = get_userdata( $user ); 1205 $last_user_name = $last_user ? $last_user->display_name : __('Somebody'); 1201 global $post_ID; 1206 1202 1207 switch ($post->post_type) { 1208 case 'post': 1209 $message = __( 'Warning: %s is currently editing this post' ); 1210 break; 1211 case 'page': 1212 $message = __( 'Warning: %s is currently editing this page' ); 1213 break; 1214 default: 1215 $message = __( 'Warning: %s is currently editing this.' ); 1203 if ( $post_ID && ( $user = wp_check_post_lock( $post_ID ) ) ) { 1204 $user = get_userdata( $user ); 1205 1206 $message = sprintf( __( 'This content is currently locked. If you take over, %s will be blocked from continuing to edit.' ), $user->display_name ); 1207 } else { 1208 $message = ''; 1209 } 1210 1211 ?> 1212 <div id="notification-dialog-wrap"<?php if ( ! $message ) echo ' style="display:none"'; ?>> 1213 <div id="notification-dialog"> 1214 <?php 1215 1216 if ( $message ) { 1217 ?> 1218 <div class="post-locked-message"> 1219 <div class="post-locked-avatar"><?php echo get_avatar( $user->ID, 64 ) ?></div> 1220 <p><?php echo esc_html( $message ); ?></p> 1221 <p> 1222 <a class="button" href="<?php echo esc_url( wp_get_referer() ); ?>"><?php _e('Go back'); ?></a> 1223 <a class="button button-primary" href="<?php echo esc_url( add_query_arg( 'get-post-lock', '1', get_edit_post_link( $post_ID, 'url' ) ) ); ?>"><?php _e('Take over'); ?></a> 1224 </p> 1225 </div> 1226 <?php 1227 } else { 1228 ?> 1229 <div class="post-taken-over"> 1230 <p class="currently-editing"></p> 1231 <p><a class="button button-primary" href="<?php echo esc_url( admin_url('edit.php') ); ?>"><?php _e('Go to All Posts'); ?></a></p> 1232 </div> 1233 <?php 1216 1234 } 1217 1235 1218 $message = sprintf( $message, esc_html( $last_user_name ) ); 1219 echo "<div class='error'><p>$message</p></div>"; 1236 ?> 1237 </div> 1238 </div> 1239 <?php 1220 1240 } 1221 1241 1222 1242 /** -
wp-admin/js/post.js
diff --git wp-admin/js/post.js wp-admin/js/post.js index d0d0403..4fb01a9 100644
WPRemoveThumbnail = function(nonce){ 251 251 ); 252 252 }; 253 253 254 })(jQuery); 254 $(document).on( 'heartbeat-send.refresh-lock', function( e, data ) { 255 var lock = $('#active_post_lock').val(), post_id = $('#post_ID').val(), send = {}; 256 257 if ( !post_id ) 258 return; 259 260 send['post_id'] = post_id; 261 262 if ( lock ) 263 send['lock'] = lock; 264 265 data['wp-refresh-post-lock'] = send; 266 }); 267 268 $(document).on( 'heartbeat-tick.refresh-lock', function( e, data ) { 269 var received; 270 271 if ( data['wp-refresh-post-lock'] ) { 272 received = data['wp-refresh-post-lock']; 273 274 if ( received['lock_error'] ) { 275 // show "editing taken over" message 276 var wrap = $('#notification-dialog-wrap'); 277 278 if ( !wrap.is(':visible') ) { 279 autosave(); 280 wrap.find('p.currently-editing').html( received['lock_error'] ); 281 wrap.show(); 282 } 283 } 284 285 if ( received['new_lock'] ) 286 $('#active_post_lock').val( received['new_lock'].replace(/[^0-9:]+/, '') ); 287 } 288 }); 289 290 }(jQuery)); 255 291 256 292 jQuery(document).ready( function($) { 257 293 var stamp, visibility, sticky = '', last = 0, co = $('#content'); -
wp-admin/post.php
diff --git wp-admin/post.php wp-admin/post.php index 95f1cc6..7be9bfb 100644
case 'edit': 147 147 if ( 'trash' == $post->post_status ) 148 148 wp_die( __('You can’t edit this item because it is in the Trash. Please restore it and try again.') ); 149 149 150 if ( !empty( $_GET['get-post-lock'] ) ) { 151 wp_set_post_lock( $post_id ); 152 wp_redirect( get_edit_post_link( $post_id, 'url' ) ); 153 exit(); 154 } 155 150 156 $post_type = $post->post_type; 151 157 if ( 'post' == $post_type ) { 152 158 $parent_file = "edit.php"; … … case 'edit': 165 171 $post_new_file = "post-new.php?post_type=$post_type"; 166 172 } 167 173 168 if ( $last = wp_check_post_lock( $post->ID ) ) { 169 add_action('admin_notices', '_admin_notice_post_locked' ); 170 } else { 174 if ( ! wp_check_post_lock( $post->ID ) ) { 171 175 $active_post_lock = wp_set_post_lock( $post->ID ); 172 176 173 177 if ( 'attachment' !== $post_type ) 174 178 wp_enqueue_script('autosave'); 175 179 } 176 180 181 add_action( 'admin_footer', '_admin_notice_post_locked' ); 182 177 183 $title = $post_type_object->labels->edit_item; 178 184 $post = get_post($post_id, OBJECT, 'edit'); 179 185 … … case 'trash': 217 223 if ( !current_user_can($post_type_object->cap->delete_post, $post_id) ) 218 224 wp_die( __('You are not allowed to move this item to the Trash.') ); 219 225 226 if ( $user_id = wp_check_post_lock( $post_id ) ) { 227 $user = get_userdata( $user_id ); 228 wp_die( sprintf( __( 'You cannot move this item to the Trash. %s is currently editing.' ), $user->display_name ) ); 229 } 230 220 231 if ( ! wp_trash_post($post_id) ) 221 232 wp_die( __('Error in moving to Trash.') ); 222 233