Make WordPress Core

Ticket #23920: 23920.patch

File 23920.patch, 4.6 KB (added by azaozz, 13 years ago)
  • wp-admin/includes/ajax-actions.php

     
    20962096function wp_ajax_revisions_data() {
    20972097        check_ajax_referer( 'revisions-ajax-nonce', 'nonce' );
    20982098
    2099         $compare_to = isset( $_GET['compare_to'] ) ? absint( $_GET['compare_to'] ) : 0;
    2100         $show_autosaves = isset( $_GET['show_autosaves'] ) ? $_GET['show_autosaves'] : '';
    2101         $show_split_view = isset( $_GET['show_split_view'] ) ? $_GET['show_split_view'] : '';
    2102         $post_id = isset( $_GET['post_id'] ) ? absint( $_GET['post_id'] ) : '';
    2103         $right_handle_at = isset( $_GET['right_handle_at'] ) ? $_GET['right_handle_at'] : 0;
    2104         $left_handle_at = isset( $_GET['left_handle_at'] ) ? $_GET['left_handle_at'] : 0;
    2105         $single_revision_id = isset( $_GET['single_revision_id'] ) ? $_GET['single_revision_id'] : 0;
     2099        $compare_to = ! empty( $_GET['compare_to'] ) ? absint( $_GET['compare_to'] ) : 0;
     2100        $show_autosaves = ! empty( $_GET['show_autosaves'] );
     2101        $show_split_view = ! empty( $_GET['show_split_view'] );
     2102        $post_id = ! empty( $_GET['post_id'] ) ? absint( $_GET['post_id'] ) : 0;
     2103        $right_handle_at = ! empty( $_GET['right_handle_at'] ) ? (int) $_GET['right_handle_at'] : 0;
     2104        $left_handle_at = ! empty( $_GET['left_handle_at'] ) ? (int) $_GET['left_handle_at'] : 0;
     2105        $single_revision_id = ! empty( $_GET['single_revision_id'] ) ? absint( $_GET['single_revision_id'] ) : 0;
    21062106
    2107         $compare_two_mode = ( '' == $post_id ) ? false : true;
     2107        $compare_two_mode = (bool) $post_id;
    21082108        //
    21092109        //TODO: currently code returns all possible comparisons for the indicated 'compare_to' revision
    21102110        //however, the front end prevents users from pulling the right handle past the left or the left pass the right,
    21112111        //so only the possible diffs need be generated
    21122112        //
    21132113        $alltherevisions = array();
    2114         if ( '' == $post_id )
     2114        if ( ! $post_id )
    21152115                $post_id = $compare_to;
    21162116
    21172117        if ( ! current_user_can( 'read_post', $post_id ) )
     
    21272127
    21282128        //single model fetch mode
    21292129        //return the diff of a single revision comparison
    2130         if ( 0 != $single_revision_id ) {
     2130        if ( $single_revision_id ) {
    21312131                $right_revision = get_post( $single_revision_id );
    21322132
    2133         if ( 0 == $compare_to )
     2133                if ( ! $compare_to )
    21342134                        $left_revision = get_post( $post_id );
    21352135
    2136         // make sure the right revision is the most recent
    2137         if ( $compare_two_mode && $right_revision->ID < $left_revision->ID ) {
    2138                 $temp = $left_revision;
    2139                 $left_revision = $right_revision;
    2140                 $right_revision = $temp;
    2141         }
     2136                // make sure the right revision is the most recent
     2137                if ( $compare_two_mode && $right_revision->ID < $left_revision->ID ) {
     2138                        $temp = $left_revision;
     2139                        $left_revision = $right_revision;
     2140                        $right_revision = $temp;
     2141                }
    21422142
    2143                 $linesadded=0;
    2144                 $linesdeleted=0;
    2145 
     2143                $linesadded = $linesdeleted = 0;
     2144                $content = '';
    21462145                //
    21472146                //compare from left to right, passed from application
    21482147                //
    2149                 $content='';
    21502148                foreach ( array_keys( _wp_post_revision_fields() ) as $field ) {
    21512149                        $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field, $left_revision, 'left' );
    21522150                        $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field, $right_revision, 'right' );
     
    21552153
    21562154                        $args = array();
    21572155
    2158                         if ( ! empty( $show_split_view ) )
     2156                        if ( $show_split_view )
    21592157                                 $args = array( 'show_split_view' => true );
    21602158
    21612159                        // compare_to == 0 means first revision, so compare to a blank field to show whats changed
     
    21692167
    21702168                        if ( isset( $diff[ 'linesdeleted' ] ) )
    21712169                                $linesdeleted = $linesdeleted + $diff[ 'linesdeleted' ];
     2170                }
    21722171
    2173 
    2174                 }
    21752172                $content = '' == $content ? __( 'No difference' ) : $content;
    21762173
    21772174                $alltherevisions = array (
     
    21792176                        'lines_deleted' => $linesdeleted,
    21802177                        'lines_added' => $linesadded
    21812178                );
     2179
    21822180                echo json_encode( $alltherevisions );
    21832181                exit();
    21842182        } //end single model fetch
     
    21922190
    21932191        foreach ( $revisions as $revision ) :
    21942192                //error_log( ( $show_autosaves  ));
    2195                 if ( empty( $show_autosaves ) && wp_is_post_autosave( $revision ) )
    2196                                 continue;
     2193                if ( $show_autosaves && wp_is_post_autosave( $revision ) )
     2194                        continue;
    21972195
    21982196                $revision_from_date_author = '';
    21992197                $count++;
     
    22372235                $autosavef = __( '%1$s [Autosave]' );
    22382236                $currentf  = __( '%1$s [Current Revision]' );
    22392237
    2240                 if ( ! $post = get_post( $post_id))
    2241                         exit();
     2238                if ( ! $post = get_post( $post_id ) )
     2239                        exit(); // Should that be `continue;` instead?
    22422240
    22432241                if ( $left_revision->post_modified === $post->post_modified )
    22442242                        $revision_from_date_author = sprintf( $currentf, $revision_from_date_author );