Ticket #23920: 23920.2.patch
File 23920.2.patch, 7.1 KB (added by , 12 years ago) |
---|
-
wp-admin/includes/ajax-actions.php
2092 2092 function wp_ajax_revisions_data() { 2093 2093 check_ajax_referer( 'revisions-ajax-nonce', 'nonce' ); 2094 2094 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; 2102 2103 2103 $compare_two_mode = ( '' == $post_id ) ? false : true;2104 2104 // 2105 2105 //TODO: currently code returns all possible comparisons for the indicated 'compare_to' revision 2106 2106 //however, the front end prevents users from pulling the right handle past the left or the left pass the right, 2107 2107 //so only the possible diffs need be generated 2108 2108 // 2109 2109 $alltherevisions = array(); 2110 if ( '' ==$post_id )2110 if ( ! $post_id ) 2111 2111 $post_id = $compare_to; 2112 2112 2113 2113 if ( ! current_user_can( 'read_post', $post_id ) ) … … 2116 2116 if ( ! $revisions = wp_get_post_revisions( $post_id ) ) 2117 2117 return; 2118 2118 2119 /* translators: revision date format, see http://php.net/date */2120 $datef = _x( 'j F, Y @ G:i:s', 'revision date format');2121 2122 2119 $left_revision = get_post( $compare_to ); 2123 2120 2124 2121 //single model fetch mode 2125 2122 //return the diff of a single revision comparison 2126 if ( 0 !=$single_revision_id ) {2123 if ( $single_revision_id ) { 2127 2124 $right_revision = get_post( $single_revision_id ); 2128 2125 2129 if ( 0 ==$compare_to )2126 if ( ! $compare_to ) 2130 2127 $left_revision = get_post( $post_id ); 2131 2128 2132 // make sure the right revision is the most recent2133 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 } 2138 2135 2139 $linesadded=0; 2140 $linesdeleted=0; 2141 2142 // 2136 $linesadded = $linesdeleted = 0; 2137 $content = ''; 2143 2138 //compare from left to right, passed from application 2144 //2145 $content='';2146 2139 foreach ( array_keys( _wp_post_revision_fields() ) as $field ) { 2147 2140 $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field, $left_revision, 'left' ); 2148 2141 $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field, $right_revision, 'right' ); … … 2151 2144 2152 2145 $args = array(); 2153 2146 2154 if ( ! empty( $show_split_view ))2147 if ( $show_split_view ) 2155 2148 $args = array( 'show_split_view' => true ); 2156 2149 2157 2150 // 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 ); 2159 2152 2160 2153 if ( isset( $diff[ 'html' ] ) ) 2161 2154 $content .= $diff[ 'html' ]; … … 2165 2158 2166 2159 if ( isset( $diff[ 'linesdeleted' ] ) ) 2167 2160 $linesdeleted = $linesdeleted + $diff[ 'linesdeleted' ]; 2168 2169 2170 2161 } 2171 2162 $content = '' == $content ? __( 'No difference' ) : $content; 2172 2163 2173 2164 $alltherevisions = array ( 2174 'revisiondiff' => $content,2165 'revisiondiff' => $content, 2175 2166 'lines_deleted' => $linesdeleted, 2176 'lines_added' => $linesadded2167 'lines_added' => $linesadded 2177 2168 ); 2169 2178 2170 echo json_encode( $alltherevisions ); 2179 2171 exit(); 2180 2172 } //end single model fetch … … 2186 2178 2187 2179 $previous_revision_id = 0; 2188 2180 2181 /* translators: revision date format, see http://php.net/date */ 2182 $datef = _x( 'j F, Y @ G:i:s', 'revision date format'); 2183 2189 2184 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; 2193 2187 2194 2188 $revision_from_date_author = ''; 2195 2189 $count++; … … 2230 2224 $date 2231 2225 ); 2232 2226 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' ); 2235 2229 2236 if ( ! $post = get_post( $post_id ))2237 exit(); 2230 if ( ! $post = get_post( $post_id ) ) 2231 exit(); // Should that be `continue;` instead? 2238 2232 2239 2233 if ( $left_revision->post_modified === $post->post_modified ) 2240 2234 $revision_from_date_author = sprintf( $currentf, $revision_from_date_author ); … … 2246 2240 elseif ( wp_is_post_autosave( $revision ) ) 2247 2241 $revision_date_author = sprintf( $autosavef, $revision_date_author ); 2248 2242 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'); 2250 2245 $date_short = date_i18n( $date_short_format, strtotime( $revision->post_modified ) ); 2251 2246 2252 2247 $revision_date_author_short = sprintf( … … 2264 2259 ), 2265 2260 "restore-post_{$revision->ID}" 2266 2261 ); 2262 2267 2263 // if this is a left handled calculation swap data 2268 2264 if ( 0 != $right_handle_at ) { 2269 2265 $tmp = $revision_from_date_author; 2270 2266 $revision_from_date_author = $revision_date_author; 2271 2267 $revision_date_author = $tmp; 2272 2268 } 2269 2273 2270 if ( ( $compare_two_mode || -1 !== $previous_revision_id ) ) { 2274 2271 $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, 2278 2275 'revision_date_author_short' => $revision_date_author_short, 2279 'restoreaction' => urldecode( $restoreaction ),2280 'revision_toload' => true,2281 'previous_revision_id' => $previous_revision_id2276 'restoreaction' => urldecode( $restoreaction ), 2277 'revision_toload' => true, 2278 'previous_revision_id' => $previous_revision_id 2282 2279 ); 2283 2280 } 2284 2281 $previous_revision_id = $revision->ID;