Changeset 8011
- Timestamp:
- 05/29/2008 10:21:36 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-ajax.php
r7971 r8011 520 520 $id = edit_post(); 521 521 } else { // Non drafts are not overwritten. The autosave is stored in a special post revision. 522 $revision_id = wp_create_ autosave( $post->ID );522 $revision_id = wp_create_post_autosave( $post->ID ); 523 523 if ( is_wp_error($revision_id) ) 524 524 $id = $revision_id; -
trunk/wp-admin/edit-form-advanced.php
r7967 r8011 22 22 $form_action = 'editpost'; 23 23 $form_extra = "<input type='hidden' id='post_ID' name='post_ID' value='$post_ID' />"; 24 $autosave = wp_get_ autosave( $post_id );24 $autosave = wp_get_post_autosave( $post_id ); 25 25 if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt ) > mysql2date( 'U', $post->post_modified_gmt ) ) 26 26 $notice = sprintf( $notices[1], get_edit_post_link( $autosave->ID ) ); -
trunk/wp-admin/edit-page-form.php
r7948 r8011 20 20 $nonce_action = 'update-page_' . $post_ID; 21 21 $form_extra = "<input type='hidden' id='post_ID' name='post_ID' value='$post_ID' />"; 22 $autosave = wp_get_ autosave( $post_id );22 $autosave = wp_get_post_autosave( $post_id ); 23 23 if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt ) > mysql2date( 'U', $post->post_modified_gmt ) ) 24 24 $notice = sprintf( $notices[1], get_edit_post_link( $autosave->ID ) ); -
trunk/wp-admin/includes/post.php
r7980 r8011 650 650 651 651 /** 652 * wp_create_ autosave() - creates autosave data for the specified post from $_POST data652 * wp_create_post_autosave() - creates autosave data for the specified post from $_POST data 653 653 * 654 654 * @package WordPress … … 657 657 * 658 658 * @uses _wp_translate_postdata() 659 * @uses _wp_ revision_fields()659 * @uses _wp_post_revision_fields() 660 660 */ 661 function wp_create_ autosave( $post_id ) {661 function wp_create_post_autosave( $post_id ) { 662 662 $translated = _wp_translate_postdata( true ); 663 663 if ( is_wp_error( $translated ) ) … … 665 665 666 666 // Only store one autosave. If there is already an autosave, overwrite it. 667 if ( $old_autosave = wp_get_ autosave( $post_id ) ) {668 $new_autosave = _wp_ revision_fields( $_POST, true );667 if ( $old_autosave = wp_get_post_autosave( $post_id ) ) { 668 $new_autosave = _wp_post_revision_fields( $_POST, true ); 669 669 $new_autosave['ID'] = $old_autosave->ID; 670 670 return wp_update_post( $new_autosave ); … … 672 672 673 673 // Otherwise create the new autosave as a special post revision 674 return _wp_put_ revision( $_POST, true );675 } 674 return _wp_put_post_revision( $_POST, true ); 675 } -
trunk/wp-admin/revision.php
r7913 r8011 2 2 3 3 require_once('admin.php'); 4 5 if ( !constant('WP_POST_REVISIONS') ) {6 wp_redirect( 'edit.php' );7 exit;8 }9 4 10 5 wp_reset_vars(array('revision', 'left', 'right', 'action')); … … 19 14 case 'delete' : // stubs 20 15 case 'edit' : 21 $redirect = remove_query_arg( 'action' ); 16 if ( constant('WP_POST_REVISIONS') ) // stub 17 $redirect = remove_query_arg( 'action' ); 18 else // Revisions disabled 19 $redirect = 'edit.php'; 22 20 break; 23 21 case 'restore' : 22 if ( !$revision = wp_get_post_revision( $revision_id ) ) 23 break; 24 24 if ( !current_user_can( 'edit_post', $revision->post_parent ) ) 25 25 break; 26 if ( !$revision = wp_get_revision( $revision_id ) )27 break;28 26 if ( !$post = get_post( $revision->post_parent ) ) 29 27 break; 30 28 29 if ( !constant('WP_POST_REVISIONS') && !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave 30 break; 31 31 32 check_admin_referer( "restore-post_$post->ID|$revision->ID" ); 32 33 33 wp_restore_ revision( $revision->ID );34 wp_restore_post_revision( $revision->ID ); 34 35 $redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) ); 35 36 break; … … 58 59 break; // Don't diff two unrelated revisions 59 60 61 if ( !constant('WP_POST_REVISIONS') ) { // Revisions disabled 62 if ( 63 // we're not looking at an autosave 64 ( !wp_is_post_autosave( $left_revision ) && !wp_is_post_autosave( $right_revision ) ) 65 || 66 // we're not comparing an autosave to the current post 67 ( $post->ID !== $left_revision->ID && $post->ID !== $right_revision->ID ) 68 ) 69 break; 70 } 71 60 72 if ( 61 73 // They're the same … … 63 75 || 64 76 // Neither is a revision 65 ( !wp_get_ revision( $left_revision->ID ) && !wp_get_revision( $right_revision->ID ) )77 ( !wp_get_post_revision( $left_revision->ID ) && !wp_get_post_revision( $right_revision->ID ) ) 66 78 ) 67 79 break; … … 77 89 case 'view' : 78 90 default : 79 if ( !$revision = wp_get_ revision( $revision_id ) )91 if ( !$revision = wp_get_post_revision( $revision_id ) ) 80 92 break; 81 93 if ( !$post = get_post( $revision->post_parent ) ) … … 83 95 84 96 if ( !current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) ) 97 break; 98 99 if ( !constant('WP_POST_REVISIONS') && !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave 85 100 break; 86 101 … … 114 129 115 130 // Converts post_author ID# into name 116 add_filter( '_wp_ revision_field_post_author', 'get_author_name' );131 add_filter( '_wp_post_revision_field_post_author', 'get_author_name' ); 117 132 118 133 require_once( 'admin-header.php' ); … … 138 153 // use get_post_to_edit filters? 139 154 $identical = true; 140 foreach ( _wp_ revision_fields() as $field => $field_title ) :155 foreach ( _wp_post_revision_fields() as $field => $field_title ) : 141 156 if ( 'diff' == $action ) { 142 $left_content = apply_filters( "_wp_ revision_field_$field", $left_revision->$field, $field );143 $right_content = apply_filters( "_wp_ revision_field_$field", $right_revision->$field, $field );157 $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field ); 158 $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field ); 144 159 if ( !$content = wp_text_diff( $left_content, $right_content ) ) 145 160 continue; // There is no difference between left and right 146 161 $identical = false; 147 162 } else { 148 add_filter( "_wp_ revision_field_$field", 'htmlspecialchars' );149 $content = apply_filters( "_wp_ revision_field_$field", $revision->$field, $field );163 add_filter( "_wp_post_revision_field_$field", 'htmlspecialchars' ); 164 $content = apply_filters( "_wp_post_revision_field_$field", $revision->$field, $field ); 150 165 } 151 166 ?> … … 180 195 <?php 181 196 182 wp_list_post_revisions( $post, array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left ) ); 197 $args = array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left ); 198 if ( !constant( 'WP_POST_REVISIONS' ) ) 199 $args['type'] = 'autosave'; 200 201 wp_list_post_revisions( $post, $args ); 183 202 184 203 require_once( 'admin-footer.php' ); -
trunk/wp-includes/default-filters.php
r7970 r8011 180 180 add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 ); 181 181 add_action( 'shutdown', 'wp_ob_end_flush_all', 1); 182 add_action( 'pre_post_update', 'wp_save_ revision' );182 add_action( 'pre_post_update', 'wp_save_post_revision' ); 183 183 add_action('publish_post', '_publish_post_hook', 5, 1); 184 184 add_action('future_post', '_future_post_hook', 5, 2); -
trunk/wp-includes/post-template.php
r7913 r8011 594 594 $date = "<a href='$link'>$date</a>"; 595 595 596 if ( 'revision' != $revision->post_type)596 if ( !wp_is_post_revision( $revision ) ) 597 597 $date = sprintf( $currentf, $date ); 598 elseif ( "{$revision->post_parent}-autosave" == $revision->post_name)598 elseif ( wp_is_post_autosave( $revision ) ) 599 599 $date = sprintf( $autosavef, $date ); 600 600 … … 629 629 return; 630 630 631 if ( !$revisions = wp_get_post_revisions( $post->ID ) ) 632 return; 633 634 $defaults = array( 'parent' => false, 'right' => false, 'left' => false, 'format' => 'list' ); 631 $defaults = array( 'parent' => false, 'right' => false, 'left' => false, 'format' => 'list', 'type' => 'all' ); 635 632 extract( wp_parse_args( $args, $defaults ), EXTR_SKIP ); 633 634 switch ( $type ) { 635 case 'autosave' : 636 if ( !$autosave = wp_get_post_autosave( $post->ID ) ) 637 return; 638 $revisions = array( $autosave ); 639 break; 640 case 'revision' : // just revisions - remove autosave later 641 case 'all' : 642 default : 643 if ( !$revisions = wp_get_post_revisions( $post->ID ) ) 644 return; 645 break; 646 } 636 647 637 648 $titlef = _c( '%1$s by %2$s|post revision 1:datetime, 2:name' ); … … 645 656 foreach ( $revisions as $revision ) { 646 657 if ( !current_user_can( 'read_post', $revision->ID ) ) 658 continue; 659 if ( 'revision' === $type && wp_is_post_autosave( $revision ) ) 647 660 continue; 648 661 -
trunk/wp-includes/post.php
r7995 r8011 957 957 // Do raw query. wp_get_post_revisions() is filtered 958 958 $revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid ) ); 959 // Use wp_delete_post (via wp_delete_ revision) again. Ensures any meta/misplaced data gets cleaned up.959 // Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up. 960 960 foreach ( $revision_ids as $revision_id ) 961 wp_delete_ revision( $revision_id );961 wp_delete_post_revision( $revision_id ); 962 962 963 963 // Point all attachments to this post up one level … … 2952 2952 2953 2953 /** 2954 * _wp_ revision_fields() - determines which fields of posts are to be saved in revisions2954 * _wp_post_revision_fields() - determines which fields of posts are to be saved in revisions 2955 2955 * 2956 2956 * Does two things. If passed a post *array*, it will return a post array ready to be … … 2966 2966 * @return array post array ready to be inserted as a post revision or array of fields that can be versioned 2967 2967 */ 2968 function _wp_ revision_fields( $post = null, $autosave = false ) {2968 function _wp_post_revision_fields( $post = null, $autosave = false ) { 2969 2969 static $fields = false; 2970 2970 … … 2979 2979 2980 2980 // Runs only once 2981 $fields = apply_filters( '_wp_ revision_fields', $fields );2981 $fields = apply_filters( '_wp_post_revision_fields', $fields ); 2982 2982 2983 2983 // WP uses these internally either in versioning or elsewhere - they cannot be versioned … … 3004 3004 3005 3005 /** 3006 * wp_save_ revision() - Saves an already existing post as a post revision. Typically used immediately prior to post updates.3006 * wp_save_post_revision() - Saves an already existing post as a post revision. Typically used immediately prior to post updates. 3007 3007 * 3008 3008 * @package WordPress … … 3010 3010 * @since 2.6 3011 3011 * 3012 * @uses _wp_put_ revision()3012 * @uses _wp_put_post_revision() 3013 3013 * 3014 3014 * @param int $post_id The ID of the post to save as a revision 3015 3015 * @return mixed null or 0 if error, new revision ID if success 3016 3016 */ 3017 function wp_save_ revision( $post_id ) {3018 // We do autosaves manually with wp_create_ autosave()3017 function wp_save_post_revision( $post_id ) { 3018 // We do autosaves manually with wp_create_post_autosave() 3019 3019 if ( @constant( 'DOING_AUTOSAVE' ) ) 3020 3020 return; … … 3030 3030 return; 3031 3031 3032 $return = _wp_put_ revision( $post );3032 $return = _wp_put_post_revision( $post ); 3033 3033 3034 3034 // WP_POST_REVISIONS = true (default), -1 … … 3050 3050 if ( false !== strpos( $revisions[$i]->post_name, 'autosave' ) ) 3051 3051 continue; 3052 wp_delete_ revision( $revisions[$i]->ID );3052 wp_delete_post_revision( $revisions[$i]->ID ); 3053 3053 } 3054 3054 … … 3057 3057 3058 3058 /** 3059 * wp_get_ autosave() - returns the autosaved data of the specified post.3059 * wp_get_post_autosave() - returns the autosaved data of the specified post. 3060 3060 * 3061 3061 * Returns a post object containing the information that was autosaved for the specified post. … … 3068 3068 * @return object|bool the autosaved data or false on failure or when no autosave exists 3069 3069 */ 3070 function wp_get_ autosave( $post_id ) {3070 function wp_get_post_autosave( $post_id ) { 3071 3071 global $wpdb; 3072 3072 if ( !$post = get_post( $post_id ) ) … … 3083 3083 $autosave_query = new WP_Query; 3084 3084 3085 add_action( 'parse_query', '_wp_get_ autosave_hack' );3085 add_action( 'parse_query', '_wp_get_post_autosave_hack' ); 3086 3086 $autosave = $autosave_query->query( $q ); 3087 remove_action( 'parse_query', '_wp_get_ autosave_hack' );3087 remove_action( 'parse_query', '_wp_get_post_autosave_hack' ); 3088 3088 3089 3089 if ( $autosave && is_array($autosave) && is_object($autosave[0]) ) … … 3094 3094 3095 3095 // Internally used to hack WP_Query into submission 3096 function _wp_get_ autosave_hack( $query ) {3096 function _wp_get_post_autosave_hack( $query ) { 3097 3097 $query->is_single = false; 3098 3098 } 3099 3099 3100 /** 3101 * _wp_put_revision() - Inserts post data into the posts table as a post revision 3100 3101 /** 3102 * wp_is_post_revision() - Determines if the specified post is a revision. 3103 * 3104 * @package WordPress 3105 * @subpackage Post Revisions 3106 * @since 2.6 3107 * 3108 * @param int|object $post post ID or post object 3109 * @return bool|int false if not a revision, ID of revision's parent otherwise 3110 */ 3111 function wp_is_post_revision( $post ) { 3112 if ( !$post = wp_get_post_revision( $post ) ) 3113 return false; 3114 return (int) $post->post_parent; 3115 } 3116 3117 /** 3118 * wp_is_post_autosave() - Determines if the specified post is an autosave. 3119 * 3120 * @package WordPress 3121 * @subpackage Post Revisions 3122 * @since 2.6 3123 * 3124 * @param int|object $post post ID or post object 3125 * @return bool|int false if not a revision, ID of autosave's parent otherwise 3126 */ 3127 function wp_is_post_autosave( $post ) { 3128 if ( !$post = wp_get_post_revision( $post ) ) 3129 return false; 3130 if ( "{$post->post_parent}-autosave" !== $post->post_name ) 3131 return false; 3132 return (int) $post->post_parent; 3133 } 3134 3135 /** 3136 * _wp_put_post_revision() - Inserts post data into the posts table as a post revision 3102 3137 * 3103 3138 * @package WordPress … … 3111 3146 * @return mixed null or 0 if error, new revision ID if success 3112 3147 */ 3113 function _wp_put_ revision( $post = null, $autosave = false ) {3148 function _wp_put_post_revision( $post = null, $autosave = false ) { 3114 3149 if ( is_object($post) ) 3115 3150 $post = get_object_vars( $post ); … … 3122 3157 return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) ); 3123 3158 3124 $post = _wp_ revision_fields( $post, $autosave );3159 $post = _wp_post_revision_fields( $post, $autosave ); 3125 3160 3126 3161 $revision_id = wp_insert_post( $post ); … … 3129 3164 3130 3165 if ( $revision_id ) 3131 do_action( '_wp_put_ revision', $revision_id );3166 do_action( '_wp_put_post_revision', $revision_id ); 3132 3167 return $revision_id; 3133 3168 } 3134 3169 3135 3170 /** 3136 * wp_get_ revision() - Gets a post revision3171 * wp_get_post_revision() - Gets a post revision 3137 3172 * 3138 3173 * @package WordPress … … 3147 3182 * @return mixed null if error or post object if success 3148 3183 */ 3149 function &wp_get_ revision(&$post, $output = OBJECT, $filter = 'raw') {3184 function &wp_get_post_revision(&$post, $output = OBJECT, $filter = 'raw') { 3150 3185 $null = null; 3151 3186 if ( !$revision = get_post( $post, OBJECT, $filter ) ) … … 3168 3203 3169 3204 /** 3170 * wp_restore_ revision() - Restores a post to the specified revision3205 * wp_restore_post_revision() - Restores a post to the specified revision 3171 3206 * 3172 3207 * Can restore a past using all fields of the post revision, or only selected fields. … … 3176 3211 * @since 2.6 3177 3212 * 3178 * @uses wp_get_ revision()3213 * @uses wp_get_post_revision() 3179 3214 * @uses wp_update_post() 3180 3215 * … … 3183 3218 * @return mixed null if error, false if no fields to restore, (int) post ID if success 3184 3219 */ 3185 function wp_restore_ revision( $revision_id, $fields = null ) {3186 if ( !$revision = wp_get_ revision( $revision_id, ARRAY_A ) )3220 function wp_restore_post_revision( $revision_id, $fields = null ) { 3221 if ( !$revision = wp_get_post_revision( $revision_id, ARRAY_A ) ) 3187 3222 return $revision; 3188 3223 3189 3224 if ( !is_array( $fields ) ) 3190 $fields = array_keys( _wp_ revision_fields() );3225 $fields = array_keys( _wp_post_revision_fields() ); 3191 3226 3192 3227 $update = array(); … … 3204 3239 3205 3240 if ( $post_id ) 3206 do_action( 'wp_restore_ revision', $post_id, $revision['ID'] );3241 do_action( 'wp_restore_post_revision', $post_id, $revision['ID'] ); 3207 3242 3208 3243 return $post_id; … … 3210 3245 3211 3246 /** 3212 * wp_delete_ revision() - Deletes a revision.3247 * wp_delete_post_revision() - Deletes a revision. 3213 3248 * 3214 3249 * Deletes the row from the posts table corresponding to the specified revision … … 3218 3253 * @since 2.6 3219 3254 * 3220 * @uses wp_get_ revision()3255 * @uses wp_get_post_revision() 3221 3256 * @uses wp_delete_post() 3222 3257 * … … 3225 3260 * @return mixed null if error, false if no fields to restore, (int) post ID if success 3226 3261 */ 3227 function wp_delete_ revision( $revision_id ) {3228 if ( !$revision = wp_get_ revision( $revision_id ) )3262 function wp_delete_post_revision( $revision_id ) { 3263 if ( !$revision = wp_get_post_revision( $revision_id ) ) 3229 3264 return $revision; 3230 3265 … … 3234 3269 3235 3270 if ( $delete ) 3236 do_action( 'wp_delete_ revision', $revision->ID, $revision );3271 do_action( 'wp_delete_post_revision', $revision->ID, $revision ); 3237 3272 3238 3273 return $delete;
Note: See TracChangeset
for help on using the changeset viewer.