Ticket #23920: 23920.patch
| File 23920.patch, 4.6 KB (added by , 13 years ago) |
|---|
-
wp-admin/includes/ajax-actions.php
2096 2096 function wp_ajax_revisions_data() { 2097 2097 check_ajax_referer( 'revisions-ajax-nonce', 'nonce' ); 2098 2098 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; 2106 2106 2107 $compare_two_mode = ( '' == $post_id ) ? false : true;2107 $compare_two_mode = (bool) $post_id; 2108 2108 // 2109 2109 //TODO: currently code returns all possible comparisons for the indicated 'compare_to' revision 2110 2110 //however, the front end prevents users from pulling the right handle past the left or the left pass the right, 2111 2111 //so only the possible diffs need be generated 2112 2112 // 2113 2113 $alltherevisions = array(); 2114 if ( '' ==$post_id )2114 if ( ! $post_id ) 2115 2115 $post_id = $compare_to; 2116 2116 2117 2117 if ( ! current_user_can( 'read_post', $post_id ) ) … … 2127 2127 2128 2128 //single model fetch mode 2129 2129 //return the diff of a single revision comparison 2130 if ( 0 !=$single_revision_id ) {2130 if ( $single_revision_id ) { 2131 2131 $right_revision = get_post( $single_revision_id ); 2132 2132 2133 if ( 0 ==$compare_to )2133 if ( ! $compare_to ) 2134 2134 $left_revision = get_post( $post_id ); 2135 2135 2136 // make sure the right revision is the most recent2137 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 } 2142 2142 2143 $linesadded=0; 2144 $linesdeleted=0; 2145 2143 $linesadded = $linesdeleted = 0; 2144 $content = ''; 2146 2145 // 2147 2146 //compare from left to right, passed from application 2148 2147 // 2149 $content='';2150 2148 foreach ( array_keys( _wp_post_revision_fields() ) as $field ) { 2151 2149 $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field, $left_revision, 'left' ); 2152 2150 $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field, $right_revision, 'right' ); … … 2155 2153 2156 2154 $args = array(); 2157 2155 2158 if ( ! empty( $show_split_view ))2156 if ( $show_split_view ) 2159 2157 $args = array( 'show_split_view' => true ); 2160 2158 2161 2159 // compare_to == 0 means first revision, so compare to a blank field to show whats changed … … 2169 2167 2170 2168 if ( isset( $diff[ 'linesdeleted' ] ) ) 2171 2169 $linesdeleted = $linesdeleted + $diff[ 'linesdeleted' ]; 2170 } 2172 2171 2173 2174 }2175 2172 $content = '' == $content ? __( 'No difference' ) : $content; 2176 2173 2177 2174 $alltherevisions = array ( … … 2179 2176 'lines_deleted' => $linesdeleted, 2180 2177 'lines_added' => $linesadded 2181 2178 ); 2179 2182 2180 echo json_encode( $alltherevisions ); 2183 2181 exit(); 2184 2182 } //end single model fetch … … 2192 2190 2193 2191 foreach ( $revisions as $revision ) : 2194 2192 //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; 2197 2195 2198 2196 $revision_from_date_author = ''; 2199 2197 $count++; … … 2237 2235 $autosavef = __( '%1$s [Autosave]' ); 2238 2236 $currentf = __( '%1$s [Current Revision]' ); 2239 2237 2240 if ( ! $post = get_post( $post_id ))2241 exit(); 2238 if ( ! $post = get_post( $post_id ) ) 2239 exit(); // Should that be `continue;` instead? 2242 2240 2243 2241 if ( $left_revision->post_modified === $post->post_modified ) 2244 2242 $revision_from_date_author = sprintf( $currentf, $revision_from_date_author );