Ticket #34560: 34560.8.diff
| File 34560.8.diff, 5.7 KB (added by , 10 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 220 221 require_once( ABSPATH . 'wp-admin/includes/class-wp-revisions.php' ); 222 global $wp_revisions; 223 222 224 // 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 ) ); 225 if ( $wp_revisions->revisions_count > 1 ) { 226 $publish_callback_args = array( 227 'revisions_count' => $wp_revisions->revisions_count, 228 'revision_id' => $wp_revisions->last_revision_id, 229 ); 226 230 add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', null, 'normal', 'core'); 227 231 } 228 232 } -
src/wp-admin/includes/class-wp-revisions.php
1 <?php 2 /** 3 * WP_Revisions helper class. 4 */ 5 class WP_Revisions { 6 7 /** 8 * Construct the revisions class. 9 */ 10 function __construct() { 11 global $post, $wpdb; 12 13 // Grab all the revision details we need to the Post Edit screen. 14 $this->revisions_details = $wpdb->get_results( 15 $wpdb->prepare( " 16 SELECT ID, post_author, post_date, post_date_gmt, 17 post_title, post_status, post_parent, post_modified, post_type 18 FROM $wpdb->posts 19 WHERE post_parent = %d 20 AND post_type = 'revision' 21 AND post_status = 'inherit' 22 ORDER BY post_date DESC, ID DESC", 23 $post->ID 24 ) 25 ); 26 27 // Store the total revisions count. 28 $this->revisions_count = $wpdb->num_rows; 29 30 // Store the id of the last revision. 31 $this->last_revision_id = isset( $this->revisions_details[0] ) ? $this->revisions_details[0]->ID : false; 32 } 33 34 /** 35 * The number of revisions for the current object. 36 * @var int 37 */ 38 public $revisions_count; 39 40 /** 41 * Details about the revisions. 42 * @var Array 43 */ 44 public $revisions_details; 45 46 /** 47 * The id of the last revision. 48 * @var int 49 */ 50 public $last_revision_id; 51 } 52 53 /** 54 * @global WP_Revisions $wp_revisions 55 */ 56 $GLOBALS['wp_revisions'] = new WP_Revisions; -
src/wp-includes/post-template.php
1649 1649 * @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'. 1650 1650 */ 1651 1651 function wp_post_revision_title_expanded( $revision, $link = true ) { 1652 if ( !$revision = get_post( $revision ) )1653 return $revision;1654 1652 1655 1653 if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) 1656 1654 return false; … … 1662 1660 $gravatar = get_avatar( $revision->post_author, 24 ); 1663 1661 1664 1662 $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); 1665 if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID) )1663 if ( $link && $link = admin_url( sprintf( 'revision.php?revision=%d&action=edit', $revision->ID ) ) ) 1666 1664 $date = "<a href='$link'>$date</a>"; 1667 1665 1668 1666 $revision_date_author = sprintf( … … 1710 1708 if ( ! $post = get_post( $post_id ) ) 1711 1709 return; 1712 1710 1711 if ( ! current_user_can( 'read_post', $post->ID ) ) 1712 return; 1713 1713 1714 // $args array with (parent, format, right, left, type) deprecated since 3.6 1714 1715 if ( is_array( $type ) ) { 1715 1716 $type = ! empty( $type['type'] ) ? $type['type'] : $type; … … 1716 1717 _deprecated_argument( __FUNCTION__, '3.6' ); 1717 1718 } 1718 1719 1719 if ( ! $revisions = wp_get_post_revisions( $post->ID ) ) 1720 require_once( ABSPATH . 'wp-admin/includes/class-wp-revisions.php' ); 1721 global $wp_revisions; 1722 1723 if ( ! $revisions = $wp_revisions->revisions_details ) { 1720 1724 return; 1725 } 1721 1726 1722 1727 $rows = ''; 1723 1728 foreach ( $revisions as $revision ) { 1724 if ( ! current_user_can( 'read_post', $revision->ID ) )1725 continue;1726 1727 1729 $is_autosave = wp_is_post_autosave( $revision ); 1728 1730 if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) ) 1729 1731 continue; -
src/wp-includes/revision.php
198 198 * @return WP_Post|false The autosaved data or false on failure or when no autosave exists. 199 199 */ 200 200 function wp_get_post_autosave( $post_id, $user_id = 0 ) { 201 $revisions = wp_get_post_revisions( $post_id, array( 'check_enabled' => false ) );201 global $wpdb; 202 202 203 foreach ( $revisions as $revision ) { 204 if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) { 205 if ( $user_id && $user_id != $revision->post_author ) 206 continue; 203 // Contruct the autosave query. 204 $autosave_query = " 205 SELECT * 206 FROM $wpdb->posts 207 WHERE post_parent = %d 208 AND post_type = 'revision' 209 AND post_status = 'inherit' 210 AND post_name = %s 211 AND post_author = %s 212 LIMIT 1"; 207 213 208 return $revision; 209 } 214 $autosave_details = $wpdb->get_results( 215 $wpdb->prepare( 216 $autosave_query, 217 $post_id, 218 $post_id . '-autosave-v1', 219 ( 0 !== $user_id ) ? $user_id : get_current_user_id() 220 ) 221 ); 222 223 if ( empty( $autosave_details ) ) { 224 return false; 210 225 } 211 226 212 return false;227 return $autosave_details[0]; 213 228 } 214 229 215 230 /**