Make WordPress Core

Ticket #23920: 23920.2.patch

File 23920.2.patch, 7.1 KB (added by ocean90, 12 years ago)
  • wp-admin/includes/ajax-actions.php

     
    20922092function wp_ajax_revisions_data() {
    20932093        check_ajax_referer( 'revisions-ajax-nonce', 'nonce' );
    20942094
    2095         $compare_to = isset( $_GET['compare_to'] ) ? absint( $_GET['compare_to'] ) : 0;
    2096         $show_autosaves = isset( $_GET['show_autosaves'] ) ? $_GET['show_autosaves'] : '';
    2097         $show_split_view = isset( $_GET['show_split_view'] ) ? $_GET['show_split_view'] : '';
    2098         $post_id = isset( $_GET['post_id'] ) ? absint( $_GET['post_id'] ) : '';
    2099         $right_handle_at = isset( $_GET['right_handle_at'] ) ? $_GET['right_handle_at'] : 0;
    2100         $left_handle_at = isset( $_GET['left_handle_at'] ) ? $_GET['left_handle_at'] : 0;
    2101         $single_revision_id = isset( $_GET['single_revision_id'] ) ? $_GET['single_revision_id'] : 0;
     2095        $compare_to = ! empty( $_GET['compare_to'] ) ? absint( $_GET['compare_to'] ) : 0;
     2096        $show_autosaves = ! empty( $_GET['show_autosaves'] );
     2097        $show_split_view = ! empty( $_GET['show_split_view'] );
     2098        $post_id = ! empty( $_GET['post_id'] ) ? absint( $_GET['post_id'] ) : 0;
     2099        $right_handle_at = ! empty( $_GET['right_handle_at'] ) ? $_GET['right_handle_at'] : 0;
     2100        $left_handle_at = ! empty( $_GET['left_handle_at'] ) ? $_GET['left_handle_at'] : 0;
     2101        $single_revision_id = ! empty( $_GET['single_revision_id'] ) ? $_GET['single_revision_id'] : 0;
     2102        $compare_two_mode = (bool) $post_id;
    21022103
    2103         $compare_two_mode = ( '' == $post_id ) ? false : true;
    21042104        //
    21052105        //TODO: currently code returns all possible comparisons for the indicated 'compare_to' revision
    21062106        //however, the front end prevents users from pulling the right handle past the left or the left pass the right,
    21072107        //so only the possible diffs need be generated
    21082108        //
    21092109        $alltherevisions = array();
    2110         if ( '' == $post_id )
     2110        if ( ! $post_id )
    21112111                $post_id = $compare_to;
    21122112
    21132113        if ( ! current_user_can( 'read_post', $post_id ) )
     
    21162116        if ( ! $revisions = wp_get_post_revisions( $post_id ) )
    21172117                return;
    21182118
    2119         /* translators: revision date format, see http://php.net/date */
    2120         $datef = _x( 'j F, Y @ G:i:s', 'revision date format');
    2121 
    21222119        $left_revision = get_post( $compare_to );
    21232120
    21242121        //single model fetch mode
    21252122        //return the diff of a single revision comparison
    2126         if ( 0 != $single_revision_id ) {
     2123        if ( $single_revision_id ) {
    21272124                $right_revision = get_post( $single_revision_id );
    21282125
    2129         if ( 0 == $compare_to )
     2126                if ( ! $compare_to )
    21302127                        $left_revision = get_post( $post_id );
    21312128
    2132         // make sure the right revision is the most recent
    2133         if ( $compare_two_mode && $right_revision->ID < $left_revision->ID ) {
    2134                 $temp = $left_revision;
    2135                 $left_revision = $right_revision;
    2136                 $right_revision = $temp;
    2137         }
     2129                // make sure the right revision is the most recent
     2130                if ( $compare_two_mode && $right_revision->ID < $left_revision->ID ) {
     2131                        $temp = $left_revision;
     2132                        $left_revision = $right_revision;
     2133                        $right_revision = $temp;
     2134                }
    21382135
    2139                 $linesadded=0;
    2140                 $linesdeleted=0;
    2141 
    2142                 //
     2136                $linesadded = $linesdeleted = 0;
     2137                $content = '';
    21432138                //compare from left to right, passed from application
    2144                 //
    2145                 $content='';
    21462139                foreach ( array_keys( _wp_post_revision_fields() ) as $field ) {
    21472140                        $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field, $left_revision, 'left' );
    21482141                        $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field, $right_revision, 'right' );
     
    21512144
    21522145                        $args = array();
    21532146
    2154                         if ( ! empty( $show_split_view ) )
     2147                        if ( $show_split_view )
    21552148                                 $args = array( 'show_split_view' => true );
    21562149
    21572150                        // compare_to == 0 means first revision, so compare to a blank field to show whats changed
    2158                         $diff = wp_text_diff_with_count( ( 0 == $compare_to) ? '' : $left_content, $right_content, $args );
     2151                        $diff = wp_text_diff_with_count( ( 0 == $compare_to ) ? '' : $left_content, $right_content, $args );
    21592152
    21602153                        if ( isset( $diff[ 'html' ] ) )
    21612154                                $content .= $diff[ 'html' ];
     
    21652158
    21662159                        if ( isset( $diff[ 'linesdeleted' ] ) )
    21672160                                $linesdeleted = $linesdeleted + $diff[ 'linesdeleted' ];
    2168 
    2169 
    21702161                }
    21712162                $content = '' == $content ? __( 'No difference' ) : $content;
    21722163
    21732164                $alltherevisions = array (
    2174                         'revisiondiff' => $content,
     2165                        'revisiondiff'  => $content,
    21752166                        'lines_deleted' => $linesdeleted,
    2176                         'lines_added' => $linesadded
     2167                        'lines_added'   => $linesadded
    21772168                );
     2169
    21782170                echo json_encode( $alltherevisions );
    21792171                exit();
    21802172        } //end single model fetch
     
    21862178
    21872179        $previous_revision_id = 0;
    21882180
     2181        /* translators: revision date format, see http://php.net/date */
     2182        $datef = _x( 'j F, Y @ G:i:s', 'revision date format');
     2183
    21892184        foreach ( $revisions as $revision ) :
    2190                 //error_log( ( $show_autosaves  ));
    2191                 if ( empty( $show_autosaves ) && wp_is_post_autosave( $revision ) )
    2192                                 continue;
     2185                if ( $show_autosaves && wp_is_post_autosave( $revision ) )
     2186                        continue;
    21932187
    21942188                $revision_from_date_author = '';
    21952189                $count++;
     
    22302224                        $date
    22312225                );
    22322226
    2233                 $autosavef = __( '%1$s [Autosave]' );
    2234                 $currentf  = __( '%1$s [Current Revision]' );
     2227                $autosavef = _x( '%1$s [Autosave]', 'post revision title extra' );
     2228                $currentf  = _x( '%1$s [Current Revision]', 'post revision title extra' );
    22352229
    2236                 if ( ! $post = get_post( $post_id))
    2237                         exit();
     2230                if ( ! $post = get_post( $post_id ) )
     2231                        exit();  // Should that be `continue;` instead?
    22382232
    22392233                if ( $left_revision->post_modified === $post->post_modified )
    22402234                        $revision_from_date_author = sprintf( $currentf, $revision_from_date_author );
     
    22462240                elseif ( wp_is_post_autosave( $revision ) )
    22472241                        $revision_date_author = sprintf( $autosavef, $revision_date_author );
    22482242
    2249                 $date_short_format = __( 'j M @ G:i' );
     2243                /* translators: revision date short format, see http://php.net/date */
     2244                $date_short_format = _x( 'j M @ G:i', 'revision date short format');
    22502245                $date_short = date_i18n( $date_short_format, strtotime( $revision->post_modified ) );
    22512246
    22522247                $revision_date_author_short = sprintf(
     
    22642259                        ),
    22652260                        "restore-post_{$revision->ID}"
    22662261                );
     2262
    22672263                // if this is a left handled calculation swap data
    22682264                if ( 0 != $right_handle_at ) {
    22692265                        $tmp = $revision_from_date_author;
    22702266                        $revision_from_date_author = $revision_date_author;
    22712267                        $revision_date_author = $tmp;
    22722268                }
     2269
    22732270                if ( ( $compare_two_mode || -1 !== $previous_revision_id ) ) {
    22742271                        $alltherevisions[] = array (
    2275                                 'ID' => $revision->ID,
    2276                                 'revision_date_author' => $revision_date_author,
    2277                                 'revision_from_date_author' => $revision_from_date_author,
     2272                                'ID'                         => $revision->ID,
     2273                                'revision_date_author'       => $revision_date_author,
     2274                                'revision_from_date_author'  => $revision_from_date_author,
    22782275                                'revision_date_author_short' => $revision_date_author_short,
    2279                                 'restoreaction' => urldecode( $restoreaction ),
    2280                                 'revision_toload' => true,
    2281                                 'previous_revision_id' => $previous_revision_id
     2276                                'restoreaction'              => urldecode( $restoreaction ),
     2277                                'revision_toload'            => true,
     2278                                'previous_revision_id'       => $previous_revision_id
    22822279                        );
    22832280                }
    22842281                $previous_revision_id = $revision->ID;