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