3 * Revisions administration panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once('./admin.php');
12 wp_enqueue_script('list-revisions');
14 wp_reset_vars(array('revision', 'left', 'right', 'action'));
16 $revision_id = absint($revision);
17 $left = absint($left);
18 $right = absint($right);
20 $redirect = 'edit.php';
24 if ( !$revision = wp_get_post_revision( $revision_id ) )
26 if ( !current_user_can( 'edit_post', $revision->post_parent ) )
28 if ( !$post = get_post( $revision->post_parent ) )
31 // Revisions disabled and we're not looking at an autosave
32 if ( ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) {
33 $redirect = 'edit.php?post_type=' . $post->post_type;
37 check_admin_referer( "restore-post_$post->ID|$revision->ID" );
39 wp_restore_post_revision( $revision->ID );
40 $redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) );
43 if ( !$left_revision = get_post( $left ) )
45 if ( !$right_revision = get_post( $right ) )
48 if ( !current_user_can( 'read_post', $left_revision->ID ) || !current_user_can( 'read_post', $right_revision->ID ) )
51 // If we're comparing a revision to itself, redirect to the 'view' page for that revision or the edit page for that post
52 if ( $left_revision->ID == $right_revision->ID ) {
53 $redirect = get_edit_post_link( $left_revision->ID );
54 include( './js/revisions-js.php' );
58 // Don't allow reverse diffs?
59 if ( strtotime($right_revision->post_modified_gmt) < strtotime($left_revision->post_modified_gmt) ) {
60 $redirect = add_query_arg( array( 'left' => $right, 'right' => $left ) );
64 if ( $left_revision->ID == $right_revision->post_parent ) // right is a revision of left
65 $post =& $left_revision;
66 elseif ( $left_revision->post_parent == $right_revision->ID ) // left is a revision of right
67 $post =& $right_revision;
68 elseif ( $left_revision->post_parent == $right_revision->post_parent ) // both are revisions of common parent
69 $post = get_post( $left_revision->post_parent );
71 break; // Don't diff two unrelated revisions
73 if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) { // Revisions disabled
75 // we're not looking at an autosave
76 ( !wp_is_post_autosave( $left_revision ) && !wp_is_post_autosave( $right_revision ) )
78 // we're not comparing an autosave to the current post
79 ( $post->ID !== $left_revision->ID && $post->ID !== $right_revision->ID )
81 $redirect = 'edit.php?post_type=' . $post->post_type;
88 $left_revision->ID == $right_revision->ID
90 // Neither is a revision
91 ( !wp_get_post_revision( $left_revision->ID ) && !wp_get_post_revision( $right_revision->ID ) )
95 $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
96 $h2 = sprintf( __( 'Compare Revisions of “%1$s”' ), $post_title );
97 $title = __( 'Revisions' );
99 $left = $left_revision->ID;
100 $right = $right_revision->ID;
106 if ( !$revision = wp_get_post_revision( $revision_id ) )
108 if ( !$post = get_post( $revision->post_parent ) )
111 if ( !current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) )
114 // Revisions disabled and we're not looking at an autosave
115 if ( ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) {
116 $redirect = 'edit.php?post_type=' . $post->post_type;
120 $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
121 $revision_title = wp_post_revision_title( $revision, false );
122 $h2 = sprintf( __( 'Revision for “%1$s” created on %2$s' ), $post_title, $revision_title );
123 $title = __( 'Revisions' );
125 // Sets up the diff radio buttons
126 $left = $revision->ID;
133 // Empty post_type means either malformed object found, or no valid parent was found.
134 if ( !$redirect && empty($post->post_type) )
135 $redirect = 'edit.php';
137 if ( !empty($redirect) ) {
138 wp_redirect( $redirect );
142 // This is so that the correct "Edit" menu item is selected.
143 if ( !empty($post->post_type) && 'post' != $post->post_type )
144 $parent_file = $submenu_file = 'edit.php?post_type=' . $post->post_type;
146 $parent_file = $submenu_file = 'edit.php';
148 require_once( './admin-header.php' );
154 <h2 class="long-header"><?php echo $h2; ?></h2>
156 <table class="form-table ie-fixed">
158 <?php if ( 'diff' == $action ) : ?>
160 <th scope="row"></th>
161 <th scope="col" class="th-full">
162 <span class="alignleft"><?php printf( __('Older: %s'), wp_post_revision_title( $left_revision ) ); ?></span>
163 <span class="alignright"><?php printf( __('Newer: %s'), wp_post_revision_title( $right_revision ) ); ?></span>
168 // use get_post_to_edit filters?
170 foreach ( _wp_post_revision_fields() as $field => $field_title ) :
171 if ( 'diff' == $action ) {
172 $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field );
173 $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field );
174 if ( !$content = wp_text_diff( $left_content, $right_content ) )
175 continue; // There is no difference between left and right
178 add_filter( "_wp_post_revision_field_$field", 'htmlspecialchars' );
179 $content = apply_filters( "_wp_post_revision_field_$field", $revision->$field, $field );
183 <tr id="revision-field-<?php echo $field; ?>">
184 <th scope="row"><?php echo esc_html( $field_title ); ?></th>
185 <td><div class="pre"><?php echo $content; ?></div></td>
192 if ( 'diff' == $action && $identical ) :
196 <tr><td colspan="2"><div class="updated"><p><?php _e( 'These revisions are identical.' ); ?></p></div></td></tr>
208 <h3><?php echo $title; ?></h3>
212 $args = array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left );
213 if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') )
214 $args['type'] = 'autosave';
216 wp_list_post_revisions( $post, $args );
223 require_once( './admin-footer.php' );