diff --git a/wp-admin/css/wp-admin.css b/wp-admin/css/wp-admin.css index 1397016f42..478bf0ed7d 100644 --- a/wp-admin/css/wp-admin.css +++ b/wp-admin/css/wp-admin.css @@ -3539,7 +3539,7 @@ td.plugin-title p { margin: 0 auto; height: 0.8em; top: 7px; - width: 70%; + max-width: 70%; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; @@ -3641,6 +3641,11 @@ body.folded .revisions .loading-indicator { .revisions-controls .author-card .date { color: #777; } + +.revisions-controls .author-card.autosave { + color: #d54e21; +} + .revisions-controls .author-card .author-name { font-weight: bold; } @@ -3663,8 +3668,8 @@ body.folded .revisions .loading-indicator { float: right; } -.wp-slider { - width: 70%; +.revisions-controls .wp-slider { + max-width: 70%; margin: 0 auto; top: -3px; } diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index 5f65944163..dee6450b17 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -109,13 +109,30 @@ $post_type_object = get_post_type_object($post_type); // All meta boxes should be defined and added before the first do_meta_boxes() call (or potentially during the do_meta_boxes action). require_once('./includes/meta-boxes.php'); + +$publish_callback_args = null; +if ( post_type_supports($post_type, 'revisions') && 'auto-draft' != $post->post_status ) { + $revisions = wp_get_post_revisions( $post_ID ); + + // Check if the revisions have been upgraded + if ( ! empty( $revisions ) && _wp_get_post_revision_version( end( $revisions ) ) < 1 ) + _wp_upgrade_revisions_of_post( $post, $revisions ); + + // We should aim to show the revisions metabox only when there are revisions. + if ( count( $revisions ) > 1 ) { + reset( $revisions ); // Reset pointer for key() + $publish_callback_args = array( 'revisions_count' => count( $revisions ), 'revision_id' => key( $revisions ) ); + // add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', null, 'normal', 'core'); + } +} + if ( 'attachment' == $post_type ) { wp_enqueue_script( 'image-edit' ); wp_enqueue_style( 'imgareaselect' ); add_meta_box( 'submitdiv', __('Save'), 'attachment_submit_meta_box', null, 'side', 'core' ); add_action( 'edit_form_after_title', 'edit_form_image_editor' ); } else { - add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', null, 'side', 'core' ); + add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', null, 'side', 'core', $publish_callback_args ); } if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post_type, 'post-formats' ) ) @@ -172,18 +189,6 @@ if ( post_type_supports($post_type, 'author') ) { add_meta_box('authordiv', __('Author'), 'post_author_meta_box', null, 'normal', 'core'); } -if ( post_type_supports($post_type, 'revisions') && 'auto-draft' != $post->post_status ) { - $revisions = wp_get_post_revisions( $post_ID ); - - // Check if the revisions have been upgraded - if ( ! empty( $revisions ) && _wp_get_post_revision_version( end( $revisions ) ) < 1 ) - _wp_upgrade_revisions_of_post( $post, $revisions ); - - // We should aim to show the revisions metabox only when there are revisions. - if ( count( $revisions ) > 1 ) - add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', null, 'normal', 'core'); -} - do_action('add_meta_boxes', $post_type, $post); do_action('add_meta_boxes_' . $post_type, $post); diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index e067ab07eb..9e7ec0ce5c 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -2099,7 +2099,7 @@ function wp_ajax_get_revision_diffs() { wp_send_json_error(); // Really just pre-loading the cache here. - if ( ! $revisions = wp_get_post_revisions( $post->ID ) ) + if ( ! $revisions = wp_get_post_revisions( $post->ID, array( 'check_enabled' => false ) ) ) wp_send_json_error(); $return = array(); diff --git a/wp-admin/includes/meta-boxes.php b/wp-admin/includes/meta-boxes.php index efbbc98591..01c00ceb72 100644 --- a/wp-admin/includes/meta-boxes.php +++ b/wp-admin/includes/meta-boxes.php @@ -9,7 +9,7 @@ * * @param object $post */ -function post_submit_meta_box($post) { +function post_submit_meta_box($post, $args = array() ) { global $action; $post_type = $post->post_type; @@ -171,6 +171,24 @@ if ( 0 != $post->ID ) { $date = date_i18n( $datef, strtotime( current_time('mysql') ) ); } +if ( ! empty( $args['args']['revisions_count'] ) ) : + $revisions_to_keep = wp_revisions_to_keep( $post ); +?> +
+ 0 && $revisions_to_keep <= $args['args']['revisions_count'] ) { + echo ''; + printf( __( 'Revisions: %s' ), '' . number_format_i18n( $args['args']['revisions_count'] ) . '+' ); + echo ''; + } else { + printf( 'Revisions: %s', '' . number_format_i18n( $args['args']['revisions_count'] ) . '' ); + } +?> + +
+
diff --git a/wp-admin/includes/revision.php b/wp-admin/includes/revision.php index ec9e7dc24e..51d3763e2c 100644 --- a/wp-admin/includes/revision.php +++ b/wp-admin/includes/revision.php @@ -32,9 +32,10 @@ function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) { return false; // If comparing revisions, make sure we're dealing with the right post parent. - if ( $compare_from && $compare_from->post_parent !== $post->ID ) + // The parent post may be a 'revision' when revisions are disabled and we're looking at autosaves. + if ( $compare_from && $compare_from->post_parent !== $post->ID && $compare_from->ID !== $post->ID ) return false; - if ( $compare_to->post_parent !== $post->ID ) + if ( $compare_to->post_parent !== $post->ID && $compare_to->ID !== $post->ID ) return false; if ( $compare_from && strtotime( $compare_from->post_date_gmt ) > strtotime( $compare_to->post_date_gmt ) ) { @@ -91,22 +92,35 @@ function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null $revisions = $authors = array(); $now_gmt = time(); - $revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC' ) ); + $revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC', 'check_enabled' => false ) ); + // If revisions are disabled, we only want autosaves and the current post. + if ( ! wp_revisions_enabled( $post ) ) { + foreach ( $revisions as $revision_id => $revision ) { + if ( ! wp_is_post_autosave( $revision ) ) + unset( $revisions[ $revision_id ] ); + } + $revisions = array( $post->ID => $post ) + $revisions; + } + $show_avatars = get_option( 'show_avatars' ); cache_users( wp_list_pluck( $revisions, 'post_author' ) ); + $can_restore = current_user_can( 'edit_post', $post->ID ); + foreach ( $revisions as $revision ) { $modified = strtotime( $revision->post_modified ); $modified_gmt = strtotime( $revision->post_modified_gmt ); - $restore_link = str_replace( '&', '&', wp_nonce_url( - add_query_arg( - array( 'revision' => $revision->ID, - 'action' => 'restore' ), - admin_url( 'revision.php' ) - ), - "restore-post_{$revision->ID}" - ) ); + if ( $can_restore ) { + $restore_link = str_replace( '&', '&', wp_nonce_url( + add_query_arg( + array( 'revision' => $revision->ID, + 'action' => 'restore' ), + admin_url( 'revision.php' ) + ), + "restore-post_{$revision->ID}" + ) ); + } if ( ! isset( $authors[ $revision->post_author ] ) ) { $authors[ $revision->post_author ] = array( @@ -116,9 +130,10 @@ function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ); } - $autosave = wp_is_post_autosave( $revision ); + $autosave = (bool) wp_is_post_autosave( $revision ); $current = ! $autosave && $revision->post_modified_gmt === $post->post_modified_gmt; if ( $current && ! empty( $current_id ) ) { + // If multiple revisions have the same post_modified_gmt, highest ID is current. if ( $current_id < $revision->ID ) { $revisions[ $current_id ]['current'] = false; $current_id = $revision->ID; @@ -138,14 +153,24 @@ function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null 'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( $modified_gmt, $now_gmt ) ), 'autosave' => $autosave, 'current' => $current, - 'restoreUrl' => urldecode( $restore_link ), + 'restoreUrl' => $can_restore ? $restore_link : false, ); } // If a post has been saved since the last revision (no revisioned fields were changed) // we may not have a "current" revision. Mark the latest revision as "current". - if ( empty( $current_id ) ) - $revisions[ $revision->ID ]['current'] = true; + if ( empty( $current_id ) ) { + if ( $revisions[ $revision->ID ]['autosave'] ) { + $revision = end( $revisions ); + while ( $revision['autosave'] ) { + $revision = prev( $revisions ); + } + $current_id = $revision['id']; + } else { + $current_id = $revision->ID; + } + $revisions[ $current_id ]['current'] = true; + } // Now, grab the initial diff $compare_two_mode = is_numeric( $from ); diff --git a/wp-admin/js/revisions.js b/wp-admin/js/revisions.js index 3bc5200d30..a31d429c69 100644 --- a/wp-admin/js/revisions.js +++ b/wp-admin/js/revisions.js @@ -651,9 +651,11 @@ window.wp = window.wp || {}; var tickCount, tickWidth; tickCount = this.model.revisions.length - 1; tickWidth = 1 / tickCount; + this.$el.css('width', ( this.model.revisions.length * 50 ) + 'px'); _(tickCount).times( function( index ){ - this.$el.append( '
' ); }, this ); + this.$el.append( '
' ); + }, this ); } }); @@ -831,6 +833,7 @@ window.wp = window.wp || {}; }, ready: function() { + this.$el.css('width', ( this.model.revisions.length * 50 ) + 'px'); this.$el.slider( _.extend( this.model.toJSON(), { start: this.start, slide: this.slide, diff --git a/wp-admin/revision.php b/wp-admin/revision.php index e29f710a4d..7cd79bdb49 100644 --- a/wp-admin/revision.php +++ b/wp-admin/revision.php @@ -31,7 +31,7 @@ case 'restore' : if ( ! $post = get_post( $revision->post_parent ) ) break; - // Revisions disabled (previously checked autosavegs && ! wp_is_post_autosave( $revision )) + // Revisions disabled (previously checked autosaves && ! wp_is_post_autosave( $revision )) if ( ! wp_revisions_enabled( $post ) ) { $redirect = 'edit.php?post_type=' . $post->post_type; break; @@ -133,14 +133,23 @@ require_once( './admin-header.php' ); diff --git a/wp-includes/revision.php b/wp-includes/revision.php index cd6166f9a3..5f441d3f5a 100644 --- a/wp-includes/revision.php +++ b/wp-includes/revision.php @@ -157,7 +157,7 @@ function wp_save_post_revision( $post_id ) { * @return object|bool The autosaved data or false on failure or when no autosave exists. */ function wp_get_post_autosave( $post_id, $user_id = 0 ) { - $revisions = wp_get_post_revisions($post_id); + $revisions = wp_get_post_revisions( $post_id, array( 'check_enabled' => false ) ); foreach ( $revisions as $revision ) { if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) { @@ -369,11 +369,15 @@ function wp_delete_post_revision( $revision_id ) { */ function wp_get_post_revisions( $post_id = 0, $args = null ) { $post = get_post( $post_id ); - if ( ! $post || empty( $post->ID ) || ! wp_revisions_enabled( $post ) ) + if ( ! $post || empty( $post->ID ) ) return array(); - $defaults = array( 'order' => 'DESC', 'orderby' => 'date' ); + $defaults = array( 'order' => 'DESC', 'orderby' => 'date', 'check_enabled' => true ); $args = wp_parse_args( $args, $defaults ); + + if ( $args['check_enabled'] && ! wp_revisions_enabled( $post ) ) + return array(); + $args = array_merge( $args, array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) ); if ( ! $revisions = get_children( $args ) )