mp-wp_genesis 1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * Revisions administration panel.
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @subpackage Administration
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /** WordPress Administration Bootstrap */
mp-wp_genesis 10 require_once('admin.php');
mp-wp_genesis 11
mp-wp_genesis 12 wp_reset_vars(array('revision', 'left', 'right', 'diff', 'action'));
mp-wp_genesis 13 $revision_id = absint($revision);
mp-wp_genesis 14 $diff = absint($diff);
mp-wp_genesis 15 $left = absint($left);
mp-wp_genesis 16 $right = absint($right);
mp-wp_genesis 17
mp-wp_genesis 18 $parent_file = $redirect = 'edit.php';
mp-wp_genesis 19
mp-wp_genesis 20 switch ( $action ) :
mp-wp_genesis 21 case 'delete' : // stubs
mp-wp_genesis 22 case 'edit' :
mp-wp_genesis 23 if ( constant('WP_POST_REVISIONS') ) // stub
mp-wp_genesis 24 $redirect = remove_query_arg( 'action' );
mp-wp_genesis 25 else // Revisions disabled
mp-wp_genesis 26 $redirect = 'edit.php';
mp-wp_genesis 27 break;
mp-wp_genesis 28 case 'restore' :
mp-wp_genesis 29 if ( !$revision = wp_get_post_revision( $revision_id ) )
mp-wp_genesis 30 break;
mp-wp_genesis 31 if ( !current_user_can( 'edit_post', $revision->post_parent ) )
mp-wp_genesis 32 break;
mp-wp_genesis 33 if ( !$post = get_post( $revision->post_parent ) )
mp-wp_genesis 34 break;
mp-wp_genesis 35
mp-wp_genesis 36 if ( !constant('WP_POST_REVISIONS') && !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave
mp-wp_genesis 37 break;
mp-wp_genesis 38
mp-wp_genesis 39 check_admin_referer( "restore-post_$post->ID|$revision->ID" );
mp-wp_genesis 40
mp-wp_genesis 41 wp_restore_post_revision( $revision->ID );
mp-wp_genesis 42 $redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) );
mp-wp_genesis 43 break;
mp-wp_genesis 44 case 'diff' :
mp-wp_genesis 45 if ( !$left_revision = get_post( $left ) )
mp-wp_genesis 46 break;
mp-wp_genesis 47 if ( !$right_revision = get_post( $right ) )
mp-wp_genesis 48 break;
mp-wp_genesis 49
mp-wp_genesis 50 if ( !current_user_can( 'read_post', $left_revision->ID ) || !current_user_can( 'read_post', $right_revision->ID ) )
mp-wp_genesis 51 break;
mp-wp_genesis 52
mp-wp_genesis 53 // If we're comparing a revision to itself, redirect to the 'view' page for that revision or the edit page for that post
mp-wp_genesis 54 if ( $left_revision->ID == $right_revision->ID ) {
mp-wp_genesis 55 $redirect = get_edit_post_link( $left_revision->ID );
mp-wp_genesis 56 include( 'js/revisions-js.php' );
mp-wp_genesis 57 break;
mp-wp_genesis 58 }
mp-wp_genesis 59
mp-wp_genesis 60 // Don't allow reverse diffs?
mp-wp_genesis 61 if ( strtotime($right_revision->post_modified_gmt) < strtotime($left_revision->post_modified_gmt) ) {
mp-wp_genesis 62 $redirect = add_query_arg( array( 'left' => $right, 'right' => $left ) );
mp-wp_genesis 63 break;
mp-wp_genesis 64 }
mp-wp_genesis 65
mp-wp_genesis 66 if ( $left_revision->ID == $right_revision->post_parent ) // right is a revision of left
mp-wp_genesis 67 $post =& $left_revision;
mp-wp_genesis 68 elseif ( $left_revision->post_parent == $right_revision->ID ) // left is a revision of right
mp-wp_genesis 69 $post =& $right_revision;
mp-wp_genesis 70 elseif ( $left_revision->post_parent == $right_revision->post_parent ) // both are revisions of common parent
mp-wp_genesis 71 $post = get_post( $left_revision->post_parent );
mp-wp_genesis 72 else
mp-wp_genesis 73 break; // Don't diff two unrelated revisions
mp-wp_genesis 74
mp-wp_genesis 75 if ( !constant('WP_POST_REVISIONS') ) { // Revisions disabled
mp-wp_genesis 76 if (
mp-wp_genesis 77 // we're not looking at an autosave
mp-wp_genesis 78 ( !wp_is_post_autosave( $left_revision ) && !wp_is_post_autosave( $right_revision ) )
mp-wp_genesis 79 ||
mp-wp_genesis 80 // we're not comparing an autosave to the current post
mp-wp_genesis 81 ( $post->ID !== $left_revision->ID && $post->ID !== $right_revision->ID )
mp-wp_genesis 82 )
mp-wp_genesis 83 break;
mp-wp_genesis 84 }
mp-wp_genesis 85
mp-wp_genesis 86 if (
mp-wp_genesis 87 // They're the same
mp-wp_genesis 88 $left_revision->ID == $right_revision->ID
mp-wp_genesis 89 ||
mp-wp_genesis 90 // Neither is a revision
mp-wp_genesis 91 ( !wp_get_post_revision( $left_revision->ID ) && !wp_get_post_revision( $right_revision->ID ) )
mp-wp_genesis 92 )
mp-wp_genesis 93 break;
mp-wp_genesis 94
mp-wp_genesis 95 $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
mp-wp_genesis 96 $h2 = sprintf( __( 'Compare Revisions of “%1$s”' ), $post_title );
mp-wp_genesis 97
mp-wp_genesis 98 $left = $left_revision->ID;
mp-wp_genesis 99 $right = $right_revision->ID;
mp-wp_genesis 100
mp-wp_genesis 101 $redirect = false;
mp-wp_genesis 102 break;
mp-wp_genesis 103 case 'view' :
mp-wp_genesis 104 default :
mp-wp_genesis 105 if ( !$revision = wp_get_post_revision( $revision_id ) )
mp-wp_genesis 106 break;
mp-wp_genesis 107 if ( !$post = get_post( $revision->post_parent ) )
mp-wp_genesis 108 break;
mp-wp_genesis 109
mp-wp_genesis 110 if ( !current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) )
mp-wp_genesis 111 break;
mp-wp_genesis 112
mp-wp_genesis 113 if ( !constant('WP_POST_REVISIONS') && !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave
mp-wp_genesis 114 break;
mp-wp_genesis 115
mp-wp_genesis 116 $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
mp-wp_genesis 117 $revision_title = wp_post_revision_title( $revision, false );
mp-wp_genesis 118 $h2 = sprintf( __( 'Post Revision for “%1$s” created on %2$s' ), $post_title, $revision_title );
mp-wp_genesis 119
mp-wp_genesis 120 // Sets up the diff radio buttons
mp-wp_genesis 121 $left = $revision->ID;
mp-wp_genesis 122 $right = $post->ID;
mp-wp_genesis 123
mp-wp_genesis 124 $redirect = false;
mp-wp_genesis 125 break;
mp-wp_genesis 126 endswitch;
mp-wp_genesis 127
mp-wp_genesis 128 if ( !$redirect && !in_array( $post->post_type, array( 'post', 'page' ) ) )
mp-wp_genesis 129 $redirect = 'edit.php';
mp-wp_genesis 130
mp-wp_genesis 131 if ( $redirect ) {
mp-wp_genesis 132 wp_redirect( $redirect );
mp-wp_genesis 133 exit;
mp-wp_genesis 134 }
mp-wp_genesis 135
mp-wp_genesis 136 if ( 'page' == $post->post_type ) {
mp-wp_genesis 137 $submenu_file = 'edit-pages.php';
mp-wp_genesis 138 $title = __( 'Page Revisions' );
mp-wp_genesis 139 } else {
mp-wp_genesis 140 $submenu_file = 'edit.php';
mp-wp_genesis 141 $title = __( 'Post Revisions' );
mp-wp_genesis 142 }
mp-wp_genesis 143
mp-wp_genesis 144 require_once( 'admin-header.php' );
mp-wp_genesis 145
mp-wp_genesis 146 ?>
mp-wp_genesis 147
mp-wp_genesis 148 <div class="wrap">
mp-wp_genesis 149
mp-wp_genesis 150 <h2 class="long-header"><?php echo $h2; ?></h2>
mp-wp_genesis 151
mp-wp_genesis 152 <table class="form-table ie-fixed">
mp-wp_genesis 153 <col class="th" />
mp-wp_genesis 154 <?php if ( 'diff' == $action ) : ?>
mp-wp_genesis 155 <tr id="revision">
mp-wp_genesis 156 <th scope="row"></th>
mp-wp_genesis 157 <th scope="col" class="th-full">
mp-wp_genesis 158 <span class="alignleft"><?php printf( __('Older: %s'), wp_post_revision_title( $left_revision ) ); ?></span>
mp-wp_genesis 159 <span class="alignright"><?php printf( __('Newer: %s'), wp_post_revision_title( $right_revision ) ); ?></span>
mp-wp_genesis 160 </th>
mp-wp_genesis 161 </tr>
mp-wp_genesis 162 <?php endif;
mp-wp_genesis 163
mp-wp_genesis 164 // use get_post_to_edit filters?
mp-wp_genesis 165 $identical = true;
mp-wp_genesis 166 foreach ( _wp_post_revision_fields() as $field => $field_title ) :
mp-wp_genesis 167 if ( 'diff' == $action ) {
mp-wp_genesis 168 $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field );
mp-wp_genesis 169 $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field );
mp-wp_genesis 170 if ( !$content = wp_text_diff( $left_content, $right_content ) )
mp-wp_genesis 171 continue; // There is no difference between left and right
mp-wp_genesis 172 $identical = false;
mp-wp_genesis 173 } else {
mp-wp_genesis 174 add_filter( "_wp_post_revision_field_$field", 'htmlspecialchars' );
mp-wp_genesis 175 $content = apply_filters( "_wp_post_revision_field_$field", $revision->$field, $field );
mp-wp_genesis 176 }
mp-wp_genesis 177 ?>
mp-wp_genesis 178
mp-wp_genesis 179 <tr id="revision-field-<?php echo $field; ?>">
mp-wp_genesis 180 <th scope="row"><?php echo wp_specialchars( $field_title ); ?></th>
mp-wp_genesis 181 <td><div class="pre"><?php echo $content; ?></div></td>
mp-wp_genesis 182 </tr>
mp-wp_genesis 183
mp-wp_genesis 184 <?php
mp-wp_genesis 185
mp-wp_genesis 186 endforeach;
mp-wp_genesis 187
mp-wp_genesis 188 if ( 'diff' == $action && $identical ) :
mp-wp_genesis 189
mp-wp_genesis 190 ?>
mp-wp_genesis 191
mp-wp_genesis 192 <tr><td colspan="2"><div class="updated"><p><?php _e( 'These revisions are identical.' ); ?></p></div></td></tr>
mp-wp_genesis 193
mp-wp_genesis 194 <?php
mp-wp_genesis 195
mp-wp_genesis 196 endif;
mp-wp_genesis 197
mp-wp_genesis 198 ?>
mp-wp_genesis 199
mp-wp_genesis 200 </table>
mp-wp_genesis 201
mp-wp_genesis 202 <br class="clear" />
mp-wp_genesis 203
mp-wp_genesis 204 <h2><?php echo $title; ?></h2>
mp-wp_genesis 205
mp-wp_genesis 206 <?php
mp-wp_genesis 207
mp-wp_genesis 208 $args = array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left );
mp-wp_genesis 209 if ( !constant( 'WP_POST_REVISIONS' ) )
mp-wp_genesis 210 $args['type'] = 'autosave';
mp-wp_genesis 211
mp-wp_genesis 212 wp_list_post_revisions( $post, $args );
mp-wp_genesis 213
mp-wp_genesis 214 ?>
mp-wp_genesis 215
mp-wp_genesis 216 </div>
mp-wp_genesis 217
mp-wp_genesis 218 <?php
mp-wp_genesis 219
mp-wp_genesis 220 require_once( 'admin-footer.php' );