Changeset 7907 for trunk/wp-admin/revision.php
- Timestamp:
- 05/08/2008 05:25:07 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/wp-admin/revision.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/revision.php
r7747 r7907 3 3 require_once('admin.php'); 4 4 5 $parent_file = 'edit.php'; 6 $submenu_file = 'edit.php'; 7 8 wp_reset_vars(array('revision', 'diff', 'restore')); 9 5 wp_reset_vars(array('revision', 'left', 'right', 'action')); 10 6 $revision_id = absint($revision); 11 7 $diff = absint($diff); 8 $left = absint($left); 9 $right = absint($right); 12 10 13 if ( $diff ) { 14 $restore = false; 15 $revision = get_post( $revision_id ); 16 $post = 'revision' == $revision->post_type ? get_post( $revision->post_parent ) : get_post( $revision_id ); 17 $left_revision = get_post( $diff ); 11 12 $parent_file = $redirect = 'edit.php'; 13 $submenu_file = 'edit.php'; 14 $title = __( 'Post Revision' ); 15 16 17 switch ( $action ) : 18 case 'delete' : // stubs 19 case 'edit' : 20 $redirect = remove_query_arg( 'action' ); 21 break; 22 case 'restore' : 23 if ( !current_user_can( 'edit_post', $revision->post_parent ) ) 24 break; 25 if ( !$revision = wp_get_revision( $revision_id ) ) 26 break; 27 if ( !$post = get_post( $revision->post_parent ) ) 28 break; 29 30 check_admin_referer( "restore-post_$post->ID|$revision->ID" ); 31 32 wp_restore_revision( $revision->ID ); 33 $redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) ); 34 break; 35 case 'diff' : 36 if ( !$left_revision = get_post( $left ) ) 37 break; 38 if ( !$right_revision = get_post( $right ) ) 39 break; 40 41 if ( !current_user_can( 'edit_post', $left_revision->ID ) || !current_user_can( 'edit_post', $right_revision->ID ) ) 42 break; 18 43 19 44 // Don't allow reverse diffs? 20 if ( strtotime($r evision->post_modified_gmt) < strtotime($left_revision->post_modified_gmt) ) {21 wp_redirect( add_query_arg( array( 'diff' => $revision->ID, 'revision' => $diff )) );22 exit;45 if ( strtotime($right_revision->post_modified_gmt) < strtotime($left_revision->post_modified_gmt) ) { 46 $redirect = add_query_arg( array( 'left' => $right, 'right' => $left ) ); 47 break; 23 48 } 24 49 25 $h2 = __( 'Compare Revisions of “%1$s”' ); 26 $right = $revision->ID; 27 $left = $left_revision->ID; 50 if ( $left_revision->ID == $right_revision->post_parent ) // right is a revision of left 51 $post =& $left_revision; 52 elseif ( $left_revision->post_parent == $right_revision->ID ) // left is a revision of right 53 $post =& $right_revision; 54 elseif ( $left_revision->post_parent == $right_revision->post_parent ) // both are revisions of common parent 55 $post = get_post( $left_revision->post_parent ); 56 else 57 break; // Don't diff two unrelated revisions 28 58 29 59 if ( 30 60 // They're the same 31 $left_revision->ID == $revision->ID 32 || 33 // They don't have a comment parent (and we're not comparing a revision to it's post) 34 ( $left_revision->ID != $revision->post_parent && $left_revision->post_parent != $revision->ID && $left_revision->post_parent != $revision->post_parent ) 61 $left_revision->ID == $right_revision->ID 35 62 || 36 63 // Neither is a revision 37 ( !wp_get_revision( $left_revision->ID ) && !wp_get_revision( $revision->ID ) ) 38 ) { 39 wp_redirect( get_edit_post_link( $revision->ID, 'url' ) ); 40 exit(); 41 } 42 } else { 43 $revision = wp_get_revision( $revision_id ); 44 $post = get_post( $revision->post_parent ); 45 $h2 = __( 'Post Revision for “%1$s” created on %2$s' ); 64 ( !wp_get_revision( $left_revision->ID ) && !wp_get_revision( $right_revision->ID ) ) 65 ) 66 break; 67 68 $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>'; 69 $h2 = sprintf( __( 'Compare Revisions of “%1$s”' ), $post_title ); 70 71 $left = $left_revision->ID; 72 $right = $right_revision->ID; 73 74 $redirect = false; 75 break; 76 case 'view' : 77 default : 78 if ( !$revision = wp_get_revision( $revision_id ) ) 79 break; 80 if ( !$post = get_post( $revision->post_parent ) ) 81 break; 82 83 if ( !current_user_can( 'edit_post', $revision->ID ) || !current_user_can( 'edit_post', $post->ID ) ) 84 break; 85 86 $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>'; 87 $revision_title = wp_post_revision_title( $revision, false ); 88 $h2 = sprintf( __( 'Post Revision for “%1$s” created on %2$s' ), $post_title, $revision_title ); 89 90 // Sets up the diff radio buttons 91 $left = $revision->ID; 46 92 $right = $post->ID; 47 $left = $revision->ID;48 }49 93 50 if ( !$revision || !$post ) { 51 wp_redirect("edit.php"); 52 exit(); 53 } 94 $redirect = false; 95 break; 96 endswitch; 54 97 55 if ( $restore && current_user_can( 'edit_post', $revision->post_parent ) ) { 56 check_admin_referer( "restore-post_$post->ID|$revision->ID" ); 57 wp_restore_revision( $revision->ID ); 58 wp_redirect( add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) ) ); 98 if ( $redirect ) { 99 wp_redirect( $redirect ); 59 100 exit; 60 101 } 61 102 103 // Converts post_author ID# into name 62 104 add_filter( '_wp_revision_field_post_author', 'get_author_name' ); 63 64 $title = __( 'Post Revision' );65 105 66 106 require_once( 'admin-header.php' ); 67 107 68 $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';69 $revision_time = wp_post_revision_time( $revision );70 108 ?> 71 109 72 110 <div class="wrap"> 73 111 74 <h2 style="padding-right: 0"><?php printf( $h2, $post_title, $revision_time ); ?></h2>112 <h2 class="long-header"><?php echo $h2; ?></h2> 75 113 76 114 <table class="form-table ie-fixed"> 77 115 <col class="th" /> 78 <?php if ( $diff ) : ?> 79 116 <?php if ( 'diff' == $action ) : ?> 80 117 <tr id="revision"> 81 118 <th scope="row"></th> 82 <th scope="col" class="th-full"><?php printf( __('Older: %s'), wp_post_revision_time( $left_revision ) ); ?></td> 83 <th scope="col" class="th-full"><?php printf( __('Newer: %s'), wp_post_revision_time( $revision ) ); ?></td> 119 <th scope="col" class="th-full"> 120 <span class="alignleft"><?php printf( __('Older: %s'), wp_post_revision_title( $left_revision ) ); ?></span> 121 <span class="alignright"><?php printf( __('Newer: %s'), wp_post_revision_title( $right_revision ) ); ?></span> 122 </td> 84 123 </tr> 85 86 124 <?php endif; 87 125 88 // use get_post_to_edit ?126 // use get_post_to_edit filters? 89 127 $identical = true; 90 128 foreach ( _wp_revision_fields() as $field => $field_title ) : 91 if ( !$diff ) 129 if ( 'diff' == $action ) { 130 $left_content = apply_filters( "_wp_revision_field_$field", $left_revision->$field, $field ); 131 $right_content = apply_filters( "_wp_revision_field_$field", $right_revision->$field, $field ); 132 if ( !$content = wp_text_diff( $left_content, $right_content ) ) 133 continue; // There is no difference between left and right 134 $identical = false; 135 } else { 92 136 add_filter( "_wp_revision_field_$field", 'htmlspecialchars' ); 93 $content = apply_filters( "_wp_revision_field_$field", $revision->$field, $field ); 94 if ( $diff ) { 95 $left_content = apply_filters( "_wp_revision_field_$field", $left_revision->$field, $field ); 96 if ( !$content = wp_text_diff( $left_content, $content ) ) 97 continue; 137 $content = apply_filters( "_wp_revision_field_$field", $revision->$field, $field ); 98 138 } 99 $identical = false;100 139 ?> 101 140 102 <tr id="revision-field-<?php echo $field; ?>" ?>141 <tr id="revision-field-<?php echo $field; ?>"> 103 142 <th scope="row"><?php echo wp_specialchars( $field_title ); ?></th> 104 <td colspan="2"><pre><?php echo $content; ?></pre></td>143 <td><pre><?php echo $content; ?></pre></td> 105 144 </tr> 106 145 … … 109 148 endforeach; 110 149 111 if ( $diff&& $identical ) :150 if ( 'diff' == $action && $identical ) : 112 151 113 152 ?> 114 153 115 <tr><td colspan=" 3"><div class="updated"><p><?php _e( 'These revisions are identical' ); ?></p></div></td></tr>154 <tr><td colspan="2"><div class="updated"><p><?php _e( 'These revisions are identical.' ); ?></p></div></td></tr> 116 155 117 156 <?php … … 128 167 129 168 <?php 130 wp_list_post_revisions( $post, array( 'format' => 'form-table', 'exclude' => $revision->ID, 'parent' => true, 'right' => $right, 'left' => $left ) );131 169 132 require_once( 'admin-footer.php' ); 170 wp_list_post_revisions( $post, array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left ) ); 171 172 require_once( 'admin-footer.php' );
Note: See TracChangeset
for help on using the changeset viewer.