Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 224 lines (173 sloc) 6.667 kB
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
1 <?php
c19b2d7 More phpdoc updates for wp-adming. See #7496 props santosj.
westi authored
2 /**
3 * Revisions administration panel.
4 *
5 * @package WordPress
6 * @subpackage Administration
7 */
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
8
c19b2d7 More phpdoc updates for wp-adming. See #7496 props santosj.
westi authored
9 /** WordPress Administration Bootstrap */
6ec7cb4 Use relative paths when including files, avoiding include_path. fixes…
nacin authored
10 require_once('./admin.php');
7ec819d Improve the revision comparison user interface to hilight that we com…
westi authored
11
12 wp_enqueue_script('list-revisions');
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
13
caf573b Fix viewing autosave revision for custom post types. Props duck_. fix…
ryan authored
14 wp_reset_vars(array('revision', 'left', 'right', 'action'));
7f34057 Introduce Revisioning for custom Post Types, Introduce 'supports' arg…
dd32 authored
15
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
16 $revision_id = absint($revision);
17 $left = absint($left);
18 $right = absint($right);
19
7f34057 Introduce Revisioning for custom Post Types, Introduce 'supports' arg…
dd32 authored
20 $redirect = 'edit.php';
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
21
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
22 switch ( $action ) :
23 case 'restore' :
0db872b Post revisions API cleanup from mdawaffe. see #6775
ryan authored
24 if ( !$revision = wp_get_post_revision( $revision_id ) )
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
25 break;
0db872b Post revisions API cleanup from mdawaffe. see #6775
ryan authored
26 if ( !current_user_can( 'edit_post', $revision->post_parent ) )
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
27 break;
28 if ( !$post = get_post( $revision->post_parent ) )
29 break;
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
30
caf573b Fix viewing autosave revision for custom post types. Props duck_. fix…
ryan authored
31 // Revisions disabled and we're not looking at an autosave
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;
0db872b Post revisions API cleanup from mdawaffe. see #6775
ryan authored
34 break;
caf573b Fix viewing autosave revision for custom post types. Props duck_. fix…
ryan authored
35 }
0db872b Post revisions API cleanup from mdawaffe. see #6775
ryan authored
36
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
37 check_admin_referer( "restore-post_$post->ID|$revision->ID" );
38
0db872b Post revisions API cleanup from mdawaffe. see #6775
ryan authored
39 wp_restore_post_revision( $revision->ID );
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
40 $redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) );
41 break;
42 case 'diff' :
43 if ( !$left_revision = get_post( $left ) )
44 break;
45 if ( !$right_revision = get_post( $right ) )
46 break;
47
3c8cb2b Revisioning for pages from mdawaffe. see #6775
ryan authored
48 if ( !current_user_can( 'read_post', $left_revision->ID ) || !current_user_can( 'read_post', $right_revision->ID ) )
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
49 break;
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
50
4f77631 better handling of comparing a revision to itself. Props mdawaffe. se…
ryan authored
51 // If we're comparing a revision to itself, redirect to the 'view' page for that revision or the edit page for that post
52 if ( $left_revision->ID == $right_revision->ID ) {
53 $redirect = get_edit_post_link( $left_revision->ID );
6ec7cb4 Use relative paths when including files, avoiding include_path. fixes…
nacin authored
54 include( './js/revisions-js.php' );
4f77631 better handling of comparing a revision to itself. Props mdawaffe. se…
ryan authored
55 break;
56 }
57
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
58 // Don't allow reverse diffs?
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
59 if ( strtotime($right_revision->post_modified_gmt) < strtotime($left_revision->post_modified_gmt) ) {
60 $redirect = add_query_arg( array( 'left' => $right, 'right' => $left ) );
61 break;
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
62 }
63
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
64 if ( $left_revision->ID == $right_revision->post_parent ) // right is a revision of left
65 $post =& $left_revision;
66 elseif ( $left_revision->post_parent == $right_revision->ID ) // left is a revision of right
67 $post =& $right_revision;
68 elseif ( $left_revision->post_parent == $right_revision->post_parent ) // both are revisions of common parent
69 $post = get_post( $left_revision->post_parent );
70 else
71 break; // Don't diff two unrelated revisions
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
72
caf573b Fix viewing autosave revision for custom post types. Props duck_. fix…
ryan authored
73 if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) { // Revisions disabled
0db872b Post revisions API cleanup from mdawaffe. see #6775
ryan authored
74 if (
75 // we're not looking at an autosave
76 ( !wp_is_post_autosave( $left_revision ) && !wp_is_post_autosave( $right_revision ) )
77 ||
78 // we're not comparing an autosave to the current post
79 ( $post->ID !== $left_revision->ID && $post->ID !== $right_revision->ID )
caf573b Fix viewing autosave revision for custom post types. Props duck_. fix…
ryan authored
80 ) {
81 $redirect = 'edit.php?post_type=' . $post->post_type;
0db872b Post revisions API cleanup from mdawaffe. see #6775
ryan authored
82 break;
caf573b Fix viewing autosave revision for custom post types. Props duck_. fix…
ryan authored
83 }
0db872b Post revisions API cleanup from mdawaffe. see #6775
ryan authored
84 }
85
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
86 if (
87 // They're the same
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
88 $left_revision->ID == $right_revision->ID
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
89 ||
90 // Neither is a revision
0db872b Post revisions API cleanup from mdawaffe. see #6775
ryan authored
91 ( !wp_get_post_revision( $left_revision->ID ) && !wp_get_post_revision( $right_revision->ID ) )
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
92 )
93 break;
35b18e5 Trailing whitespace cleanup
ryan authored
94
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
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 );
caf573b Fix viewing autosave revision for custom post types. Props duck_. fix…
ryan authored
97 $title = __( 'Revisions' );
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
98
99 $left = $left_revision->ID;
100 $right = $right_revision->ID;
101
102 $redirect = false;
103 break;
104 case 'view' :
105 default :
0db872b Post revisions API cleanup from mdawaffe. see #6775
ryan authored
106 if ( !$revision = wp_get_post_revision( $revision_id ) )
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
107 break;
108 if ( !$post = get_post( $revision->post_parent ) )
109 break;
110
3c8cb2b Revisioning for pages from mdawaffe. see #6775
ryan authored
111 if ( !current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) )
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
112 break;
113
caf573b Fix viewing autosave revision for custom post types. Props duck_. fix…
ryan authored
114 // Revisions disabled and we're not looking at an autosave
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;
0db872b Post revisions API cleanup from mdawaffe. see #6775
ryan authored
117 break;
caf573b Fix viewing autosave revision for custom post types. Props duck_. fix…
ryan authored
118 }
7f34057 Introduce Revisioning for custom Post Types, Introduce 'supports' arg…
dd32 authored
119
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
120 $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
121 $revision_title = wp_post_revision_title( $revision, false );
7f34057 Introduce Revisioning for custom Post Types, Introduce 'supports' arg…
dd32 authored
122 $h2 = sprintf( __( 'Revision for &#8220;%1$s&#8221; created on %2$s' ), $post_title, $revision_title );
123 $title = __( 'Revisions' );
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
124
125 // Sets up the diff radio buttons
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
126 $left = $revision->ID;
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
127 $right = $post->ID;
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
128
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
129 $redirect = false;
130 break;
131 endswitch;
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
132
caf573b Fix viewing autosave revision for custom post types. Props duck_. fix…
ryan authored
133 // Empty post_type means either malformed object found, or no valid parent was found.
134 if ( !$redirect && empty($post->post_type) )
135 $redirect = 'edit.php';
3c8cb2b Revisioning for pages from mdawaffe. see #6775
ryan authored
136
7f34057 Introduce Revisioning for custom Post Types, Introduce 'supports' arg…
dd32 authored
137 if ( !empty($redirect) ) {
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
138 wp_redirect( $redirect );
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
139 exit;
140 }
141
7f34057 Introduce Revisioning for custom Post Types, Introduce 'supports' arg…
dd32 authored
142 // This is so that the correct "Edit" menu item is selected.
143 if ( !empty($post->post_type) && 'post' != $post->post_type )
144 $parent_file = $submenu_file = 'edit.php?post_type=' . $post->post_type;
145 else
146 $parent_file = $submenu_file = 'edit.php';
3c8cb2b Revisioning for pages from mdawaffe. see #6775
ryan authored
147
6ec7cb4 Use relative paths when including files, avoiding include_path. fixes…
nacin authored
148 require_once( './admin-header.php' );
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
149
150 ?>
151
152 <div class="wrap">
153
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
154 <h2 class="long-header"><?php echo $h2; ?></h2>
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
155
156 <table class="form-table ie-fixed">
157 <col class="th" />
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
158 <?php if ( 'diff' == $action ) : ?>
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
159 <tr id="revision">
160 <th scope="row"></th>
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
161 <th scope="col" class="th-full">
162 <span class="alignleft"><?php printf( __('Older: %s'), wp_post_revision_title( $left_revision ) ); ?></span>
163 <span class="alignright"><?php printf( __('Newer: %s'), wp_post_revision_title( $right_revision ) ); ?></span>
18fb540 Validation fixes for post revisions. Props mdawaffe. see #6775
ryan authored
164 </th>
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
165 </tr>
166 <?php endif;
167
35b18e5 Trailing whitespace cleanup
ryan authored
168 // use get_post_to_edit filters?
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
169 $identical = true;
0db872b Post revisions API cleanup from mdawaffe. see #6775
ryan authored
170 foreach ( _wp_post_revision_fields() as $field => $field_title ) :
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
171 if ( 'diff' == $action ) {
0db872b Post revisions API cleanup from mdawaffe. see #6775
ryan authored
172 $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field );
173 $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field );
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
174 if ( !$content = wp_text_diff( $left_content, $right_content ) )
175 continue; // There is no difference between left and right
176 $identical = false;
177 } else {
0db872b Post revisions API cleanup from mdawaffe. see #6775
ryan authored
178 add_filter( "_wp_post_revision_field_$field", 'htmlspecialchars' );
179 $content = apply_filters( "_wp_post_revision_field_$field", $revision->$field, $field );
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
180 }
181 ?>
182
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
183 <tr id="revision-field-<?php echo $field; ?>">
119b39c deprecate wp_specialchars() in favor of esc_html(). Encode quotes for…
markjaquith authored
184 <th scope="row"><?php echo esc_html( $field_title ); ?></th>
18fb540 Validation fixes for post revisions. Props mdawaffe. see #6775
ryan authored
185 <td><div class="pre"><?php echo $content; ?></div></td>
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
186 </tr>
187
188 <?php
189
190 endforeach;
191
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
192 if ( 'diff' == $action && $identical ) :
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
193
194 ?>
195
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
196 <tr><td colspan="2"><div class="updated"><p><?php _e( 'These revisions are identical.' ); ?></p></div></td></tr>
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
197
198 <?php
199
200 endif;
201
202 ?>
203
204 </table>
205
206 <br class="clear" />
207
71d4760 Mid-page headers should be h3, not h2.
nacin authored
208 <h3><?php echo $title; ?></h3>
35086b8 Post revisions from mdawaffe. see #6775
ryan authored
209
210 <?php
211
0db872b Post revisions API cleanup from mdawaffe. see #6775
ryan authored
212 $args = array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left );
caf573b Fix viewing autosave revision for custom post types. Props duck_. fix…
ryan authored
213 if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') )
0db872b Post revisions API cleanup from mdawaffe. see #6775
ryan authored
214 $args['type'] = 'autosave';
215
216 wp_list_post_revisions( $post, $args );
129d030 Move autosave to post revisions. Props mdawaffe. see #6775
ryan authored
217
18fb540 Validation fixes for post revisions. Props mdawaffe. see #6775
ryan authored
218 ?>
219
220 </div>
221
222 <?php
6ec7cb4 Use relative paths when including files, avoiding include_path. fixes…
nacin authored
223 require_once( './admin-footer.php' );
Something went wrong with that request. Please try again.