]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/revision.php
Wordpress 2.8.5-scripts
[autoinstalls/wordpress.git] / wp-admin / revision.php
1 <?php
2 /**
3  * Revisions administration panel.
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /** WordPress Administration Bootstrap */
10 require_once('admin.php');
11
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);
17
18 $parent_file = $redirect = 'edit.php';
19
20 switch ( $action ) :
21 case 'delete' : // stubs
22 case 'edit' :
23         if ( constant('WP_POST_REVISIONS') ) // stub
24                 $redirect = remove_query_arg( 'action' );
25         else // Revisions disabled
26                 $redirect = 'edit.php';
27         break;
28 case 'restore' :
29         if ( !$revision = wp_get_post_revision( $revision_id ) )
30                 break;
31         if ( !current_user_can( 'edit_post', $revision->post_parent ) )
32                 break;
33         if ( !$post = get_post( $revision->post_parent ) )
34                 break;
35
36         if ( !constant('WP_POST_REVISIONS') && !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave
37                 break;
38
39         check_admin_referer( "restore-post_$post->ID|$revision->ID" );
40
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' ) );
43         break;
44 case 'diff' :
45         if ( !$left_revision  = get_post( $left ) )
46                 break;
47         if ( !$right_revision = get_post( $right ) )
48                 break;
49
50         if ( !current_user_can( 'read_post', $left_revision->ID ) || !current_user_can( 'read_post', $right_revision->ID ) )
51                 break;
52
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' );
57                 break;
58         }
59
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 ) );
63                 break;
64         }
65
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 );
72         else
73                 break; // Don't diff two unrelated revisions
74
75         if ( !constant('WP_POST_REVISIONS') ) { // Revisions disabled
76                 if (
77                         // we're not looking at an autosave
78                         ( !wp_is_post_autosave( $left_revision ) && !wp_is_post_autosave( $right_revision ) )
79                 ||
80                         // we're not comparing an autosave to the current post
81                         ( $post->ID !== $left_revision->ID && $post->ID !== $right_revision->ID )
82                 )
83                         break;
84         }
85
86         if (
87                 // They're the same
88                 $left_revision->ID == $right_revision->ID
89         ||
90                 // Neither is a revision
91                 ( !wp_get_post_revision( $left_revision->ID ) && !wp_get_post_revision( $right_revision->ID ) )
92         )
93                 break;
94
95         $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
96         $h2 = sprintf( __( 'Compare Revisions of &#8220;%1$s&#8221;' ), $post_title );
97
98         $left  = $left_revision->ID;
99         $right = $right_revision->ID;
100
101         $redirect = false;
102         break;
103 case 'view' :
104 default :
105         if ( !$revision = wp_get_post_revision( $revision_id ) )
106                 break;
107         if ( !$post = get_post( $revision->post_parent ) )
108                 break;
109
110         if ( !current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) )
111                 break;
112
113         if ( !constant('WP_POST_REVISIONS') && !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave
114                 break;
115
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 &#8220;%1$s&#8221; created on %2$s' ), $post_title, $revision_title );
119
120         // Sets up the diff radio buttons
121         $left  = $revision->ID;
122         $right = $post->ID;
123
124         $redirect = false;
125         break;
126 endswitch;
127
128 if ( !$redirect && !in_array( $post->post_type, array( 'post', 'page' ) ) )
129         $redirect = 'edit.php';
130
131 if ( $redirect ) {
132         wp_redirect( $redirect );
133         exit;
134 }
135
136 if ( 'page' == $post->post_type ) {
137         $submenu_file = 'edit-pages.php';
138         $title = __( 'Page Revisions' );
139 } else {
140         $submenu_file = 'edit.php';
141         $title = __( 'Post Revisions' );
142 }
143
144 require_once( 'admin-header.php' );
145
146 ?>
147
148 <div class="wrap">
149
150 <h2 class="long-header"><?php echo $h2; ?></h2>
151
152 <table class="form-table ie-fixed">
153         <col class="th" />
154 <?php if ( 'diff' == $action ) : ?>
155 <tr id="revision">
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>
160         </th>
161 </tr>
162 <?php endif;
163
164 // use get_post_to_edit filters?
165 $identical = true;
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
172                 $identical = false;
173         } else {
174                 add_filter( "_wp_post_revision_field_$field", 'htmlspecialchars' );
175                 $content = apply_filters( "_wp_post_revision_field_$field", $revision->$field, $field );
176         }
177         ?>
178
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>
182         </tr>
183
184         <?php
185
186 endforeach;
187
188 if ( 'diff' == $action && $identical ) :
189
190         ?>
191
192         <tr><td colspan="2"><div class="updated"><p><?php _e( 'These revisions are identical.' ); ?></p></div></td></tr>
193
194         <?php
195
196 endif;
197
198 ?>
199
200 </table>
201
202 <br class="clear" />
203
204 <h2><?php echo $title; ?></h2>
205
206 <?php
207
208 $args = array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left );
209 if ( !constant( 'WP_POST_REVISIONS' ) )
210         $args['type'] = 'autosave';
211
212 wp_list_post_revisions( $post, $args );
213
214 ?>
215
216 </div>
217
218 <?php
219
220 require_once( 'admin-footer.php' );