Ticket #34560: 34560.13.diff
| File 34560.13.diff, 6.1 KB (added by , 9 years ago) |
|---|
-
src/wp-admin/edit-form-advanced.php
217 217 218 218 $publish_callback_args = null; 219 219 if ( post_type_supports($post_type, 'revisions') && 'auto-draft' != $post->post_status ) { 220 $revisions = wp_get_post_revisions( $post_ID );221 222 220 // We should aim to show the revisions metabox only when there are revisions. 223 if ( count( $revisions ) > 1 ) { 224 reset( $revisions ); // Reset pointer for key() 225 $publish_callback_args = array( 'revisions_count' => count( $revisions ), 'revision_id' => key( $revisions ) ); 221 $revision_count = wp_get_post_revision_count( $post->ID ); 222 if ( $revision_count > 1 ) { 223 $last_revision = wp_get_last_revision_id( $post->ID ); 224 $publish_callback_args = array( 225 'revisions_count' => $revision_count, 226 'revision_id' => $last_revision, 227 ); 226 228 add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', null, 'normal', 'core'); 227 229 } 228 230 } -
src/wp-includes/post-template.php
1660 1660 * @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'. 1661 1661 */ 1662 1662 function wp_post_revision_title_expanded( $revision, $link = true ) { 1663 if ( !$revision = get_post( $revision ) )1664 return $revision;1665 1663 1666 1664 if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) 1667 1665 return false; … … 1673 1671 $gravatar = get_avatar( $revision->post_author, 24 ); 1674 1672 1675 1673 $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); 1676 if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID) )1674 if ( $link && $link = admin_url( sprintf( 'revision.php?revision=%d&action=edit', $revision->ID ) ) ) 1677 1675 $date = "<a href='$link'>$date</a>"; 1678 1676 1679 1677 $revision_date_author = sprintf( … … 1721 1719 if ( ! $post = get_post( $post_id ) ) 1722 1720 return; 1723 1721 1722 if ( ! current_user_can( 'read_post', $post->ID ) ) 1723 return; 1724 1724 1725 // $args array with (parent, format, right, left, type) deprecated since 3.6 1725 1726 if ( is_array( $type ) ) { 1726 1727 $type = ! empty( $type['type'] ) ? $type['type'] : $type; … … 1727 1728 _deprecated_argument( __FUNCTION__, '3.6' ); 1728 1729 } 1729 1730 1730 if ( ! $revisions = wp_get_post_revisions ( $post->ID ) )1731 if ( ! $revisions = wp_get_post_revisions_details( $post->ID ) ) 1731 1732 return; 1732 1733 1733 1734 $rows = ''; 1734 1735 foreach ( $revisions as $revision ) { 1735 if ( ! current_user_can( 'read_post', $revision->ID ) )1736 continue;1737 1738 1736 $is_autosave = wp_is_post_autosave( $revision ); 1739 1737 if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) ) 1740 1738 continue; -
src/wp-includes/revision.php
225 225 * @return WP_Post|false The autosaved data or false on failure or when no autosave exists. 226 226 */ 227 227 function wp_get_post_autosave( $post_id, $user_id = 0 ) { 228 $revisions = wp_get_post_revisions( $post_id, array( 'check_enabled' => false ) );228 global $wpdb; 229 229 230 foreach ( $revisions as $revision ) { 231 if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) { 232 if ( $user_id && $user_id != $revision->post_author ) 233 continue; 230 // Contruct the autosave query. 231 $autosave_query = " 232 SELECT * 233 FROM $wpdb->posts 234 WHERE post_parent = %d 235 AND post_type = 'revision' 236 AND post_status = 'inherit' 237 AND post_name = %s 238 AND post_author = %s 239 LIMIT 1"; 234 240 235 return $revision; 236 } 241 $autosave_details = $wpdb->get_results( 242 $wpdb->prepare( 243 $autosave_query, 244 $post_id, 245 $post_id . '-autosave-v1', 246 ( 0 !== $user_id ) ? $user_id : get_current_user_id() 247 ) 248 ); 249 250 if ( empty( $autosave_details ) ) { 251 return false; 237 252 } 238 253 239 return false;254 return $autosave_details[0]; 240 255 } 241 256 242 257 /** … … 456 471 } 457 472 458 473 /** 474 * Returns the revision details of specified post. 475 * 476 * Data includes details about each revision on a post. Includes ID, post_author, 477 * post_date, post_date_gmt, post_title, post_status, post_parent, and post_modified. 478 * 479 * @since 4.5.0 480 * 481 * @param int $post_id The post id. 482 * @return array An array of revision details. 483 */ 484 function wp_get_post_revisions_details( $post_id ) { 485 global $wpdb; 486 487 $revision_details = $wpdb->get_results( 488 $wpdb->prepare( " 489 SELECT ID, post_author, post_date, post_date_gmt, 490 post_title, post_status, post_parent, post_modified, post_type 491 FROM $wpdb->posts 492 WHERE post_parent = %d 493 AND post_type = 'revision' 494 AND post_status = 'inherit' 495 ORDER BY post_date DESC, ID DESC", 496 $post_id 497 ) 498 ); 499 500 return $revision_details; 501 } 502 503 /** 504 * Returns the count of revisions for a given post. 505 * 506 * @since 4.5.0 507 * 508 * @param int $post_id The post id. 509 * @return int The count of revisions for this post. 510 */ 511 function wp_get_post_revision_count( $post_id ) { 512 global $wpdb; 513 514 $revision_count = $wpdb->get_row( 515 $wpdb->prepare( " 516 SELECT COUNT(*) as count 517 FROM $wpdb->posts 518 WHERE post_parent = %d 519 AND post_type = 'revision' 520 AND post_status = 'inherit'", 521 $post_id 522 ) 523 ); 524 return intval( $revision_count->count ); 525 } 526 527 /** 528 * Returns the id of the last stored revision. 529 * 530 * @since 4.5.0 531 * 532 * @param int $post_id The post id. 533 * @return int The id of the last stored revision for this post. 534 */ 535 function wp_get_last_revision_id( $post_id ) { 536 global $wpdb; 537 538 $last_revision_id = intval( 539 $wpdb->get_var( 540 $wpdb->prepare( " 541 SELECT ID, post_date 542 FROM $wpdb->posts 543 WHERE post_parent = %d 544 AND post_type = 'revision' 545 AND post_status = 'inherit' 546 ORDER BY post_date DESC, ID DESC 547 LIMIT 1", 548 $post_id 549 ) 550 ) 551 ); 552 return $last_revision_id; 553 } 554 555 /** 459 556 * Determine if revisions are enabled for a given post. 460 557 * 461 558 * @since 3.6.0