+
+if ( isset($_GET['revision']) )
+ $messages[5] = sprintf( __('Post restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) );
+
+$notice = false;
+$notices[1] = __( 'There is an autosave of this post that is more recent than the version below. <a href="%s">View the autosave</a>.' );
+
+if ( !isset($post_ID) || 0 == $post_ID ) {
+ $form_action = 'post';
+ $temp_ID = -1 * time(); // don't change this formula without looking at wp_write_post()
+ $form_extra = "<input type='hidden' id='post_ID' name='temp_ID' value='$temp_ID' />";
+ $autosave = false;
+} else {
+ $post_ID = (int) $post_ID;
+ $form_action = 'editpost';
+ $form_extra = "<input type='hidden' id='post_ID' name='post_ID' value='$post_ID' />";
+ $autosave = wp_get_post_autosave( $post_id );
+
+ // Detect if there exists an autosave newer than the post and if that autosave is different than the post
+ if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt ) > mysql2date( 'U', $post->post_modified_gmt ) ) {
+ foreach ( _wp_post_revision_fields() as $autosave_field => $_autosave_field ) {
+ if ( wp_text_diff( $autosave->$autosave_field, $post->$autosave_field ) ) {
+ $notice = sprintf( $notices[1], get_edit_post_link( $autosave->ID ) );
+ break;
+ }
+ }
+ unset($autosave_field, $_autosave_field);
+ }
+}
+