Ticket #16215: 16215.7.diff
File 16215.7.diff, 10.8 KB (added by , 12 years ago) |
---|
-
wp-includes/post-template.php
1403 1403 continue; 1404 1404 1405 1405 $date = wp_post_revision_title( $revision ); 1406 $name = get_the_ author_meta( 'display_name', $revision->post_author);1406 $name = get_the_modified_author( $revision ); 1407 1407 1408 1408 if ( 'form-table' == $format ) { 1409 1409 if ( $left ) -
wp-includes/post.php
2822 2822 $wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] ), $where ); 2823 2823 } 2824 2824 2825 if ( 'revision' !== $post_type ) 2826 update_post_meta( $post_ID, '_edit_last', $user_ID ); 2827 2825 2828 if ( is_object_in_taxonomy($post_type, 'category') ) 2826 2829 wp_set_post_categories( $post_ID, $post_category ); 2827 2830 -
wp-includes/revision.php
52 52 $return['post_parent'] = $post['ID']; 53 53 $return['post_status'] = 'inherit'; 54 54 $return['post_type'] = 'revision'; 55 $return['post_name'] = $autosave ? "$post[ID]- autosave" : "$post[ID]-revision";55 $return['post_name'] = $autosave ? "$post[ID]-1-autosave" : "$post[ID]-1-revision"; // "1" is the revisioning system version 56 56 $return['post_date'] = isset($post['post_modified']) ? $post['post_modified'] : ''; 57 57 $return['post_date_gmt'] = isset($post['post_modified_gmt']) ? $post['post_modified_gmt'] : ''; 58 $return['post_author'] = get_post_meta( $post['ID'], '_edit_last', true ); 58 59 59 60 return $return; 60 61 } … … 142 143 * @subpackage Post_Revisions 143 144 * @since 2.6.0 144 145 * @uses wp_get_post_revisions() 145 * 146 * 146 147 * @param int $post_id The post ID. 147 148 * @param int $user_id optional The post author ID. 148 149 * @return object|bool The autosaved data or false on failure or when no autosave exists. … … 393 394 return $post; 394 395 } 395 396 397 function _wp_get_post_revision_version( $post ) { 398 if ( is_array( $post ) ) { 399 if ( ! isset( $post['post_name'] ) ) { 400 return false; 401 } 402 403 $name = $post['post_name']; 404 } elseif ( is_object( $post ) ) { 405 if ( ! isset( $post->post_name ) ) { 406 return false; 407 } 408 409 $name = $post->post_name; 410 } else { 411 return false; 412 } 413 414 if ( ! preg_match( '/^([\d-]+)(?:autosave|revision)(?:-\d+)*$/', $name, $matches ) ) { 415 return false; 416 } 417 418 $parts = explode( '-', trim( $matches[1], '-' ) ); 419 420 if ( 2 !== count( $parts ) ) { 421 return 0; 422 } 423 424 return (int) $parts[1]; 425 } 426 427 function _wp_upgrade_revisions_of_post( $post ) { 428 global $wpdb; 429 430 $post = get_post( $post ); 431 if ( ! $post ) 432 return false; 433 434 if ( ! post_type_supports( $post->post_type, 'revisions' ) ) 435 return false; 436 437 $revisions = wp_get_post_revisions( $post->ID ); // array( 'order' => 'DESC', 'orderby' => 'date' ); // Always work from most recent to oldest 438 439 if ( ! $revisions ) 440 return true; 441 442 // Add post option exclusively 443 $lock = "revision-upgrade-{$post->ID}"; 444 $locked_at = time(); 445 $result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no') /* LOCK */", $lock, $locked_at ) ); 446 if ( ! $result ) { 447 // If we couldn't get a lock, see how old the previous lock is 448 $locked_at = get_option( $lock ); 449 if ( !$locked_at ) { 450 // Can't write to the lock, and can't read the lock. 451 // Something broken has happened 452 return false; 453 } 454 455 if ( $lock_at < time() - 3600 ) { 456 // Lock is too old - try again 457 delete_option( $lock ); 458 return wp_upgrade_revisions_of_post( $post ); 459 } 460 461 // Lock is not too old: some other process may be upgrading this post. Bail. 462 return; 463 } else { 464 // If we could get a lock, re-"add" the option to fire all the correct filters. 465 add_option( $lock, $locked_at ); 466 } 467 468 $success = true; 469 470 reset( $revisions ); 471 do { 472 $this_revision = current( $revisions ); 473 $prev_revision = next( $revisions ); 474 475 $this_revision_version = _wp_get_post_revision_version( $this_revision ); 476 477 // Something terrible happened 478 if ( false === $this_revision_version ) 479 continue; 480 481 // 1 is the latest revision version, so we're already up to date 482 if ( 0 < $this_revision_version ) 483 continue; 484 485 // This revision is the oldest revision of the post. 486 // The correct post_author is probably $post->post_author, but that's only a good guess. 487 // Leave un-upgraded. Will be caught by get_modified_post_author() on display. 488 if ( ! $prev_revision ) { 489 continue; 490 } 491 492 $prev_revision_version = _wp_get_post_revision_version( $prev_revision ); 493 494 // If the previous revision is already up to date, it no longer has the information we need :( 495 if ( 0 < $prev_revision_version ) { 496 continue; 497 } 498 499 // Upgrade this revision 500 501 // Cast as object so that wp_update_post() handles slashing for us 502 $update = (object) array( 503 'ID' => $this_revision->ID, 504 'post_name' => preg_replace( '/^(\d+)(?:-0)?-/', '\\1-1-', $this_revision->post_name ), 505 'post_author' => $prev_revision->post_author, 506 ); 507 508 $result = wp_update_post( $update ); 509 if ( ! $result || is_wp_error( $result ) ) { 510 // Wilhelm! 511 $success = false; 512 break; 513 } 514 } while ( $prev_revision ); 515 516 delete_option( $lock ); 517 return true; 518 } 519 520 396 521 function _show_post_preview() { 397 522 398 523 if ( isset($_GET['preview_id']) && isset($_GET['preview_nonce']) ) { -
wp-includes/author-template.php
61 61 /** 62 62 * Retrieve the author who last edited the current post. 63 63 * 64 * As of WordPress 3.6, returns the display name of the user who created the revision if called on a revision object. 65 * 64 66 * @since 2.8 65 * @uses $post The current post's DB object.66 67 * @uses get_post_meta() Retrieves the ID of the author who last edited the current post. 67 68 * @uses get_userdata() Retrieves the author's DB object. 68 69 * @uses apply_filters() Calls 'the_modified_author' hook on the author display name. 70 * 71 * @param mixed $post_id Post ID, WP_Post, or falsey to use the current post. 69 72 * @return string The author's display name. 70 73 */ 71 function get_the_modified_author() { 72 if ( $last_id = get_post_meta( get_post()->ID, '_edit_last', true) ) { 73 $last_user = get_userdata($last_id); 74 return apply_filters('the_modified_author', $last_user->display_name); 74 function get_the_modified_author( $post_id = 0 ) { 75 $post = get_post( $post_id ); 76 if ( ! $post ) 77 return; 78 79 $unknown = false; 80 81 if ( 'revision' === $post->post_type ) { 82 // _wp_get_post_revision_version() can return false 83 $revision_version = _wp_get_post_revision_version( $post ); 84 if ( false === $revision_version ) { 85 // False means something horrible happened. Just return something. 86 $modified_author_id = $post->post_author; 87 } elseif ( 0 === $revision_version ) { 88 // Set as fallback 89 $modified_author_id = $post->post_author; 90 91 $revisions = wp_get_post_revisions( $post->post_parent ); 92 reset( $revisions ); 93 do { 94 $this_revision = current( $revisions ); 95 $prev_revision = next( $revisions ); // Ordered DESC 96 97 if ( $post->ID == $this_revision->ID && $prev_revision ) { 98 $prev_revision_version = _wp_get_post_revision_version( $prev_revision ); 99 if ( 0 === $prev_revision_version ) { 100 $modified_author_id = $prev_revision->post_author; 101 } else { 102 $unknown = true; 103 } 104 break; 105 } 106 } while ( $prev_revision ); 107 } else { 108 // Everything is up to date 109 $modified_author_id = $post->post_author; 110 } 111 } else { 112 $modified_author_id = get_post_meta( $post->ID, '_edit_last', true ); 75 113 } 114 115 if ( ! $modified_author_id ) 116 return; 117 118 $modified_author = get_userdata( $modified_author_id ); 119 120 $display_name = $modified_author->display_name; 121 if ( $unknown ) { 122 $display_name = sprintf( _x( '%1$s?', 'Unknown revision author name: %1$s = display_name of best guess at author' ), $display_name ); 123 } 124 125 return apply_filters( 'the_modified_author', $display_name ); 76 126 } 77 127 78 128 /** -
wp-admin/includes/ajax-actions.php
2130 2130 2131 2131 if ( $compare_two_mode ) { 2132 2132 $compare_to_gravatar = get_avatar( $left_revision->post_author, 18 ); 2133 $compare_to_author = get_the_ author_meta( 'display_name', $left_revision->post_author);2133 $compare_to_author = get_the_modified_author( $left_revision->ID ); 2134 2134 $compare_to_date = date_i18n( $datef, strtotime( $left_revision->post_modified ) ); 2135 2135 2136 2136 $revision_from_date_author = sprintf( … … 2179 2179 2180 2180 //if we are comparing two revisions, the first 'revision' represented by the leftmost 2181 2181 //slider position is the current revision, prepend a comparison to this revision 2182 if ( $compare_two_mode ) 2182 if ( $compare_two_mode ) 2183 2183 array_unshift( $revisions, get_post( $post_id ) ); 2184 2184 2185 2185 $count = -1; 2186 2186 2187 2187 foreach ( $revisions as $revision ) : … … 2192 2192 $count++; 2193 2193 // return blank data for diffs to the left of the left handle (for right handel model) 2194 2194 // or to the right of the right handle (for left handel model) 2195 if ( ( 0 != $left_handle_at && $count <= $left_handle_at ) || 2196 ( 0 != $right_handle_at && $count > $right_handle_at )) { 2195 if ( ( 0 != $left_handle_at && $count <= $left_handle_at ) || 2196 ( 0 != $right_handle_at && $count > $right_handle_at )) { 2197 2197 $alltherevisions[] = array ( 2198 2198 'ID' => $revision->ID, 2199 2199 ); 2200 2200 2201 2201 continue; 2202 2202 } 2203 2203 2204 2204 $gravatar = get_avatar( $revision->post_author, 18 ); 2205 $author = get_the_ author_meta( 'display_name', $revision->post_author);2205 $author = get_the_modified_author( $revision->ID ); 2206 2206 $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); 2207 2207 $revision_date_author = sprintf( 2208 2208 /* translators: post revision title: 1: author avatar, 2: author name, 3: time ago, 4: date */ -
wp-admin/includes/post.php
249 249 250 250 add_meta( $post_ID ); 251 251 252 update_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );253 254 252 wp_update_post( $post_data ); 255 253 256 254 // Now that we have an ID we can fix any attachment anchor hrefs … … 565 563 566 564 add_meta( $post_ID ); 567 565 568 add_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );569 570 566 // Now that we have an ID we can fix any attachment anchor hrefs 571 567 _fix_attachment_links( $post_ID ); 572 568