3 * Revisions administration panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once('admin.php');
12 wp_reset_vars(array('revision', 'left', 'right', 'diff', 'action'));
13 $revision_id = absint($revision);
14 $diff = absint($diff);
15 $left = absint($left);
16 $right = absint($right);
18 $parent_file = $redirect = 'edit.php';
21 case 'delete' : // stubs
23 if ( constant('WP_POST_REVISIONS') ) // stub
24 $redirect = remove_query_arg( 'action' );
25 else // Revisions disabled
26 $redirect = 'edit.php';
29 if ( !$revision = wp_get_post_revision( $revision_id ) )
31 if ( !current_user_can( 'edit_post', $revision->post_parent ) )
33 if ( !$post = get_post( $revision->post_parent ) )
36 if ( !constant('WP_POST_REVISIONS') && !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave
39 check_admin_referer( "restore-post_$post->ID|$revision->ID" );
41 wp_restore_post_revision( $revision->ID );
42 $redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) );
45 if ( !$left_revision = get_post( $left ) )
47 if ( !$right_revision = get_post( $right ) )
50 if ( !current_user_can( 'read_post', $left_revision->ID ) || !current_user_can( 'read_post', $right_revision->ID ) )
53 // If we're comparing a revision to itself, redirect to the 'view' page for that revision or the edit page for that post
54 if ( $left_revision->ID == $right_revision->ID ) {
55 $redirect = get_edit_post_link( $left_revision->ID );
56 include( 'js/revisions-js.php' );
60 // Don't allow reverse diffs?
61 if ( strtotime($right_revision->post_modified_gmt) < strtotime($left_revision->post_modified_gmt) ) {
62 $redirect = add_query_arg( array( 'left' => $right, 'right' => $left ) );
66 if ( $left_revision->ID == $right_revision->post_parent ) // right is a revision of left
67 $post =& $left_revision;
68 elseif ( $left_revision->post_parent == $right_revision->ID ) // left is a revision of right
69 $post =& $right_revision;
70 elseif ( $left_revision->post_parent == $right_revision->post_parent ) // both are revisions of common parent
71 $post = get_post( $left_revision->post_parent );
73 break; // Don't diff two unrelated revisions
75 if ( !constant('WP_POST_REVISIONS') ) { // Revisions disabled
77 // we're not looking at an autosave
78 ( !wp_is_post_autosave( $left_revision ) && !wp_is_post_autosave( $right_revision ) )
80 // we're not comparing an autosave to the current post
81 ( $post->ID !== $left_revision->ID && $post->ID !== $right_revision->ID )
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 );
98 $left = $left_revision->ID;
99 $right = $right_revision->ID;
105 if ( !$revision = wp_get_post_revision( $revision_id ) )
107 if ( !$post = get_post( $revision->post_parent ) )
110 if ( !current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) )
113 if ( !constant('WP_POST_REVISIONS') && !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave
116 $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
117 $revision_title = wp_post_revision_title( $revision, false );
118 $h2 = sprintf( __( 'Post Revision for “%1$s” created on %2$s' ), $post_title, $revision_title );
120 // Sets up the diff radio buttons
121 $left = $revision->ID;
128 if ( !$redirect && !in_array( $post->post_type, array( 'post', 'page' ) ) )
129 $redirect = 'edit.php';
132 wp_redirect( $redirect );
136 if ( 'page' == $post->post_type ) {
137 $submenu_file = 'edit-pages.php';
138 $title = __( 'Page Revisions' );
140 $submenu_file = 'edit.php';
141 $title = __( 'Post Revisions' );
144 require_once( 'admin-header.php' );
150 <h2 class="long-header"><?php echo $h2; ?></h2>
152 <table class="form-table ie-fixed">
154 <?php if ( 'diff' == $action ) : ?>
156 <th scope="row"></th>
157 <th scope="col" class="th-full">
158 <span class="alignleft"><?php printf( __('Older: %s'), wp_post_revision_title( $left_revision ) ); ?></span>
159 <span class="alignright"><?php printf( __('Newer: %s'), wp_post_revision_title( $right_revision ) ); ?></span>
164 // use get_post_to_edit filters?
166 foreach ( _wp_post_revision_fields() as $field => $field_title ) :
167 if ( 'diff' == $action ) {
168 $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field );
169 $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field );
170 if ( !$content = wp_text_diff( $left_content, $right_content ) )
171 continue; // There is no difference between left and right
174 add_filter( "_wp_post_revision_field_$field", 'htmlspecialchars' );
175 $content = apply_filters( "_wp_post_revision_field_$field", $revision->$field, $field );
179 <tr id="revision-field-<?php echo $field; ?>">
180 <th scope="row"><?php echo esc_html( $field_title ); ?></th>
181 <td><div class="pre"><?php echo $content; ?></div></td>
188 if ( 'diff' == $action && $identical ) :
192 <tr><td colspan="2"><div class="updated"><p><?php _e( 'These revisions are identical.' ); ?></p></div></td></tr>
204 <h2><?php echo $title; ?></h2>
208 $args = array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left );
209 if ( !constant( 'WP_POST_REVISIONS' ) )
210 $args['type'] = 'autosave';
212 wp_list_post_revisions( $post, $args );
220 require_once( 'admin-footer.php' );