Ticket #16215: 16215.9.diff
File 16215.9.diff, 19.3 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_upgrade_revisions_of_post', 11, 1 ); 254 add_action( 'pre_post_update', 'wp_save_post_revision', 10, 1 ); 255 add_action( 'post_updated', 'wp_save_post_revision', 10, 1 ); 254 256 add_action( 'publish_post', '_publish_post_hook', 5, 1 ); 255 257 add_action( 'transition_post_status', '_transition_post_status', 5, 3 ); 256 258 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_corrected_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 1352 $gravatar = get_avatar( $ revision->post_author, 24 );1352 $gravatar = get_avatar( $author['modified_author_id'], 24 ); 1353 1353 1354 1354 $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); 1355 1355 if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) … … 1359 1359 /* translators: post revision title: 1: author avatar, 2: author name, 3: time ago, 4: date */ 1360 1360 _x( '%1$s %2$s, %3$s ago (%4$s)', 'post revision title' ), 1361 1361 $gravatar, 1362 $author ,1362 $author['modified_author_display_name'], 1363 1363 human_time_diff( strtotime( $revision->post_modified ), current_time( 'timestamp' ) ), 1364 1364 $date 1365 1365 ); … … 1455 1455 1456 1456 } 1457 1457 1458 if ( 'form-table' == $format ) : ?>1459 1460 <form action="revision.php" method="get">1461 1462 <div class="tablenav">1463 <div class="alignleft">1464 <input type="submit" class="button-secondary" value="<?php esc_attr_e( 'Compare Revisions' ); ?>" />1465 <input type="hidden" name="action" value="diff" />1466 <input type="hidden" name="post_type" value="<?php echo esc_attr($post->post_type); ?>" />1467 </div>1468 </div>1469 1470 <br class="clear" />1471 1472 <table class="widefat post-revisions" cellspacing="0" id="post-revisions">1473 <col />1474 <col />1475 <col style="width: 33%" />1476 <col style="width: 33%" />1477 <col style="width: 33%" />1478 <thead>1479 <tr>1480 <th scope="col"><?php /* translators: column name in revisions */ _ex( 'Old', 'revisions column name' ); ?></th>1481 <th scope="col"><?php /* translators: column name in revisions */ _ex( 'New', 'revisions column name' ); ?></th>1482 <th scope="col"><?php /* translators: column name in revisions */ _ex( 'Date Created', 'revisions column name' ); ?></th>1483 <th scope="col"><?php _e( 'Author' ); ?></th>1484 <th scope="col" class="action-links"><?php _e( 'Actions' ); ?></th>1485 </tr>1486 </thead>1487 <tbody>1488 1489 <?php echo $rows; ?>1490 1491 </tbody>1492 </table>1493 1494 </form>1495 1496 <?php1497 else :1498 1458 echo "<ul class='post-revisions'>\n"; 1499 1459 echo $rows; 1500 1460 … … 1524 1484 echo "</ul>"; 1525 1485 } 1526 1486 1527 endif;1528 1529 1487 } -
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 /** 448 * Upgrade the data 449 * 450 * @package WordPress 451 * @subpackage Post_Revisions 452 * @since 3.6.0 453 * 454 * @uses get_post() 455 * @uses post_type_supports() 456 * @uses wp_get_post_revisions() 457 * 458 * @param int|object $post_id Post ID or post object 459 * @return true if success, false if problems 460 */ 461 function _wp_upgrade_revisions_of_post( $post ) { 462 global $wpdb; 463 464 $post = get_post( $post ); 465 if ( ! $post ) 466 return false; 467 468 if ( ! post_type_supports( $post->post_type, 'revisions' ) ) 469 return false; 470 471 $revisions = wp_get_post_revisions( $post->ID ); // array( 'order' => 'DESC', 'orderby' => 'date' ); // Always work from most recent to oldest 472 473 if ( ! $revisions ) 474 return true; 475 476 // Add post option exclusively 477 $lock = "revision-upgrade-{$post->ID}"; 478 $locked_at = time(); 479 $result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no') /* LOCK */", $lock, $locked_at ) ); 480 if ( ! $result ) { 481 // If we couldn't get a lock, see how old the previous lock is 482 $locked_at = get_option( $lock ); 483 if ( !$locked_at ) { 484 // Can't write to the lock, and can't read the lock. 485 // Something broken has happened 486 return false; 487 } 488 489 if ( $lock_at < time() - 3600 ) { 490 // Lock is too old - try again 491 delete_option( $lock ); 492 return wp_upgrade_revisions_of_post( $post ); 493 } 494 495 // Lock is not too old: some other process may be upgrading this post. Bail. 496 return; 497 } else { 498 // If we could get a lock, re-"add" the option to fire all the correct filters. 499 add_option( $lock, $locked_at ); 500 } 501 502 $success = true; 503 504 reset( $revisions ); 505 do { 506 $this_revision = current( $revisions ); 507 $prev_revision = next( $revisions ); 508 509 $this_revision_version = _wp_get_post_revision_version( $this_revision ); 510 511 // Something terrible happened 512 if ( false === $this_revision_version ) 513 continue; 514 515 // 1 is the latest revision version, so we're already up to date 516 if ( 0 < $this_revision_version ) 517 continue; 518 519 // This revision is the oldest revision of the post. 520 // The correct post_author is probably $post->post_author, but that's only a good guess. 521 // Leave un-upgraded. Will be caught by get_modified_post_author() on display. 522 if ( ! $prev_revision ) { 523 continue; 524 } 525 526 $prev_revision_version = _wp_get_post_revision_version( $prev_revision ); 527 528 // If the previous revision is already up to date, it no longer has the information we need :( 529 if ( 0 < $prev_revision_version ) { 530 continue; 531 } 532 533 // Upgrade this revision 534 535 // Cast as object so that wp_update_post() handles slashing for us 536 $update = (object) array( 537 'ID' => $this_revision->ID, 538 'post_name' => preg_replace( '/^(\d+)(?:-0)?-/', '\\1-1-', $this_revision->post_name ), 539 'post_author' => $prev_revision->post_author, 540 ); 541 542 $result = wp_update_post( $update ); 543 if ( ! $result || is_wp_error( $result ) ) { 544 // Wilhelm! 545 $success = false; 546 break; 547 } 548 } while ( $prev_revision ); 549 550 delete_option( $lock ); 551 return true; 552 } 553 554 396 555 function _show_post_preview() { 397 556 398 557 if ( isset($_GET['preview_id']) && isset($_GET['preview_nonce']) ) { -
wp-includes/author-template.php
76 76 } 77 77 78 78 /** 79 * Retrieve the author who last edited the current post. 80 * 81 * As of WordPress 3.6, returns the corrected display name and ID of the user who created the revision if called on a revision object. 82 * 83 * @since 3.6 84 * @uses get_post_meta() Retrieves the ID of the author who last edited the current post. 85 * @uses get_userdata() Retrieves the author's DB object. 86 * @uses apply_filters() Calls 'the_modified_author' hook on the author display name. 87 * 88 * @param mixed $post_id Post ID, WP_Post, or falsey to use the current post. 89 * @return array modified_author_display_name => The author's display name, modified_author_id => The author's user ID; empty if problems 90 */ 91 function get_the_corrected_modified_author( $post_id = 0 ) { 92 93 if ( ! $post = get_post( $post_id ) ) 94 return; 95 96 $unknown = false; 97 98 if ( 'revision' === $post->post_type ) { 99 // _wp_get_post_revision_version() can return false 100 $revision_version = _wp_get_post_revision_version( $post ); 101 if ( false === $revision_version ) { 102 // False means something horrible happened. Just return something. 103 $modified_author_id = $post->post_author; 104 } elseif ( 0 === $revision_version ) { 105 // Set as fallback 106 $modified_author_id = $post->post_author; 107 108 $revisions = wp_get_post_revisions( $post->post_parent ); 109 reset( $revisions ); 110 do { 111 $this_revision = current( $revisions ); 112 $prev_revision = next( $revisions ); // Ordered DESC 113 114 if ( $post->ID == $this_revision->ID && $prev_revision ) { 115 $prev_revision_version = _wp_get_post_revision_version( $prev_revision ); 116 if ( 0 === $prev_revision_version ) { 117 $modified_author_id = $prev_revision->post_author; 118 } else { 119 $unknown = true; 120 } 121 break; 122 } 123 } while ( $prev_revision ); 124 } else { 125 // Everything is up to date 126 $modified_author_id = $post->post_author; 127 } 128 } else { 129 $modified_author_id = get_post_meta( $post->ID, '_edit_last', true ); 130 } 131 132 if ( ! $modified_author_id ) 133 return; 134 135 $modified_author = get_userdata( $modified_author_id ); 136 137 $display_name = $modified_author->display_name; 138 if ( $unknown ) { 139 $display_name = sprintf( _x( '%1$s?', 'Unknown revision author name: %1$s = display_name of best guess at author' ), $display_name ); 140 } 141 142 $toreturn = array ( 143 'modified_author_display_name' => apply_filters( 'the_modified_author', $display_name ), 144 'modified_author_id' => $modified_author_id, 145 ); 146 147 return $toreturn; 148 } 149 150 151 152 /** 79 153 * Display the name of the author who last edited the current post. 80 154 * 81 155 * @since 2.8 -
wp-admin/includes/ajax-actions.php
2214 2214 } 2215 2215 2216 2216 if ( $compare_two_mode ) { 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);2217 $compare_to_author = get_the_corrected_modified_author( $left_revision->ID ); 2218 $compare_to_gravatar = get_avatar( $compare_to_author['modified_author_id'], 24 ); 2219 2219 $compare_to_date = date_i18n( $datef, strtotime( $left_revision->post_modified ) ); 2220 2220 2221 2221 $revision_from_date_author = sprintf( 2222 2222 /* translators: post revision title: 1: author avatar, 2: author name, 3: time ago, 4: date */ 2223 2223 _x( '%1$s %2$s, %3$s ago (%4$s)', 'post revision title' ), 2224 2224 $compare_to_gravatar, 2225 $compare_to_author ,2225 $compare_to_author['modified_author_display_name'], 2226 2226 human_time_diff( strtotime( $left_revision->post_modified ), current_time( 'timestamp' ) ), 2227 2227 $compare_to_date 2228 2228 ); 2229 2229 } 2230 2230 2231 $ gravatar = get_avatar( $revision->post_author, 24);2232 $ author = get_the_author_meta( 'display_name', $revision->post_author);2231 $author = $author = get_the_corrected_modified_author( $revision->ID ); 2232 $gravatar = get_avatar( $author['modified_author_id'], 24 ); 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 */ 2236 2236 _x( '%1$s %2$s, %3$s ago (%4$s)', 'post revision title' ), 2237 2237 $gravatar, 2238 $author ,2238 $author['modified_author_display_name'], 2239 2239 human_time_diff( strtotime( $revision->post_modified ), current_time( 'timestamp' ) ), 2240 2240 $date 2241 2241 ); … … 2262 2262 $revision_date_author_short = sprintf( 2263 2263 '%s <strong>%s</strong><br />%s', 2264 2264 $gravatar, 2265 $author ,2265 $author['modified_author_display_name'], 2266 2266 $date_short 2267 2267 ); 2268 2268 -
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 //