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