Revisions changes.
* Eliminates the bloated Revisions meta box in favor of 'Revisions: #' in the publish box. * Adds ability to compare autosave to current post, when revisions are disabled. * Makes autosaves stand out visually, including "Restore This Autosave". Also: * Adds missing capability check for restoring a revision. * When no revision matches the post's current modified time, avoid marking an autosave as 'current'. * Fixes wp_get_post_autosave() to return an autosave even when revisions are disabled. * Add 'check_enabled' arg to wp_get_post_revisions(); false avoids the wp_revisions_enabled() check. * Adds a responsive slider that is narrower for fewer versions. props markjaquith. see #24804. git-svn-id: http://core.svn.wordpress.org/trunk@24790 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
290d61138c
commit
c8fe64a602
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 );
|
||||
?>
|
||||
<div class="misc-pub-section num-revisions">
|
||||
<?php
|
||||
if ( $revisions_to_keep > 0 && $revisions_to_keep <= $args['args']['revisions_count'] ) {
|
||||
echo '<span title="' . esc_attr( sprintf( __( 'Your site is configured to keep only the last %s revisions.' ),
|
||||
number_format_i18n( $revisions_to_keep ) ) ) . '">';
|
||||
printf( __( 'Revisions: %s' ), '<b>' . number_format_i18n( $args['args']['revisions_count'] ) . '+</b>' );
|
||||
echo '</span>';
|
||||
} else {
|
||||
printf( 'Revisions: %s', '<b>' . number_format_i18n( $args['args']['revisions_count'] ) . '</b>' );
|
||||
}
|
||||
?>
|
||||
<a class="hide-if-no-js" href="<?php echo esc_url( get_edit_post_link( $args['args']['revision_id'] ) ); ?>"><?php _ex( 'Browse', 'revisions' ); ?></a>
|
||||
</div>
|
||||
<?php endif;
|
||||
|
||||
if ( $can_publish ) : // Contributors don't get to choose the date of publish ?>
|
||||
<div class="misc-pub-section curtime">
|
||||
<span id="timestamp">
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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( '<div style="' + this.direction + ': ' + ( 100 * tickWidth * index ) + '%"></div>' ); }, this );
|
||||
this.$el.append( '<div style="' + this.direction + ': ' + ( 100 * tickWidth * index ) + '%"></div>' );
|
||||
}, 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,
|
||||
|
|
|
@ -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' );
|
|||
<script id="tmpl-revisions-tooltip" type="text/html">
|
||||
<div class="author-card">
|
||||
<# if ( 'undefined' !== typeof data && 'undefined' !== typeof data.author ) { #>
|
||||
{{{ data.author.avatar }}}
|
||||
<div class="author-info">
|
||||
|
||||
<span class="byline"><?php printf( __( 'Revision by %s' ),
|
||||
'<span class="author-name">{{ data.author.name }}</span>' ); ?></span>
|
||||
<span class="time-ago">{{ data.timeAgo }}</span>
|
||||
<span class="date">({{ data.dateShort }})</span>
|
||||
</div>
|
||||
<div class="author-card<# if ( data.autosave ) { #> autosave<# } #>">
|
||||
{{{ data.author.avatar }}}
|
||||
<div class="author-info">
|
||||
<# if ( data.autosave ) { #>
|
||||
<span class="byline"><?php printf( __( 'Autosave by %s' ),
|
||||
'<span class="author-name">{{ data.author.name }}</span>' ); ?></span>
|
||||
<# } else if ( data.current ) { #>
|
||||
<span class="byline"><?php printf( __( 'Current Revision by %s' ),
|
||||
'<span class="author-name">{{ data.author.name }}</span>' ); ?></span>
|
||||
<# } else { #>
|
||||
<span class="byline"><?php printf( __( 'Revision by %s' ),
|
||||
'<span class="author-name">{{ data.author.name }}</span>' ); ?></span>
|
||||
<# } #>
|
||||
<span class="time-ago">{{ data.timeAgo }}</span>
|
||||
<span class="date">({{ data.dateShort }})</span>
|
||||
</div>
|
||||
</div>
|
||||
<# } #>
|
||||
</div>
|
||||
<div class="revisions-tooltip-arrow"><span></span></div>
|
||||
|
@ -166,11 +175,19 @@ require_once( './admin-header.php' );
|
|||
<div class="diff-title">
|
||||
<strong><?php _ex( 'From:', 'Followed by post revision info' ); ?></strong>
|
||||
<# if ( 'undefined' !== typeof data.from ) { #>
|
||||
<div class="author-card">
|
||||
<div class="author-card<# if ( data.from.attributes.autosave ) { #> autosave<# } #>">
|
||||
{{{ data.from.attributes.author.avatar }}}
|
||||
<div class="author-info">
|
||||
<# if ( data.from.attributes.autosave ) { #>
|
||||
<span class="byline"><?php printf( __( 'Autosave by %s' ),
|
||||
'<span class="author-name">{{ data.from.attributes.author.name }}</span>' ); ?></span>
|
||||
<# } else if ( data.from.attributes.current ) { #>
|
||||
<span class="byline"><?php printf( __( 'Current Revision by %s' ),
|
||||
'<span class="author-name">{{ data.from.attributes.author.name }}</span>' ); ?></span>
|
||||
<# } else { #>
|
||||
<span class="byline"><?php printf( __( 'Revision by %s' ),
|
||||
'<span class="author-name">{{ data.from.attributes.author.name }}</span>' ); ?></span>
|
||||
<# } #>
|
||||
<span class="time-ago">{{ data.from.attributes.timeAgo }}</span>
|
||||
<span class="date">({{ data.from.attributes.dateShort }})</span>
|
||||
</div>
|
||||
|
@ -183,20 +200,34 @@ require_once( './admin-header.php' );
|
|||
<div class="diff-title">
|
||||
<strong><?php _ex( 'To:', 'Followed by post revision info' ); ?></strong>
|
||||
<# if ( 'undefined' !== typeof data.to ) { #>
|
||||
<div class="author-card">
|
||||
<div class="author-card<# if ( data.to.attributes.autosave ) { #> autosave<# } #>">
|
||||
{{{ data.to.attributes.author.avatar }}}
|
||||
<div class="author-info">
|
||||
<# if ( data.to.attributes.autosave ) { #>
|
||||
<span class="byline"><?php printf( __( 'Autosave by %s' ),
|
||||
'<span class="author-name">{{ data.to.attributes.author.name }}</span>' ); ?></span>
|
||||
<# } else if ( data.to.attributes.current ) { #>
|
||||
<span class="byline"><?php printf( __( 'Current Revision by %s' ),
|
||||
'<span class="author-name">{{ data.to.attributes.author.name }}</span>' ); ?></span>
|
||||
<# } else { #>
|
||||
<span class="byline"><?php printf( __( 'Revision by %s' ),
|
||||
'<span class="author-name">{{ data.to.attributes.author.name }}</span>' ); ?></span>
|
||||
<# } #>
|
||||
<span class="time-ago">{{ data.to.attributes.timeAgo }}</span>
|
||||
<span class="date">({{ data.to.attributes.dateShort }})</span>
|
||||
</div>
|
||||
<# } #>
|
||||
<# if ( data.to.attributes.restoreUrl ) { #>
|
||||
<input
|
||||
<# if ( data.to.attributes.current ) { #>
|
||||
disabled="disabled"
|
||||
<# } #>
|
||||
type="button" class="restore-revision button button-primary" data-restore-link="{{{ data.restoreLink }}}" value="<?php esc_attr_e( 'Restore This Revision' ); ?>" />
|
||||
<# if ( data.to.attributes.autosave ) { #>
|
||||
type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Autosave' ); ?>" />
|
||||
<# } else { #>
|
||||
type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Revision' ); ?>" />
|
||||
<# } #>
|
||||
<# } #>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
|
|
|
@ -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 ) )
|
||||
|
|
Loading…
Reference in New Issue