]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/revision.php
WordPress 3.6.1-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 require ABSPATH . 'wp-admin/includes/revision.php';
13
14 wp_reset_vars( array( 'revision', 'action', 'from', 'to' ) );
15
16 $revision_id = absint( $revision );
17
18 $from = is_numeric( $from ) ? absint( $from ) : null;
19 if ( ! $revision_id )
20         $revision_id = absint( $to );
21 $redirect = 'edit.php';
22
23 switch ( $action ) :
24 case 'restore' :
25         if ( ! $revision = wp_get_post_revision( $revision_id ) )
26                 break;
27
28         if ( ! current_user_can( 'edit_post', $revision->post_parent ) )
29                 break;
30
31         if ( ! $post = get_post( $revision->post_parent ) )
32                 break;
33
34         // Revisions disabled (previously checked autosaves && ! wp_is_post_autosave( $revision ))
35         if ( ! wp_revisions_enabled( $post ) ) {
36                 $redirect = 'edit.php?post_type=' . $post->post_type;
37                 break;
38         }
39
40         // Don't allow revision restore when post is locked
41         if ( wp_check_post_lock( $post->ID ) )
42                 break;
43
44         check_admin_referer( "restore-post_{$revision->ID}" );
45
46         wp_restore_post_revision( $revision->ID );
47         $redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) );
48         break;
49 case 'view' :
50 case 'edit' :
51 default :
52         if ( ! $revision = wp_get_post_revision( $revision_id ) )
53                 break;
54         if ( ! $post = get_post( $revision->post_parent ) )
55                 break;
56
57         if ( ! current_user_can( 'read_post', $revision->ID ) || ! current_user_can( 'read_post', $post->ID ) )
58                 break;
59
60         // Revisions disabled and we're not looking at an autosave
61         if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
62                 $redirect = 'edit.php?post_type=' . $post->post_type;
63                 break;
64         }
65
66         $post_title = '<a href="' . get_edit_post_link() . '">' . _draft_or_post_title() . '</a>';
67         $h2 = sprintf( __( 'Compare Revisions of &#8220;%1$s&#8221;' ), $post_title );
68         $title = __( 'Revisions' );
69
70         $redirect = false;
71         break;
72 endswitch;
73
74 // Empty post_type means either malformed object found, or no valid parent was found.
75 if ( ! $redirect && empty( $post->post_type ) )
76         $redirect = 'edit.php';
77
78 if ( ! empty( $redirect ) ) {
79         wp_redirect( $redirect );
80         exit;
81 }
82
83 // This is so that the correct "Edit" menu item is selected.
84 if ( ! empty( $post->post_type ) && 'post' != $post->post_type )
85         $parent_file = $submenu_file = 'edit.php?post_type=' . $post->post_type;
86 else
87         $parent_file = $submenu_file = 'edit.php';
88
89 wp_enqueue_script( 'revisions' );
90 wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $post, $revision_id, $from ) );
91
92 /* Revisions Help Tab */
93
94 $revisions_overview  = '<p>' . __( 'This screen is used for managing your content revisions.' ) . '</p>';
95 $revisions_overview .= '<p>' . __( 'Revisions are saved copies of your post or page, which are periodically created as you update your content. The red text on the left shows the content that was removed. The green text on the right shows the content that was added.' ) . '</p>';
96 $revisions_overview .= '<p>' . __( 'From this screen you can review, compare, and restore revisions:' ) . '</p>';
97 $revisions_overview .= '<ul><li>' . __( 'To navigate between revisions, <strong>drag the slider handle left or right</strong> or <strong>use the Previous or Next buttons</strong>.' ) . '</li>';
98 $revisions_overview .= '<li>' . __( 'Compare two different revisions by <strong>selecting the &#8220;Compare any two revisions&#8221; box</strong> to the side.' ) . '</li>';
99 $revisions_overview .= '<li>' . __( 'To restore a revision, <strong>click Restore This Revision</strong>.' ) . '</li></ul>';
100
101 get_current_screen()->add_help_tab( array(
102         'id'      => 'revisions-overview',
103         'title'   => __( 'Overview' ),
104         'content' => $revisions_overview
105 ) );
106
107 $revisions_sidebar  = '<p><strong>' . __( 'For more information:' ) . '</strong></p>';
108 $revisions_sidebar .= '<p>' . __( '<a href="http://codex.wordpress.org/Revision_Management" target="_blank">Revisions Management</a>' ) . '</p>';
109 $revisions_sidebar .= '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>';
110
111 get_current_screen()->set_help_sidebar( $revisions_sidebar );
112
113 require_once( './admin-header.php' );
114
115 ?>
116
117 <div class="wrap">
118         <?php screen_icon(); ?>
119         <h2 class="long-header"><?php echo $h2; ?></h2>
120 </div>
121
122 <script id="tmpl-revisions-frame" type="text/html">
123         <div class="revisions-control-frame"></div>
124         <div class="revisions-diff-frame"></div>
125 </script>
126
127 <script id="tmpl-revisions-buttons" type="text/html">
128         <div class="revisions-previous">
129                 <input class="button" type="button" value="<?php echo esc_attr_x( 'Previous', 'Button label for a previous revision' ); ?>" />
130         </div>
131
132         <div class="revisions-next">
133                 <input class="button" type="button" value="<?php echo esc_attr_x( 'Next', 'Button label for a next revision' ); ?>" />
134         </div>
135 </script>
136
137 <script id="tmpl-revisions-checkbox" type="text/html">
138         <div class="revision-toggle-compare-mode">
139                 <label>
140                         <input type="checkbox" class="compare-two-revisions"
141                         <#
142                         if ( 'undefined' !== typeof data && data.model.attributes.compareTwoMode ) {
143                                 #> checked="checked"<#
144                         }
145                         #>
146                         />
147                         <?php esc_attr_e( 'Compare any two revisions' ); ?>
148                 </label>
149         </div>
150 </script>
151
152 <script id="tmpl-revisions-meta" type="text/html">
153         <# if ( ! _.isUndefined( data.attributes ) ) { #>
154                 <div class="diff-title">
155                         <# if ( 'from' === data.type ) { #>
156                                 <strong><?php _ex( 'From:', 'Followed by post revision info' ); ?></strong>
157                         <# } else if ( 'to' === data.type ) { #>
158                                 <strong><?php _ex( 'To:', 'Followed by post revision info' ); ?></strong>
159                         <# } #>
160                         <div class="author-card<# if ( data.attributes.autosave ) { #> autosave<# } #>">
161                                 {{{ data.attributes.author.avatar }}}
162                                 <div class="author-info">
163                                 <# if ( data.attributes.autosave ) { #>
164                                         <span class="byline"><?php printf( __( 'Autosave by %s' ),
165                                                 '<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
166                                 <# } else if ( data.attributes.current ) { #>
167                                         <span class="byline"><?php printf( __( 'Current Revision by %s' ),
168                                                 '<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
169                                 <# } else { #>
170                                         <span class="byline"><?php printf( __( 'Revision by %s' ),
171                                                 '<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
172                                 <# } #>
173                                         <span class="time-ago">{{ data.attributes.timeAgo }}</span>
174                                         <span class="date">({{ data.attributes.dateShort }})</span>
175                                 </div>
176                         <# if ( 'to' === data.type && data.attributes.restoreUrl ) { #>
177                                 <input  <?php if ( wp_check_post_lock( $post->ID ) ) { ?>
178                                         disabled="disabled"
179                                 <?php } else { ?>
180                                         <# if ( data.attributes.current ) { #>
181                                                 disabled="disabled"
182                                         <# } #>
183                                 <?php } ?>
184                                 <# if ( data.attributes.autosave ) { #>
185                                         type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Autosave' ); ?>" />
186                                 <# } else { #>
187                                         type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Revision' ); ?>" />
188                                 <# } #>
189                         <# } #>
190                 </div>
191         <# if ( 'tooltip' === data.type ) { #>
192                 <div class="revisions-tooltip-arrow"><span></span></div>
193         <# } #>
194 <# } #>
195 </script>
196
197 <script id="tmpl-revisions-diff" type="text/html">
198         <div class="loading-indicator"><span class="spinner"></span></div>
199         <div class="diff-error"><?php _e( 'Sorry, something went wrong. The requested comparison could not be loaded.' ); ?></div>
200         <div class="diff">
201         <# _.each( data.fields, function( field ) { #>
202                 <h3>{{ field.name }}</h3>
203                 {{{ field.diff }}}
204         <# }); #>
205         </div>
206 </script>
207
208
209 <?php
210 require_once( './admin-footer.php' );