Ticket #16215: 16215.8.diff
File 16215.8.diff, 15.9 KB (added by , 12 years ago) |
---|
-
wp-includes/default-filters.php
250 250 add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 ); 251 251 add_action( 'plugins_loaded', 'wp_maybe_load_embeds', 0 ); 252 252 add_action( 'shutdown', 'wp_ob_end_flush_all', 1 ); 253 add_action( 'pre_post_update', 'wp_save_post_revision', 10, 2 ); 253 add_action( 'pre_post_update', 'wp_save_post_revision', 10, 1 ); 254 add_action( 'post_updated', 'wp_save_post_revision', 10, 1 ); 254 255 add_action( 'publish_post', '_publish_post_hook', 5, 1 ); 255 256 add_action( 'transition_post_status', '_transition_post_status', 5, 3 ); 256 257 add_action( 'transition_post_status', '_update_term_count_on_transition_post_status', 10, 3 ); -
wp-includes/post-template.php
1345 1345 if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) 1346 1346 return false; 1347 1347 1348 $author = get_the_ author_meta( 'display_name', $revision->post_author);1348 $author = get_the_modified_author( $revision->ID ); 1349 1349 /* translators: revision date format, see http://php.net/date */ 1350 1350 $datef = _x( 'j F, Y @ G:i:s', 'revision date format'); 1351 1351 -
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 } … … 62 63 /** 63 64 * Saves an already existing post as a post revision. 64 65 * 65 * Typically used immediately prior to post updates. 66 * Typically used immediately prior and after post updates. 67 * Prior to update checks for old revision data (latest revision != current post before update) and adds a copy of the current post as a revision if missing 68 * After update adds a copy of the current post as a revision, so latest revision always matches current post 66 69 * 67 70 * @package WordPress 68 71 * @subpackage Post_Revisions 69 72 * @since 2.6.0 70 73 * 71 74 * @uses _wp_put_post_revision() 75 * @uses wp_first_revision_matches_current_version() 72 76 * 73 77 * @param int $post_id The ID of the post to save as a revision. 74 78 * @return mixed Null or 0 if error, new revision ID, if success. 75 79 */ 76 function wp_save_post_revision( $post_id, $new_data = null ) { 77 // We do autosaves manually with wp_create_post_autosave() 80 function wp_save_post_revision( $post_id ) { 81 //check to see if the post's first revision already matches the post data 82 //should be true before post update, _except_ for old data which 83 //doesn't include a copy of the current post data in revisions 84 if ( wp_first_revision_matches_current_version( $post_id ) ) 85 return; 86 78 87 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 79 88 return; 80 89 … … 82 91 if ( ! WP_POST_REVISIONS ) 83 92 return; 84 93 85 if ( ! $post = get_post( $post_id, ARRAY_A ) )94 if ( ! $post = get_post( $post_id, ARRAY_A ) ) 86 95 return; 87 96 88 97 if ( 'auto-draft' == $post['post_status'] ) 89 98 return; 90 99 91 if ( ! post_type_supports($post['post_type'], 'revisions') )100 if ( ! post_type_supports( $post['post_type'], 'revisions' ) ) 92 101 return; 93 102 94 // if new data is supplied, check that it is different from last saved revision, unless a plugin tells us to always save regardless 95 if ( apply_filters( 'wp_save_post_revision_check_for_changes', true, $post, $new_data ) && is_array( $new_data ) ) { 96 $post_has_changed = false; 97 foreach ( array_keys( _wp_post_revision_fields() ) as $field ) { 98 if ( normalize_whitespace( $new_data[ $field ] ) != normalize_whitespace( $post[ $field ] ) ) { 99 $post_has_changed = true; 100 break; 103 // compare the proposed update with the last stored revision, verify 104 // different, unless a plugin tells us to always save regardless 105 if ( $revisions = wp_get_post_revisions( $post_id ) ) { // grab the last revision 106 $last_revision = array_shift( $revisions ); 107 108 if ( $last_revision_array = get_post( $last_revision->ID, ARRAY_A ) ) { //if no previous revisions, save one for sure 109 110 if ( apply_filters( 'wp_save_post_revision_check_for_changes', true, $last_revision_array, $post ) && is_array( $post ) ) { 111 $post_has_changed = false; 112 113 foreach ( array_keys( _wp_post_revision_fields() ) as $field ) { 114 115 if ( normalize_whitespace( $post[ $field ] ) != normalize_whitespace( $last_revision_array[ $field ] ) ) { 116 $post_has_changed = true; 117 break; 118 119 } 120 } 121 122 //don't save revision if post unchanged 123 if( ! $post_has_changed ) 124 return; 101 125 } 102 126 } 103 //don't save revision if post unchanged104 if( ! $post_has_changed )105 return;106 127 } 107 128 108 129 $return = _wp_put_post_revision( $post ); 109 130 110 131 // WP_POST_REVISIONS = true (default), -1 111 if ( ! is_numeric( WP_POST_REVISIONS ) || WP_POST_REVISIONS < 0 )132 if ( ! is_numeric( WP_POST_REVISIONS ) || WP_POST_REVISIONS < 0 ) 112 133 return $return; 113 134 114 135 // all revisions and (possibly) one autosave 115 136 $revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) ); 116 137 117 138 // WP_POST_REVISIONS = (int) (# of autosaves to save) 118 $delete = count( $revisions) - WP_POST_REVISIONS;139 $delete = count( $revisions ) - WP_POST_REVISIONS; 119 140 120 141 if ( $delete < 1 ) 121 142 return $return; … … 123 144 $revisions = array_slice( $revisions, 0, $delete ); 124 145 125 146 for ( $i = 0; isset($revisions[$i]); $i++ ) { 126 if ( false !== strpos( $revisions[ $i]->post_name, 'autosave' ) )147 if ( false !== strpos( $revisions[ $i ]->post_name, 'autosave' ) ) 127 148 continue; 128 wp_delete_post_revision( $revisions[ $i]->ID );149 wp_delete_post_revision( $revisions[ $i ]->ID ); 129 150 } 130 151 131 152 return $return; … … 142 163 * @subpackage Post_Revisions 143 164 * @since 2.6.0 144 165 * @uses wp_get_post_revisions() 145 * 166 * 146 167 * @param int $post_id The post ID. 147 168 * @param int $user_id optional The post author ID. 148 169 * @return object|bool The autosaved data or false on failure or when no autosave exists. … … 393 414 return $post; 394 415 } 395 416 417 function _wp_get_post_revision_version( $post ) { 418 if ( is_array( $post ) ) { 419 if ( ! isset( $post['post_name'] ) ) { 420 return false; 421 } 422 423 $name = $post['post_name']; 424 } elseif ( is_object( $post ) ) { 425 if ( ! isset( $post->post_name ) ) { 426 return false; 427 } 428 429 $name = $post->post_name; 430 } else { 431 return false; 432 } 433 434 if ( ! preg_match( '/^([\d-]+)(?:autosave|revision)(?:-\d+)*$/', $name, $matches ) ) { 435 return false; 436 } 437 438 $parts = explode( '-', trim( $matches[1], '-' ) ); 439 440 if ( 2 !== count( $parts ) ) { 441 return 0; 442 } 443 444 return (int) $parts[1]; 445 } 446 447 function _wp_upgrade_revisions_of_post( $post ) { 448 global $wpdb; 449 450 $post = get_post( $post ); 451 if ( ! $post ) 452 return false; 453 454 if ( ! post_type_supports( $post->post_type, 'revisions' ) ) 455 return false; 456 457 $revisions = wp_get_post_revisions( $post->ID ); // array( 'order' => 'DESC', 'orderby' => 'date' ); // Always work from most recent to oldest 458 459 if ( ! $revisions ) 460 return true; 461 462 // Add post option exclusively 463 $lock = "revision-upgrade-{$post->ID}"; 464 $locked_at = time(); 465 $result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no') /* LOCK */", $lock, $locked_at ) ); 466 if ( ! $result ) { 467 // If we couldn't get a lock, see how old the previous lock is 468 $locked_at = get_option( $lock ); 469 if ( !$locked_at ) { 470 // Can't write to the lock, and can't read the lock. 471 // Something broken has happened 472 return false; 473 } 474 475 if ( $lock_at < time() - 3600 ) { 476 // Lock is too old - try again 477 delete_option( $lock ); 478 return wp_upgrade_revisions_of_post( $post ); 479 } 480 481 // Lock is not too old: some other process may be upgrading this post. Bail. 482 return; 483 } else { 484 // If we could get a lock, re-"add" the option to fire all the correct filters. 485 add_option( $lock, $locked_at ); 486 } 487 488 $success = true; 489 490 reset( $revisions ); 491 do { 492 $this_revision = current( $revisions ); 493 $prev_revision = next( $revisions ); 494 495 $this_revision_version = _wp_get_post_revision_version( $this_revision ); 496 497 // Something terrible happened 498 if ( false === $this_revision_version ) 499 continue; 500 501 // 1 is the latest revision version, so we're already up to date 502 if ( 0 < $this_revision_version ) 503 continue; 504 505 // This revision is the oldest revision of the post. 506 // The correct post_author is probably $post->post_author, but that's only a good guess. 507 // Leave un-upgraded. Will be caught by get_modified_post_author() on display. 508 if ( ! $prev_revision ) { 509 continue; 510 } 511 512 $prev_revision_version = _wp_get_post_revision_version( $prev_revision ); 513 514 // If the previous revision is already up to date, it no longer has the information we need :( 515 if ( 0 < $prev_revision_version ) { 516 continue; 517 } 518 519 // Upgrade this revision 520 521 // Cast as object so that wp_update_post() handles slashing for us 522 $update = (object) array( 523 'ID' => $this_revision->ID, 524 'post_name' => preg_replace( '/^(\d+)(?:-0)?-/', '\\1-1-', $this_revision->post_name ), 525 'post_author' => $prev_revision->post_author, 526 ); 527 528 $result = wp_update_post( $update ); 529 if ( ! $result || is_wp_error( $result ) ) { 530 // Wilhelm! 531 $success = false; 532 break; 533 } 534 } while ( $prev_revision ); 535 536 delete_option( $lock ); 537 return true; 538 } 539 540 396 541 function _show_post_preview() { 397 542 398 543 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
2215 2215 2216 2216 if ( $compare_two_mode ) { 2217 2217 $compare_to_gravatar = get_avatar( $left_revision->post_author, 24 ); 2218 $compare_to_author = get_the_ author_meta( 'display_name', $left_revision->post_author);2218 $compare_to_author = get_the_modified_author( $left_revision->ID ); 2219 2219 $compare_to_date = date_i18n( $datef, strtotime( $left_revision->post_modified ) ); 2220 2220 2221 2221 $revision_from_date_author = sprintf( … … 2229 2229 } 2230 2230 2231 2231 $gravatar = get_avatar( $revision->post_author, 24 ); 2232 $author = get_the_author_meta( 'display_name', $revision->post_author);2232 $author = $author = get_the_modified_author( $revision->ID ); 2233 2233 $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); 2234 2234 $revision_date_author = sprintf( 2235 2235 /* 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 -
wp-admin/js/revisions.js
479 479 ( REVAPP._right_diff >= REVAPP._revisions.length ) ? '' : REVAPP._revisions.at( REVAPP._right_diff ).get( 'revision_date_author_short' ) ); 480 480 } else { 481 481 REVAPP.addTooltip ( $( 'a.ui-slider-handle' ), 482 ( REVAPP._right_diff > = REVAPP._revisions.length ) ? '' : REVAPP._revisions.at( REVAPP._right_diff).get( 'revision_date_author_short' ) );482 ( REVAPP._right_diff > REVAPP._revisions.length ) ? '' : REVAPP._revisions.at( REVAPP._right_diff - 1 ).get( 'revision_date_author_short' ) ); 483 483 } 484 484 485 485 //