wp/wp-admin/includes/revision.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * WordPress Administration Revisions API
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Administration
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 * Get the revision UI diff.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 * @param object|int $post         The post object. Also accepts a post ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 * @param int        $compare_from The revision ID to compare from.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 * @param int        $compare_to   The revision ID to come to.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
 * @return array|bool Associative array of a post's revisioned fields and their diffs.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
 *                    Or, false on failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
	if ( ! $post = get_post( $post ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
	if ( $compare_from ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
		if ( ! $compare_from = get_post( $compare_from ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
		// If we're dealing with the first revision...
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
		$compare_from = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
	if ( ! $compare_to = get_post( $compare_to ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
	// If comparing revisions, make sure we're dealing with the right post parent.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
	// The parent post may be a 'revision' when revisions are disabled and we're looking at autosaves.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
	if ( $compare_from && $compare_from->post_parent !== $post->ID && $compare_from->ID !== $post->ID )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
	if ( $compare_to->post_parent !== $post->ID && $compare_to->ID !== $post->ID )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	if ( $compare_from && strtotime( $compare_from->post_date_gmt ) > strtotime( $compare_to->post_date_gmt ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
		$temp = $compare_from;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
		$compare_from = $compare_to;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
		$compare_to = $temp;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
	// Add default title if title field is empty
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
	if ( $compare_from && empty( $compare_from->post_title ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
		$compare_from->post_title = __( '(no title)' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
	if ( empty( $compare_to->post_title ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
		$compare_to->post_title = __( '(no title)' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
	$return = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
	foreach ( _wp_post_revision_fields() as $field => $name ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
		 * Contextually filter a post revision field.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
		 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    61
		 * The dynamic portion of the hook name, `$field`, corresponds to each of the post
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
		 * fields of the revision object being iterated over in a foreach statement.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
		 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
		 * @param string  $compare_from->$field The current revision field to compare to or from.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
		 * @param string  $field                The current revision field.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
		 * @param WP_Post $compare_from         The revision post object to compare to or from.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    69
		 * @param string  null                  The context of whether the current revision is the old
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    70
		 *                                      or the new one. Values are 'to' or 'from'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
		$content_from = $compare_from ? apply_filters( "_wp_post_revision_field_$field", $compare_from->$field, $field, $compare_from, 'from' ) : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
		/** This filter is documented in wp-admin/includes/revision.php */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
		$content_to = apply_filters( "_wp_post_revision_field_$field", $compare_to->$field, $field, $compare_to, 'to' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    77
		$args = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    78
			'show_split_view' => true
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    79
		);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    80
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    81
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    82
		 * Filter revisions text diff options.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    83
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    84
		 * Filter the options passed to {@see wp_text_diff()} when viewing a post revision.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    85
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    86
		 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    87
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    88
		 * @param array   $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    89
		 *     Associative array of options to pass to {@see wp_text_diff()}.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    90
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    91
		 *     @type bool $show_split_view True for split view (two columns), false for
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    92
		 *                                 un-split view (single column). Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    93
		 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    94
		 * @param string  $field        The current revision field.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    95
		 * @param WP_Post $compare_from The revision post to compare from.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    96
		 * @param WP_Post $compare_to   The revision post to compare to.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    97
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    98
		$args = apply_filters( 'revision_text_diff_options', $args, $field, $compare_from, $compare_to );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    99
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   100
		$diff = wp_text_diff( $content_from, $content_to, $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
		if ( ! $diff && 'post_title' === $field ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
			// It's a better user experience to still show the Title, even if it didn't change.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
			// No, you didn't see this.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
			$diff = '<table class="diff"><colgroup><col class="content diffsplit left"><col class="content diffsplit middle"><col class="content diffsplit right"></colgroup><tbody><tr>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
			$diff .= '<td>' . esc_html( $compare_from->post_title ) . '</td><td></td><td>' . esc_html( $compare_to->post_title ) . '</td>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
			$diff .= '</tr></tbody>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
			$diff .= '</table>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
		if ( $diff ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
			$return[] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
				'id' => $field,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
				'name' => $name,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
				'diff' => $diff,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   119
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   120
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   121
	 * Filter the fields displayed in the post revision diff UI.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   122
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   123
	 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   124
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   125
	 * @param array   $return       Revision UI fields. Each item is an array of id, name and diff.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   126
	 * @param WP_Post $compare_from The revision post to compare from.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   127
	 * @param WP_Post $compare_to   The revision post to compare to.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   128
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   129
	return apply_filters( 'wp_get_revision_ui_diff', $return, $compare_from, $compare_to );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   130
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
 * Prepare revisions for JavaScript.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
 * @param object|int $post                 The post object. Also accepts a post ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
 * @param int        $selected_revision_id The selected revision ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
 * @param int        $from                 Optional. The revision ID to compare from.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
 * @return array An associative array of revision data and related settings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
	$post = get_post( $post );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   146
	$authors = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
	$now_gmt = time();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
	$revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC', 'check_enabled' => false ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
	// If revisions are disabled, we only want autosaves and the current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
	if ( ! wp_revisions_enabled( $post ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
		foreach ( $revisions as $revision_id => $revision ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
			if ( ! wp_is_post_autosave( $revision ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
				unset( $revisions[ $revision_id ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
		$revisions = array( $post->ID => $post ) + $revisions;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
	$show_avatars = get_option( 'show_avatars' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
	cache_users( wp_list_pluck( $revisions, 'post_author' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
	$can_restore = current_user_can( 'edit_post', $post->ID );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   164
	$current_id = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
	foreach ( $revisions as $revision ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
		$modified = strtotime( $revision->post_modified );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
		$modified_gmt = strtotime( $revision->post_modified_gmt );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
		if ( $can_restore ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
			$restore_link = str_replace( '&amp;', '&', wp_nonce_url(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
				add_query_arg(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
					array( 'revision' => $revision->ID,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
						'action' => 'restore' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
						admin_url( 'revision.php' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
				),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
				"restore-post_{$revision->ID}"
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
			) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
		if ( ! isset( $authors[ $revision->post_author ] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
			$authors[ $revision->post_author ] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
				'id' => (int) $revision->post_author,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
				'avatar' => $show_avatars ? get_avatar( $revision->post_author, 32 ) : '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
				'name' => get_the_author_meta( 'display_name', $revision->post_author ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
		$autosave = (bool) wp_is_post_autosave( $revision );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
		$current = ! $autosave && $revision->post_modified_gmt === $post->post_modified_gmt;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
		if ( $current && ! empty( $current_id ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
			// If multiple revisions have the same post_modified_gmt, highest ID is current.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
			if ( $current_id < $revision->ID ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
				$revisions[ $current_id ]['current'] = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
				$current_id = $revision->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
				$current = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
		} elseif ( $current ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
			$current_id = $revision->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
		$revisions[ $revision->ID ] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
			'id'         => $revision->ID,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
			'title'      => get_the_title( $post->ID ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
			'author'     => $authors[ $revision->post_author ],
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   206
			'date'       => date_i18n( __( 'M j, Y @ H:i' ), $modified ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   207
			'dateShort'  => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), $modified ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
			'timeAgo'    => sprintf( __( '%s ago' ), human_time_diff( $modified_gmt, $now_gmt ) ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
			'autosave'   => $autosave,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
			'current'    => $current,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
			'restoreUrl' => $can_restore ? $restore_link : false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   215
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   216
	 * If we only have one revision, the initial revision is missing; This happens
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   217
	 * when we have an autsosave and the user has clicked 'View the Autosave'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   218
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   219
	if ( 1 === sizeof( $revisions ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   220
		$revisions[ $post->ID ] = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   221
			'id'         => $post->ID,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   222
			'title'      => get_the_title( $post->ID ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   223
			'author'     => $authors[ $post->post_author ],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   224
			'date'       => date_i18n( __( 'M j, Y @ H:i' ), strtotime( $post->post_modified ) ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   225
			'dateShort'  => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), strtotime( $post->post_modified ) ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   226
			'timeAgo'    => sprintf( __( '%s ago' ), human_time_diff( strtotime( $post->post_modified_gmt ), $now_gmt ) ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   227
			'autosave'   => false,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   228
			'current'    => true,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   229
			'restoreUrl' => false,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   230
		);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   231
		$current_id = $post->ID;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   232
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   233
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   234
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   235
	 * If a post has been saved since the last revision (no revisioned fields
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   236
	 * were changed), we may not have a "current" revision. Mark the latest
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   237
	 * revision as "current".
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   238
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
	if ( empty( $current_id ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
		if ( $revisions[ $revision->ID ]['autosave'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
			$revision = end( $revisions );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
			while ( $revision['autosave'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
				$revision = prev( $revisions );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
			$current_id = $revision['id'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
			$current_id = $revision->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
		$revisions[ $current_id ]['current'] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   252
	// Now, grab the initial diff.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
	$compare_two_mode = is_numeric( $from );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
	if ( ! $compare_two_mode ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
		$found = array_search( $selected_revision_id, array_keys( $revisions ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
		if ( $found ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
			$from = array_keys( array_slice( $revisions, $found - 1, 1, true ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
			$from = reset( $from );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
			$from = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
	$from = absint( $from );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
	$diffs = array( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
		'id' => $from . ':' . $selected_revision_id,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
		'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
	));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
	return array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
		'postId'           => $post->ID,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
		'nonce'            => wp_create_nonce( 'revisions-ajax-nonce' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
		'revisionData'     => array_values( $revisions ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
		'to'               => $selected_revision_id,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
		'from'             => $from,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
		'diffData'         => $diffs,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
		'baseUrl'          => parse_url( admin_url( 'revision.php' ), PHP_URL_PATH ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
		'compareTwoMode'   => absint( $compare_two_mode ), // Apparently booleans are not allowed
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
		'revisionIds'      => array_keys( $revisions ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   283
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   284
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   285
 * Print JavaScript templates required for the revisions experience.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   286
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   287
 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   288
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   289
 * @global WP_Post $post The global `$post` object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   290
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   291
function wp_print_revision_templates() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   292
	global $post;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   293
	?><script id="tmpl-revisions-frame" type="text/html">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   294
		<div class="revisions-control-frame"></div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   295
		<div class="revisions-diff-frame"></div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   296
	</script>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   297
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   298
	<script id="tmpl-revisions-buttons" type="text/html">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   299
		<div class="revisions-previous">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   300
			<input class="button" type="button" value="<?php echo esc_attr_x( 'Previous', 'Button label for a previous revision' ); ?>" />
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   301
		</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   302
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   303
		<div class="revisions-next">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   304
			<input class="button" type="button" value="<?php echo esc_attr_x( 'Next', 'Button label for a next revision' ); ?>" />
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   305
		</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   306
	</script>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   307
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   308
	<script id="tmpl-revisions-checkbox" type="text/html">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   309
		<div class="revision-toggle-compare-mode">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   310
			<label>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   311
				<input type="checkbox" class="compare-two-revisions"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   312
				<#
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   313
				if ( 'undefined' !== typeof data && data.model.attributes.compareTwoMode ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   314
					#> checked="checked"<#
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   315
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   316
				#>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   317
				/>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   318
				<?php esc_attr_e( 'Compare any two revisions' ); ?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   319
			</label>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   320
		</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   321
	</script>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   322
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   323
	<script id="tmpl-revisions-meta" type="text/html">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   324
		<# if ( ! _.isUndefined( data.attributes ) ) { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   325
			<div class="diff-title">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   326
				<# if ( 'from' === data.type ) { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   327
					<strong><?php _ex( 'From:', 'Followed by post revision info' ); ?></strong>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   328
				<# } else if ( 'to' === data.type ) { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   329
					<strong><?php _ex( 'To:', 'Followed by post revision info' ); ?></strong>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   330
				<# } #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   331
				<div class="author-card<# if ( data.attributes.autosave ) { #> autosave<# } #>">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   332
					{{{ data.attributes.author.avatar }}}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   333
					<div class="author-info">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   334
					<# if ( data.attributes.autosave ) { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   335
						<span class="byline"><?php printf( __( 'Autosave by %s' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   336
							'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   337
					<# } else if ( data.attributes.current ) { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   338
						<span class="byline"><?php printf( __( 'Current Revision by %s' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   339
							'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   340
					<# } else { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   341
						<span class="byline"><?php printf( __( 'Revision by %s' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   342
							'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   343
					<# } #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   344
						<span class="time-ago">{{ data.attributes.timeAgo }}</span>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   345
						<span class="date">({{ data.attributes.dateShort }})</span>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   346
					</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   347
				<# if ( 'to' === data.type && data.attributes.restoreUrl ) { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   348
					<input  <?php if ( wp_check_post_lock( $post->ID ) ) { ?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   349
						disabled="disabled"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   350
					<?php } else { ?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   351
						<# if ( data.attributes.current ) { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   352
							disabled="disabled"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   353
						<# } #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   354
					<?php } ?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   355
					<# if ( data.attributes.autosave ) { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   356
						type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Autosave' ); ?>" />
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   357
					<# } else { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   358
						type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Revision' ); ?>" />
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   359
					<# } #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   360
				<# } #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   361
			</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   362
		<# if ( 'tooltip' === data.type ) { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   363
			<div class="revisions-tooltip-arrow"><span></span></div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   364
		<# } #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   365
	<# } #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   366
	</script>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   367
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   368
	<script id="tmpl-revisions-diff" type="text/html">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   369
		<div class="loading-indicator"><span class="spinner"></span></div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   370
		<div class="diff-error"><?php _e( 'Sorry, something went wrong. The requested comparison could not be loaded.' ); ?></div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   371
		<div class="diff">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   372
		<# _.each( data.fields, function( field ) { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   373
			<h3>{{ field.name }}</h3>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   374
			{{{ field.diff }}}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   375
		<# }); #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   376
		</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   377
	</script><?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   378
}