Make WordPress Core

Ticket #16215: combined-3.diff

File combined-3.diff, 8.4 KB (added by adamsilverstein, 12 years ago)

combined patch for testing

  • wp-includes/default-filters.php

     
    123123        add_filter( $filter, 'convert_chars' );
    124124}
    125125
     126// Pre save Revision Version
     127add_filter( 'wp_insert_post_data', '_wp_insert_post_data_revision_version', 10, 2 );
     128
    126129// Pre save hierarchy
    127130add_filter( 'wp_insert_post_parent', 'wp_check_post_hierarchy_for_loops', 10, 2 );
    128131add_filter( 'wp_update_term_parent', 'wp_check_term_hierarchy_for_loops', 10, 3 );
     
    249252add_action( 'plugins_loaded',             'wp_maybe_load_widgets',                    0    );
    250253add_action( 'plugins_loaded',             'wp_maybe_load_embeds',                     0    );
    251254add_action( 'shutdown',                   'wp_ob_end_flush_all',                      1    );
    252 add_action( 'pre_post_update',            'wp_save_post_revision'                          );
     255add_action( 'pre_post_update',            'wp_save_post_revision',                   10, 2 );
    253256add_action( 'publish_post',               '_publish_post_hook',                       5, 1 );
    254257add_action( 'transition_post_status',     '_transition_post_status',                  5, 3 );
    255258add_action( 'transition_post_status',     '_update_term_count_on_transition_post_status', 10, 3 );
  • wp-includes/post-template.php

     
    13751375
    13761376        if ( $parent )
    13771377                array_unshift( $revisions, $post );
     1378       
     1379        if ( ! array_pop( $revisions ) )
     1380                return;
    13781381
    13791382        $rows = $right_checked = '';
    13801383        $class = false;
    13811384        $can_edit_post = current_user_can( 'edit_post', $post->ID );
     1385
    13821386        foreach ( $revisions as $revision ) {
     1387
    13831388                if ( !current_user_can( 'read_post', $revision->ID ) )
    13841389                        continue;
    13851390                if ( 'revision' === $type && wp_is_post_autosave( $revision ) )
    13861391                        continue;
    13871392
    13881393                $date = wp_post_revision_title( $revision );
    1389                 $name = get_the_author_meta( 'display_name', $revision->post_author );
     1394                if ( wp_is_post_revision( $revision ) ) {
     1395                        $revision_author_id = $revision->post_author;
     1396                } elseif ( !$revision_author_id = get_post_meta( $revision->ID, '_edit_last', true ) ) {
     1397                        $revision_author_id = $revision->post_author;
     1398                }
     1399                $name = get_the_author_meta( 'display_name', $revision_author_id );
    13901400
    13911401                if ( 'form-table' == $format ) {
    13921402                        if ( $left )
  • wp-includes/post.php

     
    28662866        $where = array( 'ID' => $post_ID );
    28672867
    28682868        if ( $update ) {
    2869                 do_action( 'pre_post_update', $post_ID );
     2869                do_action( 'pre_post_update', $post_ID, $data );
    28702870                if ( false === $wpdb->update( $wpdb->posts, $data, $where ) ) {
    28712871                        if ( $wp_error )
    28722872                                return new WP_Error('db_update_error', __('Could not update post in the database'), $wpdb->last_error);
     
    29002900                $wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] ), $where );
    29012901        }
    29022902
     2903        update_post_meta( $post_ID, '_edit_last', $user_ID );
     2904
    29032905        if ( is_object_in_taxonomy($post_type, 'category') )
    29042906                wp_set_post_categories( $post_ID, $post_category );
    29052907
     
    49204922        $return['post_date']     = isset($post['post_modified']) ? $post['post_modified'] : '';
    49214923        $return['post_date_gmt'] = isset($post['post_modified_gmt']) ? $post['post_modified_gmt'] : '';
    49224924
     4925        $return['post_author']   = get_post_meta( $post['ID'], '_edit_last', true );
     4926        $return['comment_count'] = 1; // The comment_count field stores the revisioning system version
     4927
    49234928        return $return;
    49244929}
    49254930
     4931function _wp_insert_post_data_revision_version( $data, $post_array ) {
     4932        if ( 'revision' != $data['post_type'] ) {
     4933                return $data;
     4934        }
     4935
     4936        if ( isset( $post_array['comment_count'] ) ) {
     4937                $data['comment_count'] = (int) $post_array['comment_count'];
     4938        }
     4939
     4940        return $data;
     4941}
     4942
    49264943/**
    49274944 * Saves an already existing post as a post revision.
    49284945 *
     
    49374954 * @param int $post_id The ID of the post to save as a revision.
    49384955 * @return mixed Null or 0 if error, new revision ID, if success.
    49394956 */
    4940 function wp_save_post_revision( $post_id ) {
     4957function wp_save_post_revision( $post_id, $new_data = null ) {
    49414958        // We do autosaves manually with wp_create_post_autosave()
    49424959        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
    49434960                return;
     
    49554972        if ( !post_type_supports($post['post_type'], 'revisions') )
    49564973                return;
    49574974
     4975        // if new data is supplied, check that it is different from last saved revision
     4976        if( is_array( $new_data ) ) {
     4977                $post_has_changed = false;
     4978                foreach( array_keys( _wp_post_revision_fields() ) as $field ) {
     4979                        if( normalize_whitespace( $new_data[ $field ] ) != normalize_whitespace( $post[$field] ) ) {
     4980                                error_log( 'post changed' );
     4981                                $post_has_changed = true;
     4982                                break;
     4983                        }
     4984                }
     4985                //don't save revision if post unchanged
     4986                if( ! $post_has_changed )
     4987                        return;
     4988        }
     4989
    49584990        $return = _wp_put_post_revision( $post );
    49594991
    49604992        // WP_POST_REVISIONS = true (default), -1
     
    52355267
    52365268        if ( !$revisions = get_children( $args ) )
    52375269                return array();
     5270
     5271        $revisions = wp_fix_post_revision_authors( $revisions, $args );
    52385272        return $revisions;
    52395273}
    52405274
     5275function wp_fix_post_revision_authors( $revisions, $args ) {
     5276        $keys = array_keys( $revisions );
     5277        if ( 'DESC' == strtoupper( $args['order'] ) ) {
     5278                $keys = array_reverse( $keys );
     5279        }
     5280
     5281        $previous_author = false;
     5282        foreach ( $keys as $key ) {
     5283                if ( is_array( $revisions[$key] ) && isset( $revisions[$key]['comment_count'] ) ) {
     5284                        $revision_version = $revisions[$key]['comment_count'];
     5285                        $is_array = true;
     5286                } elseif ( is_object( $revisions[$key] ) && isset( $revisions[$key]->comment_count ) ) {
     5287                        $revision_version = $revisions[$key]->comment_count;
     5288                        $is_array = false;
     5289                } else {
     5290                        continue;
     5291                }
     5292
     5293                if ( 1 == $revision_version ) {
     5294                        $post_author_name = get_the_author_meta( 'display_name', $revisions[$key]->post_author );
     5295                        continue;
     5296                }
     5297
     5298                if ( $is_array ) {
     5299                        // swap
     5300                        list(
     5301                                $previous_author,
     5302                                $revisions[$key]['post_author']
     5303                        ) = array(
     5304                                $revisions[$key]['post_author'],
     5305                                false === $previous_author ? $revisions[$key]['post_author'] : $previous_author
     5306                        );
     5307                        $revisions[$key]['comment_count'] = 1; // in case this data gets cached somewhere, flag it as having the fixed post_author
     5308                } else {
     5309                        // swap
     5310                        list(
     5311                                $previous_author,
     5312                                $revisions[$key]->post_author
     5313                        ) = array(
     5314                                $revisions[$key]->post_author,
     5315                                false === $previous_author ? $revisions[$key]->post_author : $previous_author
     5316                        );
     5317                        $revisions[$key]->comment_count = 1; // in case this data gets cached somewhere, flag it as having the fixed post_author
     5318                }
     5319        }
     5320
     5321        return $revisions;
     5322}
     5323
    52415324function _set_preview($post) {
    52425325
    52435326        if ( ! is_object($post) )
  • wp-includes/comment.php

     
    16151615                return false;
    16161616        if ( !$post = get_post($post_id) )
    16171617                return false;
     1618        if ( 'revision' == $post->post_type )
     1619                return false;
    16181620
    16191621        $old = (int) $post->comment_count;
    16201622        $new = (int) $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id) );
  • wp-admin/includes/post.php

     
    241241
    242242        add_meta( $post_ID );
    243243
    244         update_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );
    245 
    246244        wp_update_post( $post_data );
    247245
    248246        // Now that we have an ID we can fix any attachment anchor hrefs
     
    568566
    569567        add_meta( $post_ID );
    570568
    571         add_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );
    572 
    573569        // Now that we have an ID we can fix any attachment anchor hrefs
    574570        _fix_attachment_links( $post_ID );
    575571
  • wp-admin/includes/meta-boxes.php

     
    603603 * @param object $post
    604604 */
    605605function post_revisions_meta_box($post) {
    606         wp_list_post_revisions();
     606        $args = array( 'parent' => true );
     607        wp_list_post_revisions( $post, $args );
    607608}
    608609
    609610// -- Page related Meta Boxes