2013-06-26 17:06:50 -04:00
|
|
|
<?php
|
2013-07-17 16:39:35 -04:00
|
|
|
/**
|
2013-09-12 18:59:08 -04:00
|
|
|
* WordPress Administration Revisions API
|
2013-07-17 16:39:35 -04:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Administration
|
2015-10-24 14:29:25 -04:00
|
|
|
* @since 3.6.0
|
2013-07-17 16:39:35 -04:00
|
|
|
*/
|
2013-06-26 17:06:50 -04:00
|
|
|
|
2013-07-17 16:39:35 -04:00
|
|
|
/**
|
|
|
|
* Get the revision UI diff.
|
|
|
|
*
|
2013-07-27 19:11:03 -04:00
|
|
|
* @since 3.6.0
|
|
|
|
*
|
2013-09-12 18:59:08 -04:00
|
|
|
* @param object|int $post The post object. Also accepts a post ID.
|
|
|
|
* @param int $compare_from The revision ID to compare from.
|
|
|
|
* @param int $compare_to The revision ID to come to.
|
2013-07-17 16:39:35 -04:00
|
|
|
*
|
|
|
|
* @return array|bool Associative array of a post's revisioned fields and their diffs.
|
2013-09-12 18:59:08 -04:00
|
|
|
* Or, false on failure.
|
2013-07-17 16:39:35 -04:00
|
|
|
*/
|
2013-06-26 17:06:50 -04:00
|
|
|
function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
|
2019-07-01 08:52:01 -04:00
|
|
|
$post = get_post( $post );
|
|
|
|
if ( ! $post ) {
|
2013-06-26 17:06:50 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2013-06-26 17:06:50 -04:00
|
|
|
|
|
|
|
if ( $compare_from ) {
|
2019-07-01 08:52:01 -04:00
|
|
|
$compare_from = get_post( $compare_from );
|
|
|
|
if ( ! $compare_from ) {
|
2013-06-26 17:06:50 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2013-06-26 17:06:50 -04:00
|
|
|
} else {
|
|
|
|
// If we're dealing with the first revision...
|
|
|
|
$compare_from = false;
|
|
|
|
}
|
|
|
|
|
2019-07-01 08:52:01 -04:00
|
|
|
$compare_to = get_post( $compare_to );
|
|
|
|
if ( ! $compare_to ) {
|
2013-06-26 17:06:50 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2013-06-26 17:06:50 -04:00
|
|
|
|
|
|
|
// If comparing revisions, make sure we're dealing with the right post parent.
|
2013-07-24 02:08:14 -04:00
|
|
|
// The parent post may be a 'revision' when revisions are disabled and we're looking at autosaves.
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( $compare_from && $compare_from->post_parent !== $post->ID && $compare_from->ID !== $post->ID ) {
|
2013-06-26 17:06:50 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
|
|
|
if ( $compare_to->post_parent !== $post->ID && $compare_to->ID !== $post->ID ) {
|
2013-06-26 17:06:50 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2013-06-26 17:06:50 -04:00
|
|
|
|
|
|
|
if ( $compare_from && strtotime( $compare_from->post_date_gmt ) > strtotime( $compare_to->post_date_gmt ) ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
$temp = $compare_from;
|
2013-06-26 17:06:50 -04:00
|
|
|
$compare_from = $compare_to;
|
2017-11-30 18:11:00 -05:00
|
|
|
$compare_to = $temp;
|
2013-06-26 17:06:50 -04:00
|
|
|
}
|
|
|
|
|
2013-07-06 06:48:14 -04:00
|
|
|
// Add default title if title field is empty
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( $compare_from && empty( $compare_from->post_title ) ) {
|
2013-07-06 06:48:14 -04:00
|
|
|
$compare_from->post_title = __( '(no title)' );
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
|
|
|
if ( empty( $compare_to->post_title ) ) {
|
2013-07-06 06:48:14 -04:00
|
|
|
$compare_to->post_title = __( '(no title)' );
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2013-07-06 06:48:14 -04:00
|
|
|
|
2013-06-26 17:06:50 -04:00
|
|
|
$return = array();
|
|
|
|
|
2016-02-23 19:44:59 -05:00
|
|
|
foreach ( _wp_post_revision_fields( $post ) as $field => $name ) {
|
2013-09-23 18:45:10 -04:00
|
|
|
/**
|
|
|
|
* Contextually filter a post revision field.
|
|
|
|
*
|
2014-11-30 06:28:24 -05:00
|
|
|
* The dynamic portion of the hook name, `$field`, corresponds to each of the post
|
2013-09-23 18:45:10 -04:00
|
|
|
* fields of the revision object being iterated over in a foreach statement.
|
|
|
|
*
|
|
|
|
* @since 3.6.0
|
|
|
|
*
|
|
|
|
* @param string $compare_from->$field The current revision field to compare to or from.
|
|
|
|
* @param string $field The current revision field.
|
|
|
|
* @param WP_Post $compare_from The revision post object to compare to or from.
|
2014-11-30 06:28:24 -05:00
|
|
|
* @param string null The context of whether the current revision is the old
|
|
|
|
* or the new one. Values are 'to' or 'from'.
|
2013-09-23 18:45:10 -04:00
|
|
|
*/
|
2016-08-22 14:25:31 -04:00
|
|
|
$content_from = $compare_from ? apply_filters( "_wp_post_revision_field_{$field}", $compare_from->$field, $field, $compare_from, 'from' ) : '';
|
2013-09-23 18:45:10 -04:00
|
|
|
|
2013-10-24 18:59:20 -04:00
|
|
|
/** This filter is documented in wp-admin/includes/revision.php */
|
2016-08-22 14:25:31 -04:00
|
|
|
$content_to = apply_filters( "_wp_post_revision_field_{$field}", $compare_to->$field, $field, $compare_to, 'to' );
|
2013-06-26 17:06:50 -04:00
|
|
|
|
2014-11-19 18:21:23 -05:00
|
|
|
$args = array(
|
2017-11-30 18:11:00 -05:00
|
|
|
'show_split_view' => true,
|
2014-11-19 18:21:23 -05:00
|
|
|
);
|
2014-11-20 22:50:24 -05:00
|
|
|
|
2014-11-19 18:21:23 -05:00
|
|
|
/**
|
2016-05-22 14:01:30 -04:00
|
|
|
* Filters revisions text diff options.
|
2014-11-19 18:21:23 -05:00
|
|
|
*
|
2016-05-22 14:01:30 -04:00
|
|
|
* Filters the options passed to wp_text_diff() when viewing a post revision.
|
2014-11-19 18:21:23 -05:00
|
|
|
*
|
|
|
|
* @since 4.1.0
|
|
|
|
*
|
|
|
|
* @param array $args {
|
2016-05-02 00:00:28 -04:00
|
|
|
* Associative array of options to pass to wp_text_diff().
|
2014-11-19 18:21:23 -05:00
|
|
|
*
|
2014-12-04 09:36:24 -05:00
|
|
|
* @type bool $show_split_view True for split view (two columns), false for
|
|
|
|
* un-split view (single column). Default true.
|
2014-11-19 18:21:23 -05:00
|
|
|
* }
|
|
|
|
* @param string $field The current revision field.
|
|
|
|
* @param WP_Post $compare_from The revision post to compare from.
|
|
|
|
* @param WP_Post $compare_to The revision post to compare to.
|
|
|
|
*/
|
|
|
|
$args = apply_filters( 'revision_text_diff_options', $args, $field, $compare_from, $compare_to );
|
2014-11-20 22:50:24 -05:00
|
|
|
|
2014-11-19 18:21:23 -05:00
|
|
|
$diff = wp_text_diff( $content_from, $content_to, $args );
|
2013-06-26 17:06:50 -04:00
|
|
|
|
|
|
|
if ( ! $diff && 'post_title' === $field ) {
|
|
|
|
// It's a better user experience to still show the Title, even if it didn't change.
|
|
|
|
// No, you didn't see this.
|
2018-08-16 21:51:36 -04:00
|
|
|
$diff = '<table class="diff"><colgroup><col class="content diffsplit left"><col class="content diffsplit middle"><col class="content diffsplit right"></colgroup><tbody><tr>';
|
2018-04-10 12:12:30 -04:00
|
|
|
|
|
|
|
// In split screen mode, show the title before/after side by side.
|
|
|
|
if ( true === $args['show_split_view'] ) {
|
|
|
|
$diff .= '<td>' . esc_html( $compare_from->post_title ) . '</td><td></td><td>' . esc_html( $compare_to->post_title ) . '</td>';
|
|
|
|
} else {
|
|
|
|
$diff .= '<td>' . esc_html( $compare_from->post_title ) . '</td>';
|
|
|
|
|
|
|
|
// In single column mode, only show the title once if unchanged.
|
|
|
|
if ( $compare_from->post_title !== $compare_to->post_title ) {
|
|
|
|
$diff .= '</tr><tr><td>' . esc_html( $compare_to->post_title ) . '</td>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 21:51:36 -04:00
|
|
|
$diff .= '</tr></tbody>';
|
2013-06-26 17:06:50 -04:00
|
|
|
$diff .= '</table>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $diff ) {
|
|
|
|
$return[] = array(
|
2017-11-30 18:11:00 -05:00
|
|
|
'id' => $field,
|
2013-06-26 17:06:50 -04:00
|
|
|
'name' => $name,
|
|
|
|
'diff' => $diff,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2014-10-29 15:02:21 -04:00
|
|
|
|
|
|
|
/**
|
2016-05-22 14:01:30 -04:00
|
|
|
* Filters the fields displayed in the post revision diff UI.
|
2014-10-29 15:02:21 -04:00
|
|
|
*
|
|
|
|
* @since 4.1.0
|
|
|
|
*
|
2018-03-25 14:10:32 -04:00
|
|
|
* @param array[] $return Array of revision UI fields. Each item is an array of id, name, and diff.
|
2014-10-29 15:02:21 -04:00
|
|
|
* @param WP_Post $compare_from The revision post to compare from.
|
|
|
|
* @param WP_Post $compare_to The revision post to compare to.
|
|
|
|
*/
|
|
|
|
return apply_filters( 'wp_get_revision_ui_diff', $return, $compare_from, $compare_to );
|
|
|
|
|
2013-06-26 17:06:50 -04:00
|
|
|
}
|
|
|
|
|
2013-07-17 16:39:35 -04:00
|
|
|
/**
|
|
|
|
* Prepare revisions for JavaScript.
|
|
|
|
*
|
2013-07-27 19:11:03 -04:00
|
|
|
* @since 3.6.0
|
|
|
|
*
|
2013-09-12 19:15:10 -04:00
|
|
|
* @param object|int $post The post object. Also accepts a post ID.
|
|
|
|
* @param int $selected_revision_id The selected revision ID.
|
|
|
|
* @param int $from Optional. The revision ID to compare from.
|
2013-07-17 16:39:35 -04:00
|
|
|
*
|
2013-07-17 17:09:14 -04:00
|
|
|
* @return array An associative array of revision data and related settings.
|
2013-07-17 16:39:35 -04:00
|
|
|
*/
|
2013-07-11 18:56:48 -04:00
|
|
|
function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
$post = get_post( $post );
|
2014-05-05 23:45:14 -04:00
|
|
|
$authors = array();
|
2013-07-11 16:57:47 -04:00
|
|
|
$now_gmt = time();
|
2013-06-26 17:06:50 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$revisions = wp_get_post_revisions(
|
2018-08-16 21:51:36 -04:00
|
|
|
$post->ID,
|
|
|
|
array(
|
2017-11-30 18:11:00 -05:00
|
|
|
'order' => 'ASC',
|
|
|
|
'check_enabled' => false,
|
|
|
|
)
|
|
|
|
);
|
2013-07-24 02:08:14 -04:00
|
|
|
// If revisions are disabled, we only want autosaves and the current post.
|
|
|
|
if ( ! wp_revisions_enabled( $post ) ) {
|
|
|
|
foreach ( $revisions as $revision_id => $revision ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! wp_is_post_autosave( $revision ) ) {
|
2013-07-24 02:08:14 -04:00
|
|
|
unset( $revisions[ $revision_id ] );
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2013-07-24 02:08:14 -04:00
|
|
|
}
|
|
|
|
$revisions = array( $post->ID => $post ) + $revisions;
|
|
|
|
}
|
|
|
|
|
2013-07-15 19:01:27 -04:00
|
|
|
$show_avatars = get_option( 'show_avatars' );
|
2013-06-26 17:06:50 -04:00
|
|
|
|
|
|
|
cache_users( wp_list_pluck( $revisions, 'post_author' ) );
|
|
|
|
|
2013-07-24 02:08:14 -04:00
|
|
|
$can_restore = current_user_can( 'edit_post', $post->ID );
|
2017-11-30 18:11:00 -05:00
|
|
|
$current_id = false;
|
2013-07-24 02:08:14 -04:00
|
|
|
|
2013-06-26 17:06:50 -04:00
|
|
|
foreach ( $revisions as $revision ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
$modified = strtotime( $revision->post_modified );
|
2017-09-21 19:33:44 -04:00
|
|
|
$modified_gmt = strtotime( $revision->post_modified_gmt . ' +0000' );
|
2013-07-24 02:08:14 -04:00
|
|
|
if ( $can_restore ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
$restore_link = str_replace(
|
2018-08-16 21:51:36 -04:00
|
|
|
'&',
|
|
|
|
'&',
|
|
|
|
wp_nonce_url(
|
2017-11-30 18:11:00 -05:00
|
|
|
add_query_arg(
|
|
|
|
array(
|
|
|
|
'revision' => $revision->ID,
|
|
|
|
'action' => 'restore',
|
|
|
|
),
|
2013-07-24 02:08:14 -04:00
|
|
|
admin_url( 'revision.php' )
|
2017-11-30 18:11:00 -05:00
|
|
|
),
|
|
|
|
"restore-post_{$revision->ID}"
|
|
|
|
)
|
|
|
|
);
|
2013-07-24 02:08:14 -04:00
|
|
|
}
|
2013-07-15 19:01:27 -04:00
|
|
|
|
|
|
|
if ( ! isset( $authors[ $revision->post_author ] ) ) {
|
|
|
|
$authors[ $revision->post_author ] = array(
|
2017-11-30 18:11:00 -05:00
|
|
|
'id' => (int) $revision->post_author,
|
Revisions: Pinned controls, layout tweaks, copy tweaks, misc.
* When you scroll down the diff view, the controls will pin to the top.
* The revisions meta view was cleaned up. Copy changes.
* Loading indicator in the center of the screen (so it follows as you scroll).
* Tooltips "flip" when you cross the center line, so that they don't hit the container edge and wrap for later revisions.
* The "Restore" button's inactive state is handled on render, instead of after.
* Make sure we always have a current revision, even if the timestamp doesn't work out on the most recent one.
See #24804. Props markjaquith, nacin, ocean90, aaroncampbell.
git-svn-id: http://core.svn.wordpress.org/trunk@24761 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-07-22 01:05:45 -04:00
|
|
|
'avatar' => $show_avatars ? get_avatar( $revision->post_author, 32 ) : '',
|
2017-11-30 18:11:00 -05:00
|
|
|
'name' => get_the_author_meta( 'display_name', $revision->post_author ),
|
2013-07-15 19:01:27 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-24 02:08:14 -04:00
|
|
|
$autosave = (bool) wp_is_post_autosave( $revision );
|
2017-11-30 18:11:00 -05:00
|
|
|
$current = ! $autosave && $revision->post_modified_gmt === $post->post_modified_gmt;
|
2013-07-18 10:10:33 -04:00
|
|
|
if ( $current && ! empty( $current_id ) ) {
|
2013-07-24 02:08:14 -04:00
|
|
|
// If multiple revisions have the same post_modified_gmt, highest ID is current.
|
2013-07-18 10:10:33 -04:00
|
|
|
if ( $current_id < $revision->ID ) {
|
|
|
|
$revisions[ $current_id ]['current'] = false;
|
2017-11-30 18:11:00 -05:00
|
|
|
$current_id = $revision->ID;
|
2013-07-18 10:10:33 -04:00
|
|
|
} else {
|
|
|
|
$current = false;
|
|
|
|
}
|
|
|
|
} elseif ( $current ) {
|
|
|
|
$current_id = $revision->ID;
|
|
|
|
}
|
|
|
|
|
2015-09-25 10:04:24 -04:00
|
|
|
$revisions_data = array(
|
2013-07-15 19:01:27 -04:00
|
|
|
'id' => $revision->ID,
|
|
|
|
'title' => get_the_title( $post->ID ),
|
|
|
|
'author' => $authors[ $revision->post_author ],
|
2015-03-22 22:14:27 -04:00
|
|
|
'date' => date_i18n( __( 'M j, Y @ H:i' ), $modified ),
|
|
|
|
'dateShort' => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), $modified ),
|
2013-07-15 19:01:27 -04:00
|
|
|
'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( $modified_gmt, $now_gmt ) ),
|
2013-07-18 10:10:33 -04:00
|
|
|
'autosave' => $autosave,
|
|
|
|
'current' => $current,
|
2013-07-24 02:08:14 -04:00
|
|
|
'restoreUrl' => $can_restore ? $restore_link : false,
|
2013-06-26 17:06:50 -04:00
|
|
|
);
|
2015-09-25 10:04:24 -04:00
|
|
|
|
|
|
|
/**
|
2016-05-22 14:01:30 -04:00
|
|
|
* Filters the array of revisions used on the revisions screen.
|
2015-09-25 10:04:24 -04:00
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
*
|
2015-10-05 14:03:26 -04:00
|
|
|
* @param array $revisions_data {
|
|
|
|
* The bootstrapped data for the revisions screen.
|
|
|
|
*
|
|
|
|
* @type int $id Revision ID.
|
|
|
|
* @type string $title Title for the revision's parent WP_Post object.
|
|
|
|
* @type int $author Revision post author ID.
|
|
|
|
* @type string $date Date the revision was modified.
|
|
|
|
* @type string $dateShort Short-form version of the date the revision was modified.
|
|
|
|
* @type string $timeAgo GMT-aware amount of time ago the revision was modified.
|
|
|
|
* @type bool $autosave Whether the revision is an autosave.
|
|
|
|
* @type bool $current Whether the revision is both not an autosave and the post
|
|
|
|
* modified date matches the revision modified date (GMT-aware).
|
|
|
|
* @type bool|false $restoreUrl URL if the revision can be restored, false otherwise.
|
|
|
|
* }
|
2015-10-05 14:33:28 -04:00
|
|
|
* @param WP_Post $revision The revision's WP_Post object.
|
2015-09-25 10:04:24 -04:00
|
|
|
* @param WP_Post $post The revision's parent WP_Post object.
|
|
|
|
*/
|
2015-10-05 14:33:28 -04:00
|
|
|
$revisions[ $revision->ID ] = apply_filters( 'wp_prepare_revision_for_js', $revisions_data, $revision, $post );
|
2013-06-26 17:06:50 -04:00
|
|
|
}
|
|
|
|
|
2014-11-15 22:36:23 -05:00
|
|
|
/**
|
|
|
|
* If we only have one revision, the initial revision is missing; This happens
|
|
|
|
* when we have an autsosave and the user has clicked 'View the Autosave'
|
|
|
|
*/
|
|
|
|
if ( 1 === sizeof( $revisions ) ) {
|
|
|
|
$revisions[ $post->ID ] = array(
|
|
|
|
'id' => $post->ID,
|
|
|
|
'title' => get_the_title( $post->ID ),
|
|
|
|
'author' => $authors[ $post->post_author ],
|
2015-03-22 22:14:27 -04:00
|
|
|
'date' => date_i18n( __( 'M j, Y @ H:i' ), strtotime( $post->post_modified ) ),
|
|
|
|
'dateShort' => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), strtotime( $post->post_modified ) ),
|
2014-11-15 22:36:23 -05:00
|
|
|
'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( strtotime( $post->post_modified_gmt ), $now_gmt ) ),
|
|
|
|
'autosave' => false,
|
|
|
|
'current' => true,
|
|
|
|
'restoreUrl' => false,
|
|
|
|
);
|
2017-11-30 18:11:00 -05:00
|
|
|
$current_id = $post->ID;
|
2014-11-15 22:36:23 -05:00
|
|
|
}
|
|
|
|
|
2014-07-17 05:14:16 -04:00
|
|
|
/*
|
|
|
|
* 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".
|
|
|
|
*/
|
2013-07-24 02:08:14 -04:00
|
|
|
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;
|
|
|
|
}
|
Revisions: Pinned controls, layout tweaks, copy tweaks, misc.
* When you scroll down the diff view, the controls will pin to the top.
* The revisions meta view was cleaned up. Copy changes.
* Loading indicator in the center of the screen (so it follows as you scroll).
* Tooltips "flip" when you cross the center line, so that they don't hit the container edge and wrap for later revisions.
* The "Restore" button's inactive state is handled on render, instead of after.
* Make sure we always have a current revision, even if the timestamp doesn't work out on the most recent one.
See #24804. Props markjaquith, nacin, ocean90, aaroncampbell.
git-svn-id: http://core.svn.wordpress.org/trunk@24761 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-07-22 01:05:45 -04:00
|
|
|
|
2014-07-17 05:14:16 -04:00
|
|
|
// Now, grab the initial diff.
|
2013-07-12 10:01:39 -04:00
|
|
|
$compare_two_mode = is_numeric( $from );
|
|
|
|
if ( ! $compare_two_mode ) {
|
2013-07-29 13:26:03 -04:00
|
|
|
$found = array_search( $selected_revision_id, array_keys( $revisions ) );
|
2013-07-29 13:53:24 -04:00
|
|
|
if ( $found ) {
|
|
|
|
$from = array_keys( array_slice( $revisions, $found - 1, 1, true ) );
|
|
|
|
$from = reset( $from );
|
|
|
|
} else {
|
2013-07-29 13:26:03 -04:00
|
|
|
$from = 0;
|
2013-07-29 13:53:24 -04:00
|
|
|
}
|
2013-07-12 10:01:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$from = absint( $from );
|
2013-07-12 01:11:56 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$diffs = array(
|
|
|
|
array(
|
|
|
|
'id' => $from . ':' . $selected_revision_id,
|
|
|
|
'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ),
|
|
|
|
),
|
|
|
|
);
|
2013-07-11 18:56:48 -04:00
|
|
|
|
2013-06-26 17:06:50 -04:00
|
|
|
return array(
|
2017-11-30 18:11:00 -05:00
|
|
|
'postId' => $post->ID,
|
|
|
|
'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ),
|
|
|
|
'revisionData' => array_values( $revisions ),
|
|
|
|
'to' => $selected_revision_id,
|
|
|
|
'from' => $from,
|
|
|
|
'diffData' => $diffs,
|
|
|
|
'baseUrl' => parse_url( admin_url( 'revision.php' ), PHP_URL_PATH ),
|
|
|
|
'compareTwoMode' => absint( $compare_two_mode ), // Apparently booleans are not allowed
|
|
|
|
'revisionIds' => array_keys( $revisions ),
|
2013-06-26 17:06:50 -04:00
|
|
|
);
|
2013-06-29 13:45:02 -04:00
|
|
|
}
|
2014-10-31 20:15:24 -04:00
|
|
|
|
|
|
|
/**
|
2014-12-01 19:31:22 -05:00
|
|
|
* Print JavaScript templates required for the revisions experience.
|
2014-10-31 20:15:24 -04:00
|
|
|
*
|
|
|
|
* @since 4.1.0
|
2014-11-28 04:05:23 -05:00
|
|
|
*
|
2019-08-04 08:28:56 -04:00
|
|
|
* @global WP_Post $post Global post object.
|
2014-10-31 20:15:24 -04:00
|
|
|
*/
|
|
|
|
function wp_print_revision_templates() {
|
|
|
|
global $post;
|
|
|
|
?><script id="tmpl-revisions-frame" type="text/html">
|
|
|
|
<div class="revisions-control-frame"></div>
|
|
|
|
<div class="revisions-diff-frame"></div>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script id="tmpl-revisions-buttons" type="text/html">
|
|
|
|
<div class="revisions-previous">
|
|
|
|
<input class="button" type="button" value="<?php echo esc_attr_x( 'Previous', 'Button label for a previous revision' ); ?>" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="revisions-next">
|
|
|
|
<input class="button" type="button" value="<?php echo esc_attr_x( 'Next', 'Button label for a next revision' ); ?>" />
|
|
|
|
</div>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script id="tmpl-revisions-checkbox" type="text/html">
|
|
|
|
<div class="revision-toggle-compare-mode">
|
|
|
|
<label>
|
|
|
|
<input type="checkbox" class="compare-two-revisions"
|
|
|
|
<#
|
|
|
|
if ( 'undefined' !== typeof data && data.model.attributes.compareTwoMode ) {
|
|
|
|
#> checked="checked"<#
|
|
|
|
}
|
|
|
|
#>
|
|
|
|
/>
|
2016-08-28 14:06:30 -04:00
|
|
|
<?php esc_html_e( 'Compare any two revisions' ); ?>
|
2014-10-31 20:15:24 -04:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script id="tmpl-revisions-meta" type="text/html">
|
|
|
|
<# if ( ! _.isUndefined( data.attributes ) ) { #>
|
|
|
|
<div class="diff-title">
|
|
|
|
<# if ( 'from' === data.type ) { #>
|
|
|
|
<strong><?php _ex( 'From:', 'Followed by post revision info' ); ?></strong>
|
|
|
|
<# } else if ( 'to' === data.type ) { #>
|
|
|
|
<strong><?php _ex( 'To:', 'Followed by post revision info' ); ?></strong>
|
|
|
|
<# } #>
|
|
|
|
<div class="author-card<# if ( data.attributes.autosave ) { #> autosave<# } #>">
|
|
|
|
{{{ data.attributes.author.avatar }}}
|
|
|
|
<div class="author-info">
|
|
|
|
<# if ( data.attributes.autosave ) { #>
|
2017-11-30 18:11:00 -05:00
|
|
|
<span class="byline">
|
|
|
|
<?php
|
|
|
|
printf(
|
|
|
|
__( 'Autosave by %s' ),
|
|
|
|
'<span class="author-name">{{ data.attributes.author.name }}</span>'
|
|
|
|
);
|
2018-08-16 21:51:36 -04:00
|
|
|
?>
|
2017-11-30 18:11:00 -05:00
|
|
|
</span>
|
2014-10-31 20:15:24 -04:00
|
|
|
<# } else if ( data.attributes.current ) { #>
|
2017-11-30 18:11:00 -05:00
|
|
|
<span class="byline">
|
|
|
|
<?php
|
|
|
|
printf(
|
|
|
|
__( 'Current Revision by %s' ),
|
|
|
|
'<span class="author-name">{{ data.attributes.author.name }}</span>'
|
|
|
|
);
|
2018-08-16 21:51:36 -04:00
|
|
|
?>
|
2017-11-30 18:11:00 -05:00
|
|
|
</span>
|
2014-10-31 20:15:24 -04:00
|
|
|
<# } else { #>
|
2017-11-30 18:11:00 -05:00
|
|
|
<span class="byline">
|
|
|
|
<?php
|
|
|
|
printf(
|
|
|
|
__( 'Revision by %s' ),
|
|
|
|
'<span class="author-name">{{ data.attributes.author.name }}</span>'
|
|
|
|
);
|
2018-08-16 21:51:36 -04:00
|
|
|
?>
|
2017-11-30 18:11:00 -05:00
|
|
|
</span>
|
2014-10-31 20:15:24 -04:00
|
|
|
<# } #>
|
|
|
|
<span class="time-ago">{{ data.attributes.timeAgo }}</span>
|
|
|
|
<span class="date">({{ data.attributes.dateShort }})</span>
|
|
|
|
</div>
|
|
|
|
<# if ( 'to' === data.type && data.attributes.restoreUrl ) { #>
|
|
|
|
<input <?php if ( wp_check_post_lock( $post->ID ) ) { ?>
|
|
|
|
disabled="disabled"
|
|
|
|
<?php } else { ?>
|
|
|
|
<# if ( data.attributes.current ) { #>
|
|
|
|
disabled="disabled"
|
|
|
|
<# } #>
|
|
|
|
<?php } ?>
|
|
|
|
<# if ( data.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>
|
|
|
|
<# if ( 'tooltip' === data.type ) { #>
|
|
|
|
<div class="revisions-tooltip-arrow"><span></span></div>
|
|
|
|
<# } #>
|
|
|
|
<# } #>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script id="tmpl-revisions-diff" type="text/html">
|
|
|
|
<div class="loading-indicator"><span class="spinner"></span></div>
|
|
|
|
<div class="diff-error"><?php _e( 'Sorry, something went wrong. The requested comparison could not be loaded.' ); ?></div>
|
|
|
|
<div class="diff">
|
|
|
|
<# _.each( data.fields, function( field ) { #>
|
|
|
|
<h3>{{ field.name }}</h3>
|
|
|
|
{{{ field.diff }}}
|
|
|
|
<# }); #>
|
|
|
|
</div>
|
2017-11-30 18:11:00 -05:00
|
|
|
</script>
|
|
|
|
<?php
|
2016-08-28 14:06:30 -04:00
|
|
|
}
|