5 * @package WordPress |
5 * @package WordPress |
6 * @subpackage Administration |
6 * @subpackage Administration |
7 */ |
7 */ |
8 |
8 |
9 /** WordPress Administration Bootstrap */ |
9 /** WordPress Administration Bootstrap */ |
10 require_once('admin.php'); |
10 require_once('./admin.php'); |
11 |
11 |
12 wp_reset_vars(array('revision', 'left', 'right', 'diff', 'action')); |
12 wp_enqueue_script('list-revisions'); |
|
13 |
|
14 wp_reset_vars(array('revision', 'left', 'right', 'action')); |
|
15 |
13 $revision_id = absint($revision); |
16 $revision_id = absint($revision); |
14 $diff = absint($diff); |
|
15 $left = absint($left); |
17 $left = absint($left); |
16 $right = absint($right); |
18 $right = absint($right); |
17 |
19 |
18 $parent_file = $redirect = 'edit.php'; |
20 $redirect = 'edit.php'; |
19 |
21 |
20 switch ( $action ) : |
22 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' : |
23 case 'restore' : |
29 if ( !$revision = wp_get_post_revision( $revision_id ) ) |
24 if ( !$revision = wp_get_post_revision( $revision_id ) ) |
30 break; |
25 break; |
31 if ( !current_user_can( 'edit_post', $revision->post_parent ) ) |
26 if ( !current_user_can( 'edit_post', $revision->post_parent ) ) |
32 break; |
27 break; |
33 if ( !$post = get_post( $revision->post_parent ) ) |
28 if ( !$post = get_post( $revision->post_parent ) ) |
34 break; |
29 break; |
35 |
30 |
36 if ( !constant('WP_POST_REVISIONS') && !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave |
31 // Revisions disabled and we're not looking at an autosave |
37 break; |
32 if ( ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) { |
|
33 $redirect = 'edit.php?post_type=' . $post->post_type; |
|
34 break; |
|
35 } |
38 |
36 |
39 check_admin_referer( "restore-post_$post->ID|$revision->ID" ); |
37 check_admin_referer( "restore-post_$post->ID|$revision->ID" ); |
40 |
38 |
41 wp_restore_post_revision( $revision->ID ); |
39 wp_restore_post_revision( $revision->ID ); |
42 $redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) ); |
40 $redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) ); |
51 break; |
49 break; |
52 |
50 |
53 // If we're comparing a revision to itself, redirect to the 'view' page for that revision or the edit page for that post |
51 // 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 ) { |
52 if ( $left_revision->ID == $right_revision->ID ) { |
55 $redirect = get_edit_post_link( $left_revision->ID ); |
53 $redirect = get_edit_post_link( $left_revision->ID ); |
56 include( 'js/revisions-js.php' ); |
54 include( './js/revisions-js.php' ); |
57 break; |
55 break; |
58 } |
56 } |
59 |
57 |
60 // Don't allow reverse diffs? |
58 // Don't allow reverse diffs? |
61 if ( strtotime($right_revision->post_modified_gmt) < strtotime($left_revision->post_modified_gmt) ) { |
59 if ( strtotime($right_revision->post_modified_gmt) < strtotime($left_revision->post_modified_gmt) ) { |
70 elseif ( $left_revision->post_parent == $right_revision->post_parent ) // both are revisions of common parent |
68 elseif ( $left_revision->post_parent == $right_revision->post_parent ) // both are revisions of common parent |
71 $post = get_post( $left_revision->post_parent ); |
69 $post = get_post( $left_revision->post_parent ); |
72 else |
70 else |
73 break; // Don't diff two unrelated revisions |
71 break; // Don't diff two unrelated revisions |
74 |
72 |
75 if ( !constant('WP_POST_REVISIONS') ) { // Revisions disabled |
73 if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) { // Revisions disabled |
76 if ( |
74 if ( |
77 // we're not looking at an autosave |
75 // we're not looking at an autosave |
78 ( !wp_is_post_autosave( $left_revision ) && !wp_is_post_autosave( $right_revision ) ) |
76 ( !wp_is_post_autosave( $left_revision ) && !wp_is_post_autosave( $right_revision ) ) |
79 || |
77 || |
80 // we're not comparing an autosave to the current post |
78 // we're not comparing an autosave to the current post |
81 ( $post->ID !== $left_revision->ID && $post->ID !== $right_revision->ID ) |
79 ( $post->ID !== $left_revision->ID && $post->ID !== $right_revision->ID ) |
82 ) |
80 ) { |
|
81 $redirect = 'edit.php?post_type=' . $post->post_type; |
83 break; |
82 break; |
|
83 } |
84 } |
84 } |
85 |
85 |
86 if ( |
86 if ( |
87 // They're the same |
87 // They're the same |
88 $left_revision->ID == $right_revision->ID |
88 $left_revision->ID == $right_revision->ID |
92 ) |
92 ) |
93 break; |
93 break; |
94 |
94 |
95 $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>'; |
95 $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>'; |
96 $h2 = sprintf( __( 'Compare Revisions of “%1$s”' ), $post_title ); |
96 $h2 = sprintf( __( 'Compare Revisions of “%1$s”' ), $post_title ); |
|
97 $title = __( 'Revisions' ); |
97 |
98 |
98 $left = $left_revision->ID; |
99 $left = $left_revision->ID; |
99 $right = $right_revision->ID; |
100 $right = $right_revision->ID; |
100 |
101 |
101 $redirect = false; |
102 $redirect = false; |
108 break; |
109 break; |
109 |
110 |
110 if ( !current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) ) |
111 if ( !current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) ) |
111 break; |
112 break; |
112 |
113 |
113 if ( !constant('WP_POST_REVISIONS') && !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave |
114 // Revisions disabled and we're not looking at an autosave |
114 break; |
115 if ( ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) { |
|
116 $redirect = 'edit.php?post_type=' . $post->post_type; |
|
117 break; |
|
118 } |
115 |
119 |
116 $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>'; |
120 $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>'; |
117 $revision_title = wp_post_revision_title( $revision, false ); |
121 $revision_title = wp_post_revision_title( $revision, false ); |
118 $h2 = sprintf( __( 'Post Revision for “%1$s” created on %2$s' ), $post_title, $revision_title ); |
122 $h2 = sprintf( __( 'Revision for “%1$s” created on %2$s' ), $post_title, $revision_title ); |
|
123 $title = __( 'Revisions' ); |
119 |
124 |
120 // Sets up the diff radio buttons |
125 // Sets up the diff radio buttons |
121 $left = $revision->ID; |
126 $left = $revision->ID; |
122 $right = $post->ID; |
127 $right = $post->ID; |
123 |
128 |
124 $redirect = false; |
129 $redirect = false; |
125 break; |
130 break; |
126 endswitch; |
131 endswitch; |
127 |
132 |
128 if ( !$redirect && !in_array( $post->post_type, array( 'post', 'page' ) ) ) |
133 // Empty post_type means either malformed object found, or no valid parent was found. |
|
134 if ( !$redirect && empty($post->post_type) ) |
129 $redirect = 'edit.php'; |
135 $redirect = 'edit.php'; |
130 |
136 |
131 if ( $redirect ) { |
137 if ( !empty($redirect) ) { |
132 wp_redirect( $redirect ); |
138 wp_redirect( $redirect ); |
133 exit; |
139 exit; |
134 } |
140 } |
135 |
141 |
136 if ( 'page' == $post->post_type ) { |
142 // This is so that the correct "Edit" menu item is selected. |
137 $submenu_file = 'edit-pages.php'; |
143 if ( !empty($post->post_type) && 'post' != $post->post_type ) |
138 $title = __( 'Page Revisions' ); |
144 $parent_file = $submenu_file = 'edit.php?post_type=' . $post->post_type; |
139 } else { |
145 else |
140 $submenu_file = 'edit.php'; |
146 $parent_file = $submenu_file = 'edit.php'; |
141 $title = __( 'Post Revisions' ); |
147 |
142 } |
148 require_once( './admin-header.php' ); |
143 |
|
144 require_once( 'admin-header.php' ); |
|
145 |
149 |
146 ?> |
150 ?> |
147 |
151 |
148 <div class="wrap"> |
152 <div class="wrap"> |
149 |
153 |
199 |
203 |
200 </table> |
204 </table> |
201 |
205 |
202 <br class="clear" /> |
206 <br class="clear" /> |
203 |
207 |
204 <h2><?php echo $title; ?></h2> |
208 <h3><?php echo $title; ?></h3> |
205 |
209 |
206 <?php |
210 <?php |
207 |
211 |
208 $args = array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left ); |
212 $args = array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left ); |
209 if ( !constant( 'WP_POST_REVISIONS' ) ) |
213 if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) |
210 $args['type'] = 'autosave'; |
214 $args['type'] = 'autosave'; |
211 |
215 |
212 wp_list_post_revisions( $post, $args ); |
216 wp_list_post_revisions( $post, $args ); |
213 |
217 |
214 ?> |
218 ?> |
215 |
219 |
216 </div> |
220 </div> |
217 |
221 |
218 <?php |
222 <?php |
219 |
223 require_once( './admin-footer.php' ); |
220 require_once( 'admin-footer.php' ); |
|