2013-06-26 23:06:50 +02:00
|
|
|
<?php
|
2013-07-17 22:39:35 +02:00
|
|
|
/**
|
2013-09-13 00:59:08 +02:00
|
|
|
* WordPress Administration Revisions API
|
2013-07-17 22:39:35 +02:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Administration
|
2015-10-24 20:29:25 +02:00
|
|
|
* @since 3.6.0
|
2013-07-17 22:39:35 +02:00
|
|
|
*/
|
2013-06-26 23:06:50 +02:00
|
|
|
|
2013-07-17 22:39:35 +02:00
|
|
|
/**
|
|
|
|
* Get the revision UI diff.
|
|
|
|
*
|
2013-07-28 01:11:03 +02:00
|
|
|
* @since 3.6.0
|
|
|
|
*
|
2019-12-06 23:43:04 +01:00
|
|
|
* @param WP_Post|int $post The post object or post ID.
|
|
|
|
* @param int $compare_from The revision ID to compare from.
|
|
|
|
* @param int $compare_to The revision ID to come to.
|
2021-01-03 23:04:04 +01:00
|
|
|
* @return array|false Associative array of a post's revisioned fields and their diffs.
|
2021-12-07 13:20:02 +01:00
|
|
|
* Or, false on failure.
|
2013-07-17 22:39:35 +02:00
|
|
|
*/
|
2013-06-26 23:06:50 +02:00
|
|
|
function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
|
2019-07-01 14:52:01 +02:00
|
|
|
$post = get_post( $post );
|
|
|
|
if ( ! $post ) {
|
2013-06-26 23:06:50 +02:00
|
|
|
return false;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2013-06-26 23:06:50 +02:00
|
|
|
|
|
|
|
if ( $compare_from ) {
|
2019-07-01 14:52:01 +02:00
|
|
|
$compare_from = get_post( $compare_from );
|
|
|
|
if ( ! $compare_from ) {
|
2013-06-26 23:06:50 +02:00
|
|
|
return false;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2013-06-26 23:06:50 +02:00
|
|
|
} else {
|
|
|
|
// If we're dealing with the first revision...
|
|
|
|
$compare_from = false;
|
|
|
|
}
|
|
|
|
|
2019-07-01 14:52:01 +02:00
|
|
|
$compare_to = get_post( $compare_to );
|
|
|
|
if ( ! $compare_to ) {
|
2013-06-26 23:06:50 +02:00
|
|
|
return false;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2013-06-26 23:06:50 +02:00
|
|
|
|
2023-07-09 22:07:22 +02:00
|
|
|
/*
|
|
|
|
* If comparing revisions, make sure we are dealing with the right post parent.
|
|
|
|
* The parent post may be a 'revision' when revisions are disabled and we're looking at autosaves.
|
|
|
|
*/
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( $compare_from && $compare_from->post_parent !== $post->ID && $compare_from->ID !== $post->ID ) {
|
2013-06-26 23:06:50 +02:00
|
|
|
return false;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
|
|
|
if ( $compare_to->post_parent !== $post->ID && $compare_to->ID !== $post->ID ) {
|
2013-06-26 23:06:50 +02:00
|
|
|
return false;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2013-06-26 23:06:50 +02:00
|
|
|
|
|
|
|
if ( $compare_from && strtotime( $compare_from->post_date_gmt ) > strtotime( $compare_to->post_date_gmt ) ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$temp = $compare_from;
|
2013-06-26 23:06:50 +02:00
|
|
|
$compare_from = $compare_to;
|
2017-12-01 00:11:00 +01:00
|
|
|
$compare_to = $temp;
|
2013-06-26 23:06:50 +02:00
|
|
|
}
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Add default title if title field is empty.
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( $compare_from && empty( $compare_from->post_title ) ) {
|
2013-07-06 12:48:14 +02:00
|
|
|
$compare_from->post_title = __( '(no title)' );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
|
|
|
if ( empty( $compare_to->post_title ) ) {
|
2013-07-06 12:48:14 +02:00
|
|
|
$compare_to->post_title = __( '(no title)' );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2013-07-06 12:48:14 +02:00
|
|
|
|
2013-06-26 23:06:50 +02:00
|
|
|
$return = array();
|
|
|
|
|
2016-02-24 01:44:59 +01:00
|
|
|
foreach ( _wp_post_revision_fields( $post ) as $field => $name ) {
|
2013-09-24 00:45:10 +02:00
|
|
|
/**
|
|
|
|
* Contextually filter a post revision field.
|
|
|
|
*
|
2021-03-07 13:32:09 +01:00
|
|
|
* The dynamic portion of the hook name, `$field`, corresponds to a name of a
|
|
|
|
* field of the revision object.
|
|
|
|
*
|
|
|
|
* Possible hook names include:
|
|
|
|
*
|
|
|
|
* - `_wp_post_revision_field_post_title`
|
|
|
|
* - `_wp_post_revision_field_post_content`
|
|
|
|
* - `_wp_post_revision_field_post_excerpt`
|
2013-09-24 00:45:10 +02:00
|
|
|
*
|
|
|
|
* @since 3.6.0
|
|
|
|
*
|
2019-10-27 20:11:02 +01:00
|
|
|
* @param string $revision_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.
|
|
|
|
* @param string $context The context of whether the current revision is the old
|
|
|
|
* or the new one. Values are 'to' or 'from'.
|
2013-09-24 00:45:10 +02:00
|
|
|
*/
|
2016-08-22 20:25:31 +02:00
|
|
|
$content_from = $compare_from ? apply_filters( "_wp_post_revision_field_{$field}", $compare_from->$field, $field, $compare_from, 'from' ) : '';
|
2013-09-24 00:45:10 +02:00
|
|
|
|
2013-10-25 00:59:20 +02:00
|
|
|
/** This filter is documented in wp-admin/includes/revision.php */
|
2016-08-22 20:25:31 +02:00
|
|
|
$content_to = apply_filters( "_wp_post_revision_field_{$field}", $compare_to->$field, $field, $compare_to, 'to' );
|
2013-06-26 23:06:50 +02:00
|
|
|
|
2014-11-20 00:21:23 +01:00
|
|
|
$args = array(
|
2017-12-01 00:11:00 +01:00
|
|
|
'show_split_view' => true,
|
2021-01-27 22:53:58 +01:00
|
|
|
'title_left' => __( 'Removed' ),
|
|
|
|
'title_right' => __( 'Added' ),
|
2014-11-20 00:21:23 +01:00
|
|
|
);
|
2014-11-21 04:50:24 +01:00
|
|
|
|
2014-11-20 00:21:23 +01:00
|
|
|
/**
|
2016-05-22 20:01:30 +02:00
|
|
|
* Filters revisions text diff options.
|
2014-11-20 00:21:23 +01:00
|
|
|
*
|
2016-05-22 20:01:30 +02:00
|
|
|
* Filters the options passed to wp_text_diff() when viewing a post revision.
|
2014-11-20 00:21:23 +01:00
|
|
|
*
|
|
|
|
* @since 4.1.0
|
|
|
|
*
|
|
|
|
* @param array $args {
|
2016-05-02 06:00:28 +02:00
|
|
|
* Associative array of options to pass to wp_text_diff().
|
2014-11-20 00:21:23 +01:00
|
|
|
*
|
2014-12-04 15:36:24 +01:00
|
|
|
* @type bool $show_split_view True for split view (two columns), false for
|
|
|
|
* un-split view (single column). Default true.
|
2014-11-20 00:21:23 +01: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-21 04:50:24 +01:00
|
|
|
|
2014-11-20 00:21:23 +01:00
|
|
|
$diff = wp_text_diff( $content_from, $content_to, $args );
|
2013-06-26 23:06:50 +02:00
|
|
|
|
|
|
|
if ( ! $diff && 'post_title' === $field ) {
|
2023-07-09 22:07:22 +02:00
|
|
|
/*
|
|
|
|
* 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-17 03:51:36 +02: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 18:12:30 +02: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-17 03:51:36 +02:00
|
|
|
$diff .= '</tr></tbody>';
|
2013-06-26 23:06:50 +02:00
|
|
|
$diff .= '</table>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $diff ) {
|
|
|
|
$return[] = array(
|
2017-12-01 00:11:00 +01:00
|
|
|
'id' => $field,
|
2013-06-26 23:06:50 +02:00
|
|
|
'name' => $name,
|
|
|
|
'diff' => $diff,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2014-10-29 20:02:21 +01:00
|
|
|
|
|
|
|
/**
|
2016-05-22 20:01:30 +02:00
|
|
|
* Filters the fields displayed in the post revision diff UI.
|
2014-10-29 20:02:21 +01:00
|
|
|
*
|
|
|
|
* @since 4.1.0
|
|
|
|
*
|
2018-03-25 20:10:32 +02:00
|
|
|
* @param array[] $return Array of revision UI fields. Each item is an array of id, name, and diff.
|
2014-10-29 20:02:21 +01: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 23:06:50 +02:00
|
|
|
}
|
|
|
|
|
2013-07-17 22:39:35 +02:00
|
|
|
/**
|
|
|
|
* Prepare revisions for JavaScript.
|
|
|
|
*
|
2013-07-28 01:11:03 +02:00
|
|
|
* @since 3.6.0
|
|
|
|
*
|
2019-12-06 23:43:04 +01:00
|
|
|
* @param WP_Post|int $post The post object or post ID.
|
|
|
|
* @param int $selected_revision_id The selected revision ID.
|
|
|
|
* @param int $from Optional. The revision ID to compare from.
|
2013-07-17 23:09:14 +02:00
|
|
|
* @return array An associative array of revision data and related settings.
|
2013-07-17 22:39:35 +02:00
|
|
|
*/
|
2013-07-12 00:56:48 +02:00
|
|
|
function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$post = get_post( $post );
|
2014-05-06 05:45:14 +02:00
|
|
|
$authors = array();
|
2013-07-11 22:57:47 +02:00
|
|
|
$now_gmt = time();
|
2013-06-26 23:06:50 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$revisions = wp_get_post_revisions(
|
2018-08-17 03:51:36 +02:00
|
|
|
$post->ID,
|
|
|
|
array(
|
2017-12-01 00:11:00 +01:00
|
|
|
'order' => 'ASC',
|
|
|
|
'check_enabled' => false,
|
|
|
|
)
|
|
|
|
);
|
2013-07-24 08:08:14 +02: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-12-01 00:11:00 +01:00
|
|
|
if ( ! wp_is_post_autosave( $revision ) ) {
|
2013-07-24 08:08:14 +02:00
|
|
|
unset( $revisions[ $revision_id ] );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2013-07-24 08:08:14 +02:00
|
|
|
}
|
|
|
|
$revisions = array( $post->ID => $post ) + $revisions;
|
|
|
|
}
|
|
|
|
|
2013-07-16 01:01:27 +02:00
|
|
|
$show_avatars = get_option( 'show_avatars' );
|
2013-06-26 23:06:50 +02:00
|
|
|
|
2022-12-06 14:42:13 +01:00
|
|
|
update_post_author_caches( $revisions );
|
2013-06-26 23:06:50 +02:00
|
|
|
|
2013-07-24 08:08:14 +02:00
|
|
|
$can_restore = current_user_can( 'edit_post', $post->ID );
|
2017-12-01 00:11:00 +01:00
|
|
|
$current_id = false;
|
2013-07-24 08:08:14 +02:00
|
|
|
|
2013-06-26 23:06:50 +02:00
|
|
|
foreach ( $revisions as $revision ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$modified = strtotime( $revision->post_modified );
|
2017-09-22 01:33:44 +02:00
|
|
|
$modified_gmt = strtotime( $revision->post_modified_gmt . ' +0000' );
|
2013-07-24 08:08:14 +02:00
|
|
|
if ( $can_restore ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$restore_link = str_replace(
|
2018-08-17 03:51:36 +02:00
|
|
|
'&',
|
|
|
|
'&',
|
|
|
|
wp_nonce_url(
|
2017-12-01 00:11:00 +01:00
|
|
|
add_query_arg(
|
|
|
|
array(
|
|
|
|
'revision' => $revision->ID,
|
|
|
|
'action' => 'restore',
|
|
|
|
),
|
2013-07-24 08:08:14 +02:00
|
|
|
admin_url( 'revision.php' )
|
2017-12-01 00:11:00 +01:00
|
|
|
),
|
|
|
|
"restore-post_{$revision->ID}"
|
|
|
|
)
|
|
|
|
);
|
2013-07-24 08:08:14 +02:00
|
|
|
}
|
2013-07-16 01:01:27 +02:00
|
|
|
|
|
|
|
if ( ! isset( $authors[ $revision->post_author ] ) ) {
|
|
|
|
$authors[ $revision->post_author ] = array(
|
2017-12-01 00:11:00 +01: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 07:05:45 +02:00
|
|
|
'avatar' => $show_avatars ? get_avatar( $revision->post_author, 32 ) : '',
|
2017-12-01 00:11:00 +01:00
|
|
|
'name' => get_the_author_meta( 'display_name', $revision->post_author ),
|
2013-07-16 01:01:27 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-24 08:08:14 +02:00
|
|
|
$autosave = (bool) wp_is_post_autosave( $revision );
|
2017-12-01 00:11:00 +01:00
|
|
|
$current = ! $autosave && $revision->post_modified_gmt === $post->post_modified_gmt;
|
2013-07-18 16:10:33 +02:00
|
|
|
if ( $current && ! empty( $current_id ) ) {
|
2013-07-24 08:08:14 +02:00
|
|
|
// If multiple revisions have the same post_modified_gmt, highest ID is current.
|
2013-07-18 16:10:33 +02:00
|
|
|
if ( $current_id < $revision->ID ) {
|
|
|
|
$revisions[ $current_id ]['current'] = false;
|
2017-12-01 00:11:00 +01:00
|
|
|
$current_id = $revision->ID;
|
2013-07-18 16:10:33 +02:00
|
|
|
} else {
|
|
|
|
$current = false;
|
|
|
|
}
|
|
|
|
} elseif ( $current ) {
|
|
|
|
$current_id = $revision->ID;
|
|
|
|
}
|
|
|
|
|
2015-09-25 16:04:24 +02:00
|
|
|
$revisions_data = array(
|
2013-07-16 01:01:27 +02:00
|
|
|
'id' => $revision->ID,
|
|
|
|
'title' => get_the_title( $post->ID ),
|
|
|
|
'author' => $authors[ $revision->post_author ],
|
2015-03-23 03:14:27 +01:00
|
|
|
'date' => date_i18n( __( 'M j, Y @ H:i' ), $modified ),
|
|
|
|
'dateShort' => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), $modified ),
|
2019-09-03 02:41:05 +02:00
|
|
|
/* translators: %s: Human-readable time difference. */
|
2013-07-16 01:01:27 +02:00
|
|
|
'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( $modified_gmt, $now_gmt ) ),
|
2013-07-18 16:10:33 +02:00
|
|
|
'autosave' => $autosave,
|
|
|
|
'current' => $current,
|
2013-07-24 08:08:14 +02:00
|
|
|
'restoreUrl' => $can_restore ? $restore_link : false,
|
2013-06-26 23:06:50 +02:00
|
|
|
);
|
2015-09-25 16:04:24 +02:00
|
|
|
|
|
|
|
/**
|
2016-05-22 20:01:30 +02:00
|
|
|
* Filters the array of revisions used on the revisions screen.
|
2015-09-25 16:04:24 +02:00
|
|
|
*
|
|
|
|
* @since 4.4.0
|
|
|
|
*
|
2015-10-05 20:03:26 +02: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 20:33:28 +02:00
|
|
|
* @param WP_Post $revision The revision's WP_Post object.
|
2015-09-25 16:04:24 +02:00
|
|
|
* @param WP_Post $post The revision's parent WP_Post object.
|
|
|
|
*/
|
2015-10-05 20:33:28 +02:00
|
|
|
$revisions[ $revision->ID ] = apply_filters( 'wp_prepare_revision_for_js', $revisions_data, $revision, $post );
|
2013-06-26 23:06:50 +02:00
|
|
|
}
|
|
|
|
|
2022-11-04 11:10:14 +01:00
|
|
|
/*
|
|
|
|
* If we only have one revision, the initial revision is missing. This happens
|
|
|
|
* when we have an autosave and the user has clicked 'View the Autosave'.
|
2014-11-16 04:36:23 +01:00
|
|
|
*/
|
2020-10-18 19:27:06 +02:00
|
|
|
if ( 1 === count( $revisions ) ) {
|
2014-11-16 04:36:23 +01:00
|
|
|
$revisions[ $post->ID ] = array(
|
|
|
|
'id' => $post->ID,
|
|
|
|
'title' => get_the_title( $post->ID ),
|
2021-02-01 23:03:01 +01:00
|
|
|
'author' => $authors[ $revision->post_author ],
|
2015-03-23 03:14:27 +01: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 ) ),
|
2019-09-03 02:41:05 +02:00
|
|
|
/* translators: %s: Human-readable time difference. */
|
2014-11-16 04:36:23 +01:00
|
|
|
'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( strtotime( $post->post_modified_gmt ), $now_gmt ) ),
|
|
|
|
'autosave' => false,
|
|
|
|
'current' => true,
|
|
|
|
'restoreUrl' => false,
|
|
|
|
);
|
2017-12-01 00:11:00 +01:00
|
|
|
$current_id = $post->ID;
|
2014-11-16 04:36:23 +01:00
|
|
|
}
|
|
|
|
|
2014-07-17 11:14:16 +02:00
|
|
|
/*
|
2022-07-25 21:30:09 +02:00
|
|
|
* If a post has been saved since the latest revision (no revisioned fields
|
2014-07-17 11:14:16 +02:00
|
|
|
* were changed), we may not have a "current" revision. Mark the latest
|
|
|
|
* revision as "current".
|
|
|
|
*/
|
2013-07-24 08:08:14 +02: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 07:05:45 +02:00
|
|
|
|
2014-07-17 11:14:16 +02:00
|
|
|
// Now, grab the initial diff.
|
2013-07-12 16:01:39 +02:00
|
|
|
$compare_two_mode = is_numeric( $from );
|
|
|
|
if ( ! $compare_two_mode ) {
|
2020-04-09 17:43:10 +02:00
|
|
|
$found = array_search( $selected_revision_id, array_keys( $revisions ), true );
|
2013-07-29 19:53:24 +02:00
|
|
|
if ( $found ) {
|
|
|
|
$from = array_keys( array_slice( $revisions, $found - 1, 1, true ) );
|
|
|
|
$from = reset( $from );
|
|
|
|
} else {
|
2013-07-29 19:26:03 +02:00
|
|
|
$from = 0;
|
2013-07-29 19:53:24 +02:00
|
|
|
}
|
2013-07-12 16:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$from = absint( $from );
|
2013-07-12 07:11:56 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$diffs = array(
|
|
|
|
array(
|
|
|
|
'id' => $from . ':' . $selected_revision_id,
|
|
|
|
'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ),
|
|
|
|
),
|
|
|
|
);
|
2013-07-12 00:56:48 +02:00
|
|
|
|
2013-06-26 23:06:50 +02:00
|
|
|
return array(
|
2017-12-01 00:11:00 +01: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 ),
|
2020-01-29 01:45:18 +01:00
|
|
|
'compareTwoMode' => absint( $compare_two_mode ), // Apparently booleans are not allowed.
|
2017-12-01 00:11:00 +01:00
|
|
|
'revisionIds' => array_keys( $revisions ),
|
2013-06-26 23:06:50 +02:00
|
|
|
);
|
2013-06-29 19:45:02 +02:00
|
|
|
}
|
2014-11-01 01:15:24 +01:00
|
|
|
|
|
|
|
/**
|
2014-12-02 01:31:22 +01:00
|
|
|
* Print JavaScript templates required for the revisions experience.
|
2014-11-01 01:15:24 +01:00
|
|
|
*
|
|
|
|
* @since 4.1.0
|
2014-11-28 10:05:23 +01:00
|
|
|
*
|
2019-08-04 14:28:56 +02:00
|
|
|
* @global WP_Post $post Global post object.
|
2014-11-01 01:15:24 +01: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 20:06:30 +02:00
|
|
|
<?php esc_html_e( 'Compare any two revisions' ); ?>
|
2014-11-01 01:15:24 +01: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-12-01 00:11:00 +01:00
|
|
|
<span class="byline">
|
|
|
|
<?php
|
|
|
|
printf(
|
2019-09-03 02:41:05 +02:00
|
|
|
/* translators: %s: User's display name. */
|
2017-12-01 00:11:00 +01:00
|
|
|
__( 'Autosave by %s' ),
|
|
|
|
'<span class="author-name">{{ data.attributes.author.name }}</span>'
|
|
|
|
);
|
2018-08-17 03:51:36 +02:00
|
|
|
?>
|
2017-12-01 00:11:00 +01:00
|
|
|
</span>
|
2014-11-01 01:15:24 +01:00
|
|
|
<# } else if ( data.attributes.current ) { #>
|
2017-12-01 00:11:00 +01:00
|
|
|
<span class="byline">
|
|
|
|
<?php
|
|
|
|
printf(
|
2019-09-03 02:41:05 +02:00
|
|
|
/* translators: %s: User's display name. */
|
2017-12-01 00:11:00 +01:00
|
|
|
__( 'Current Revision by %s' ),
|
|
|
|
'<span class="author-name">{{ data.attributes.author.name }}</span>'
|
|
|
|
);
|
2018-08-17 03:51:36 +02:00
|
|
|
?>
|
2017-12-01 00:11:00 +01:00
|
|
|
</span>
|
2014-11-01 01:15:24 +01:00
|
|
|
<# } else { #>
|
2017-12-01 00:11:00 +01:00
|
|
|
<span class="byline">
|
|
|
|
<?php
|
|
|
|
printf(
|
2019-09-03 02:41:05 +02:00
|
|
|
/* translators: %s: User's display name. */
|
2017-12-01 00:11:00 +01:00
|
|
|
__( 'Revision by %s' ),
|
|
|
|
'<span class="author-name">{{ data.attributes.author.name }}</span>'
|
|
|
|
);
|
2018-08-17 03:51:36 +02:00
|
|
|
?>
|
2017-12-01 00:11:00 +01:00
|
|
|
</span>
|
2014-11-01 01:15:24 +01: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-12-01 00:11:00 +01:00
|
|
|
</script>
|
|
|
|
<?php
|
2016-08-28 20:06:30 +02:00
|
|
|
}
|