Ticket #34560: 34560.10.diff
| File 34560.10.diff, 6.4 KB (added by , 10 years ago) |
|---|
-
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 222 require_once( ABSPATH . 'wp-admin/includes/class-wp-revisions.php' ); 223 $wp_revisions = WP_PostRevisions::getInstance( $post->ID ); 224 222 225 // 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 ) ); 226 if ( $wp_revisions->revisions_count > 1 ) { 227 $publish_callback_args = array( 228 'revisions_count' => $wp_revisions->revisions_count, 229 'revision_id' => $wp_revisions->last_revision_id, 230 ); 226 231 add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', null, 'normal', 'core'); 227 232 } 228 233 } -
wp-admin/includes/class-wp-revisions.php
1 <?php 2 /** 3 * WP_Revisions helper class. 4 */ 5 class WP_PostRevisions { 6 7 8 /** 9 * WP_PostRevisions constructor. 10 * @param $post_id - ID of the post in question 11 * 12 * Keep the constructor hidden from public so it's only initialized as intended. 13 */ 14 protected function __construct( $post_id ) { 15 $this->revisions_details = false; 16 $this->revisions_count = 0; 17 $this->last_revision_id = false; 18 $this->init( $post_id ); 19 } 20 21 protected static $last_init_id = null; 22 protected static $last_instance = null; 23 24 public static function getInstance( $post_id ) { 25 if ( (self::$last_init_id === $post_id) && ( self::$last_instance instanceof WP_PostRevisions) ) { 26 return self::$last_instance; 27 } 28 self::$last_init_id = $post_id; 29 self::$last_instance = new WP_PostRevisions( $post_id ); 30 31 return self::$last_instance; 32 } 33 34 /** 35 * Initialize this instance of the revisions class 36 * @param $post_id 37 */ 38 public function init( $post_id ) { 39 global $wpdb; 40 41 // Grab all the revision details we need to the Post Edit screen. 42 $this->revisions_details = $wpdb->get_results( 43 $wpdb->prepare( " 44 SELECT ID, post_author, post_date, post_date_gmt, 45 post_title, post_status, post_parent, post_modified, post_type 46 FROM $wpdb->posts 47 WHERE post_parent = %d 48 AND post_type = 'revision' 49 AND post_status = 'inherit' 50 ORDER BY post_date DESC, ID DESC", 51 $post_id 52 ) 53 ); 54 55 // Store the total revisions count. 56 $this->revisions_count = $wpdb->num_rows; 57 58 // Store the id of the last revision. 59 $this->last_revision_id = isset( $this->revisions_details[0] ) ? $this->revisions_details[0]->ID : false; 60 } 61 62 /** 63 * The number of revisions for the current object. 64 * @var int 65 */ 66 public $revisions_count; 67 68 /** 69 * Details about the revisions. 70 * @var Array 71 */ 72 public $revisions_details; 73 74 /** 75 * The id of the last revision. 76 * @var int 77 */ 78 public $last_revision_id; 79 } 80 81 -
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 $wp_revisions = WP_PostRevisions::getInstance( $post->ID ); 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; -
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 /**