Make WordPress Core

Ticket #16215: 16215.diff

File 16215.diff, 5.7 KB (added by mdawaffe, 13 years ago)

First pass. New revisions: correct info DB. Old revisions: fix on the fly for display only

  • wp-includes/default-filters.php

     
    126126        add_filter( $filter, 'convert_chars' );
    127127}
    128128
     129// Pre save Revision Version
     130add_filter( 'wp_insert_post_data', '_wp_insert_post_data_revision_version', 10, 2 );
     131
    129132// Pre save hierarchy
    130133add_filter( 'wp_insert_post_parent', 'wp_check_post_hierarchy_for_loops', 10, 2 );
    131134add_filter( 'wp_update_term_parent', 'wp_check_term_hierarchy_for_loops', 10, 3 );
  • wp-includes/post-template.php

     
    13561356        $rows = $right_checked = '';
    13571357        $class = false;
    13581358        $can_edit_post = current_user_can( 'edit_post', $post->ID );
     1359
    13591360        foreach ( $revisions as $revision ) {
    13601361                if ( !current_user_can( 'read_post', $revision->ID ) )
    13611362                        continue;
     
    13631364                        continue;
    13641365
    13651366                $date = wp_post_revision_title( $revision );
    1366                 $name = get_the_author_meta( 'display_name', $revision->post_author );
     1367                if ( wp_is_post_revision( $revision ) ) {
     1368                        $revision_author_id = $revision->post_author;
     1369                } elseif ( !$revision_author_id = get_post_meta( $revision->ID, '_edit_last', true ) ) {
     1370                        $revision_author_id = $revision->post_author;
     1371                }
    13671372
     1373                $name = get_the_author_meta( 'display_name', $revision_author_id );
     1374
    13681375                if ( 'form-table' == $format ) {
    13691376                        if ( $left )
    13701377                                $left_checked = $left == $revision->ID ? ' checked="checked"' : '';
  • wp-includes/post.php

     
    25922592                $wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] ), $where );
    25932593        }
    25942594
     2595        update_post_meta( $post_ID, '_edit_last', $user_ID );
     2596
    25952597        if ( is_object_in_taxonomy($post_type, 'category') )
    25962598                wp_set_post_categories( $post_ID, $post_category );
    25972599
     
    47104712        $return['post_date']     = isset($post['post_modified']) ? $post['post_modified'] : '';
    47114713        $return['post_date_gmt'] = isset($post['post_modified_gmt']) ? $post['post_modified_gmt'] : '';
    47124714
     4715        $return['post_author']   = get_post_meta( $post['ID'], '_edit_last', true );
     4716        $return['comment_count'] = 1; // The comment_count field stores the revisioning system version
     4717
    47134718        return $return;
    47144719}
    47154720
     4721function _wp_insert_post_data_revision_version( $data, $post_array ) {
     4722        if ( 'revision' != $data['post_type'] ) {
     4723                return $data;
     4724        }
     4725
     4726        if ( isset( $post_array['comment_count'] ) ) {
     4727                $data['comment_count'] = (int) $post_array['comment_count'];
     4728        }
     4729
     4730        return $data;
     4731}
     4732
    47164733/**
    47174734 * Saves an already existing post as a post revision.
    47184735 *
     
    50225039
    50235040        if ( !$revisions = get_children( $args ) )
    50245041                return array();
     5042
     5043        $revisions = wp_fix_post_revision_authors( $revisions, $args );
    50255044        return $revisions;
    50265045}
    50275046
     5047function wp_fix_post_revision_authors( $revisions, $args ) {
     5048        $keys = array_keys( $revisions );
     5049        if ( 'DESC' == strtoupper( $args['order'] ) ) {
     5050                $keys = array_reverse( $keys );
     5051        }
     5052
     5053        $previous_author = false;
     5054        foreach ( $keys as $key ) {
     5055                if ( is_array( $revisions[$key] ) && isset( $revisions[$key]['comment_count'] ) ) {
     5056                        $revision_version = $revisions[$key]['comment_count'];
     5057                        $is_array = true;
     5058                } elseif ( is_object( $revisions[$key] ) && isset( $revisions[$key]->comment_count ) ) {
     5059                        $revision_version = $revisions[$key]->comment_count;
     5060                        $is_array = false;
     5061                } else {
     5062                        continue;
     5063                }
     5064
     5065                if ( 1 == $revision_version ) {
     5066                        $post_author_name = get_the_author_meta( 'display_name', $revisions[$key]->post_author );
     5067                        continue;
     5068                }
     5069
     5070                if ( $is_array ) {
     5071                        // swap
     5072                        list(
     5073                                $previous_author,
     5074                                $revisions[$key]['post_author']
     5075                        ) = array(
     5076                                $revisions[$key]['post_author'],
     5077                                false === $previous_author ? $revisions[$key]['post_author'] : $previous_author
     5078                        );
     5079                        $revisions[$key]['comment_count'] = 1; // in case this data gets cached somewhere, flag it as having the fixed post_author
     5080                } else {
     5081                        // swap
     5082                        list(
     5083                                $previous_author,
     5084                                $revisions[$key]->post_author
     5085                        ) = array(
     5086                                $revisions[$key]->post_author,
     5087                                false === $previous_author ? $revisions[$key]->post_author : $previous_author
     5088                        );
     5089                        $revisions[$key]->comment_count = 1; // in case this data gets cached somewhere, flag it as having the fixed post_author
     5090                }
     5091        }
     5092
     5093        return $revisions;
     5094}
     5095
    50285096function _set_preview($post) {
    50295097
    50305098        if ( ! is_object($post) )
  • wp-includes/comment.php

     
    15631563                return false;
    15641564        if ( !$post = get_post($post_id) )
    15651565                return false;
     1566        if ( 'revision' == $post->post_type )
     1567                return false;
    15661568
    15671569        $old = (int) $post->comment_count;
    15681570        $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

     
    230230
    231231        add_meta( $post_ID );
    232232
    233         update_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );
    234 
    235233        wp_update_post( $post_data );
    236234
    237235        // Reunite any orphaned attachments with their parent
     
    609607
    610608        add_meta( $post_ID );
    611609
    612         add_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );
    613 
    614610        // Reunite any orphaned attachments with their parent
    615611        // Does this need to be updated? ~ Mark
    616612        if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )