Revisions: UI Update.

* Refines the UI to make it clearer and easier to use
* Introduces weighted tickmarks
* Fixes comparison bugs.

See #23497 props adamsilverstein


git-svn-id: http://core.svn.wordpress.org/trunk@23769 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Westwood
2013-03-21 15:54:11 +00:00
parent ebdcf967a3
commit 9d6988a221
9 changed files with 835 additions and 282 deletions

View File

@@ -1744,3 +1744,69 @@ function wp_text_diff( $left_string, $right_string, $args = null ) {
return $r;
}
endif;
if ( !function_exists( 'wp_text_diff_with_count' ) ) :
/**
* Displays a human readable HTML representation of the difference between two strings.
* similar to wp_text_diff, but tracks and returns could of lines added and removed
*
* @since 3.6
* @see wp_parse_args() Used to change defaults to user defined settings.
* @uses Text_Diff
* @uses WP_Text_Diff_Renderer_Table
*
* @param string $left_string "old" (left) version of string
* @param string $right_string "new" (right) version of string
* @param string|array $args Optional. Change 'title', 'title_left', and 'title_right' defaults.
* @return array contains html, linesadded & linesdeletd, empty string if strings are equivalent.
*/
function wp_text_diff_with_count( $left_string, $right_string, $args = null ) {
$defaults = array( 'title' => '', 'title_left' => '', 'title_right' => '' );
$args = wp_parse_args( $args, $defaults );
if ( !class_exists( 'WP_Text_Diff_Renderer_Table' ) )
require( ABSPATH . WPINC . '/wp-diff.php' );
$left_string = normalize_whitespace( $left_string );
$right_string = normalize_whitespace( $right_string );
$left_lines = explode( "\n", $left_string );
$right_lines = explode( "\n", $right_string) ;
$text_diff = new Text_Diff($left_lines, $right_lines );
$linesadded = $text_diff->countAddedLines();
$linesdeleted = $text_diff->countDeletedLines();
$renderer = new WP_Text_Diff_Renderer_Table();
$diff = $renderer->render( $text_diff );
if ( !$diff )
return '';
$r = "<table class='diff'>\n";
if ( ! empty( $args[ 'show_split_view' ] ) ) {
$r .= "<col class='content diffsplit left' /><col class='content diffsplit middle' /><col class='content diffsplit right' />";
} else {
$r .= "<col class='content' />";
}
if ( $args['title'] || $args['title_left'] || $args['title_right'] )
$r .= "<thead>";
if ( $args['title'] )
$r .= "<tr class='diff-title'><th colspan='4'>$args[title]</th></tr>\n";
if ( $args['title_left'] || $args['title_right'] ) {
$r .= "<tr class='diff-sub-title'>\n";
$r .= "\t<td></td><th>$args[title_left]</th>\n";
$r .= "\t<td></td><th>$args[title_right]</th>\n";
$r .= "</tr>\n";
}
if ( $args['title'] || $args['title_left'] || $args['title_right'] )
$r .= "</thead>\n";
$r .= "<tbody>\n$diff\n</tbody>\n";
$r .= "</table>";
return array( 'html' => $r, 'linesadded' => $linesadded, 'linesdeleted' => $linesdeleted );
}
endif;

View File

@@ -1306,11 +1306,50 @@ function wp_post_revision_title( $revision, $link = true ) {
if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) )
return false;
/* translators: revision date format, see http://php.net/date */
$datef = _x( 'j F, Y @ G:i', 'revision date format');
/* translators: 1: date */
$autosavef = __( '%1$s [Autosave]' );
/* translators: 1: date */
$currentf = __( '%1$s [Current Revision]' );
$date = date_i18n( $datef, strtotime( $revision->post_modified ) );
if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
$date = "<a href='$link'>$date</a>";
if ( !wp_is_post_revision( $revision ) )
$date = sprintf( $currentf, $date );
elseif ( wp_is_post_autosave( $revision ) )
$date = sprintf( $autosavef, $date );
return $date;
}
/**
* Retrieve formatted date timestamp of a revision (linked to that revisions's page).
*
* @package WordPress
* @subpackage Post_Revisions
* @since 3.6.0
*
* @uses date_i18n()
*
* @param int|object $revision Revision ID or revision object.
* @param bool $link Optional, default is true. Link to revisions's page?
* @return string gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'.
*/
function wp_post_revision_title_expanded( $revision, $link = true ) {
if ( !$revision = get_post( $revision ) )
return $revision;
if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) )
return false;
$author = get_the_author_meta( 'display_name', $revision->post_author );
/* translators: revision date format, see http://php.net/date */
$datef = _x( 'j F, Y @ G:i:s', 'revision date format');
$gravatar = get_avatar( $revision->post_author, 18 );
$gravatar = get_avatar( $revision->post_author, 24 );
$date = date_i18n( $datef, strtotime( $revision->post_modified ) );
if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
@@ -1388,11 +1427,18 @@ function wp_list_post_revisions( $post_id = 0, $args = null ) {
}
/* translators: post revision: 1: when, 2: author name */
$titlef = _x( '%1$s by %2$s', 'post revision' );
$titlef = _x( '%1$s', 'post revision' );
if ( $parent )
array_unshift( $revisions, $post );
// since 3.6 revisions include a copy of the current post data as a revision
// the collowing removes this current revision if present from the list of
// revisions returned by wp_list_post_revisions, remove these to include the
// crrent post revision in the list of revisions
if ( wp_first_revision_matches_current_version( $post_id ) )
array_pop( $revisions );
$rows = $right_checked = '';
$class = false;
$can_edit_post = current_user_can( 'edit_post', $post->ID );
@@ -1402,34 +1448,11 @@ function wp_list_post_revisions( $post_id = 0, $args = null ) {
if ( 'revision' === $type && wp_is_post_autosave( $revision ) )
continue;
$date = wp_post_revision_title( $revision );
$name = get_the_author_meta( 'display_name', $revision->post_author );
$date = wp_post_revision_title_expanded( $revision );
if ( 'form-table' == $format ) {
if ( $left )
$left_checked = $left == $revision->ID ? ' checked="checked"' : '';
else
$left_checked = $right_checked ? ' checked="checked"' : ''; // [sic] (the next one)
$right_checked = $right == $revision->ID ? ' checked="checked"' : '';
$title = sprintf( $titlef, $date );
$rows .= "\t<li>$title</li>\n";
$class = $class ? '' : " class='alternate'";
if ( $post->ID != $revision->ID && $can_edit_post )
$actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'action' => 'restore' ) ), "restore-post_$post->ID|$revision->ID" ) . '">' . __( 'Restore' ) . '</a>';
else
$actions = '';
$rows .= "<tr$class>\n";
$rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='$revision->ID'$left_checked /></th>\n";
$rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='right' value='$revision->ID'$right_checked /></th>\n";
$rows .= "\t<td>$date</td>\n";
$rows .= "\t<td>$name</td>\n";
$rows .= "\t<td class='action-links'>$actions</td>\n";
$rows .= "</tr>\n";
} else {
$title = sprintf( $titlef, $date, $name );
$rows .= "\t<li>$title</li>\n";
}
}
if ( 'form-table' == $format ) : ?>
@@ -1479,27 +1502,27 @@ function wp_list_post_revisions( $post_id = 0, $args = null ) {
// if the post was previously restored from a revision
// show the restore event details
//
if ( $restored_from_meta = get_post_meta( $post->ID, '_post_restored_from', true ) ) {
$author = get_the_author_meta( 'display_name', $restored_from_meta[ 'restored_by_user' ] );
/* translators: revision date format, see http://php.net/date */
$datef = _x( 'j F, Y @ G:i:s', 'revision date format');
$date = date_i18n( $datef, strtotime( $restored_from_meta[ 'restored_time' ] ) );
$timesince = human_time_diff( $restored_from_meta[ 'restored_time' ], current_time( 'timestamp' ) );
?>
if ( $restored_from_meta = get_post_meta( $post->ID, '_post_restored_from', true ) ) {
$author = get_the_author_meta( 'display_name', $restored_from_meta[ 'restored_by_user' ] );
/* translators: revision date format, see http://php.net/date */
$datef = _x( 'j F, Y @ G:i:s', 'revision date format');
$date = date_i18n( $datef, strtotime( $restored_from_meta[ 'restored_time' ] ) );
$timesince = human_time_diff( $restored_from_meta[ 'restored_time' ], current_time( 'timestamp' ) ) ;
?>
<hr />
<div id="revisions-meta-restored">
<?php
<div id="revisions-meta-restored">
<?php
/* translators: restored revision details: 1: revision ID, 2: time ago, 3: author name, 4: date */
printf( _x( 'Previously restored from revision ID %1$d, %2$s ago by %3$s (%4$s)', 'restored revision details' ),
$restored_from_meta[ 'restored_revision_id'],
$timesince,
$author,
$date );
?>
</div>
<?php
printf( _x( 'Previously restored from revision ID %1$d, %2$s ago by %3$s (%4$s)', 'restored revision details' ),
$restored_from_meta[ 'restored_revision_id'],
$timesince,
$author,
$date );
?>
</div>
<?php
echo "</ul>";
}
}
endif;

View File

@@ -404,3 +404,29 @@ function _show_post_preview() {
add_filter('the_preview', '_set_preview');
}
}
/**
* Determines if the specified post's most recent revision matches the post (by checking post_modified).
*
* @package WordPress
* @subpackage Post_Revisions
* @since 3.6.0
*
* @param int|object $post Post ID or post object.
* @return bool false if not a match, otherwise true.
*/
function wp_first_revision_matches_current_version( $post ) {
if ( ! $post = get_post( $post ) )
return false;
if ( ! $revisions = wp_get_post_revisions( $post->ID ) )
return false;
$last_revision = array_shift( $revisions );
if ( ! ($last_revision->post_modified == $post->post_modified ) )
return false;
return true;
}

View File

@@ -273,7 +273,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'template', "/wp-includes/js/template$suffix.js", array('underscore'), '1.4.4', 1 );
$scripts->add( 'backbone', '/wp-includes/js/backbone.min.js', array('underscore','jquery', 'template'), '0.9.10', 1 );
$scripts->add( 'revisions', "/wp-admin/js/revisions$suffix.js", array( 'backbone', 'jquery-ui-slider' ), false, 1 );
$scripts->add( 'revisions', "/wp-admin/js/revisions$suffix.js", array( 'backbone', 'jquery-ui-slider', 'jquery-ui-tooltip' ), false, 1 );
$scripts->add( 'imgareaselect', "/wp-includes/js/imgareaselect/jquery.imgareaselect$suffix.js", array('jquery'), '0.9.8', 1 );