Changeset 23898 for trunk/wp-admin/includes/ajax-actions.php
- Timestamp:
- 04/04/2013 07:53:49 AM (13 years ago)
- File:
-
- 1 edited
-
trunk/wp-admin/includes/ajax-actions.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/ajax-actions.php
r23890 r23898 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;2102 2103 $compare_two_mode = ( '' == $post_id ) ? false : true; 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'] ) ? (int) $_GET['right_handle_at'] : 0; 2100 $left_handle_at = ! empty( $_GET['left_handle_at'] ) ? (int) $_GET['left_handle_at'] : 0; 2101 $single_revision_id = ! empty( $_GET['single_revision_id'] ) ? absint( $_GET['single_revision_id'] ) : 0; 2102 $compare_two_mode = (bool) $post_id; 2103 2104 2104 // 2105 2105 //TODO: currently code returns all possible comparisons for the indicated 'compare_to' revision … … 2107 2107 //so only the possible diffs need be generated 2108 2108 // 2109 $all therevisions = array();2110 if ( '' ==$post_id )2109 $all_the_revisions = array(); 2110 if ( ! $post_id ) 2111 2111 $post_id = $compare_to; 2112 2112 … … 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 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 } 2138 2139 $linesadded=0; 2140 $linesdeleted=0; 2141 2142 // 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 } 2135 2136 $lines_added = $lines_deleted = 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' ); … … 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' ]; 2162 2155 2163 if ( isset( $diff[ 'linesadded' ] ) ) 2164 $linesadded = $linesadded + $diff[ 'linesadded' ]; 2165 2166 if ( isset( $diff[ 'linesdeleted' ] ) ) 2167 $linesdeleted = $linesdeleted + $diff[ 'linesdeleted' ]; 2168 2169 2156 if ( isset( $diff[ 'lines_added' ] ) ) 2157 $lines_added = $lines_added + $diff[ 'lines_added' ]; 2158 2159 if ( isset( $diff[ 'lines_deleted' ] ) ) 2160 $lines_deleted = $lines_deleted + $diff[ 'lines_deleted' ]; 2170 2161 } 2171 2162 $content = '' == $content ? __( 'No difference' ) : $content; 2172 2163 2173 $all therevisions = array (2174 ' revisiondiff'=> $content,2175 'lines_deleted' => $lines deleted,2176 'lines_added' => $linesadded2164 $all_the_revisions = array ( 2165 'diff' => $content, 2166 'lines_deleted' => $lines_deleted, 2167 'lines_added' => $lines_added 2177 2168 ); 2178 echo json_encode( $alltherevisions ); 2169 2170 echo json_encode( $all_the_revisions ); 2179 2171 exit(); 2180 2172 } //end single model fetch … … 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 = ''; … … 2196 2190 // return blank data for diffs to the left of the left handle (for right handel model) 2197 2191 // or to the right of the right handle (for left handel model) 2198 if ( ( 0 != $left_handle_at && $count < =$left_handle_at ) ||2199 ( 0 != $right_handle_at && $count > $right_handle_at )) {2200 $all therevisions[] = array (2192 if ( ( 0 != $left_handle_at && $count < $left_handle_at ) || 2193 ( 0 != $right_handle_at && $count > ( $right_handle_at - 2 ) ) ) { 2194 $all_the_revisions[] = array ( 2201 2195 'ID' => $revision->ID, 2202 2196 ); … … 2231 2225 ); 2232 2226 2233 $autosavef = _ _( '%1$s [Autosave]' );2234 $currentf = _ _( '%1$s [Current Revision]' );2235 2236 if ( ! $post = get_post( $post_id ))2237 exit();2227 $autosavef = _x( '%1$s [Autosave]', 'post revision title extra' ); 2228 $currentf = _x( '%1$s [Current Revision]', 'post revision title extra' ); 2229 2230 if ( ! $post = get_post( $post_id ) ) 2231 continue; 2238 2232 2239 2233 if ( $left_revision->post_modified === $post->post_modified ) … … 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 … … 2257 2252 ); 2258 2253 2259 $restore action= wp_nonce_url(2254 $restore_link = wp_nonce_url( 2260 2255 add_query_arg( 2261 2256 array( 'revision' => $revision->ID, … … 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 ) { … … 2271 2267 $revision_date_author = $tmp; 2272 2268 } 2269 2273 2270 if ( ( $compare_two_mode || -1 !== $previous_revision_id ) ) { 2274 $all therevisions[] = array (2275 'ID' => $revision->ID,2276 ' revision_date_author'=> $revision_date_author,2277 ' revision_from_date_author'=> $revision_from_date_author,2278 ' revision_date_author_short'=> $revision_date_author_short,2279 'restore action' => urldecode( $restoreaction),2280 'revision_toload' => true,2271 $all_the_revisions[] = array ( 2272 'ID' => $revision->ID, 2273 'titleTo' => $revision_date_author, 2274 'titleFrom' => $revision_from_date_author, 2275 'titleTooltip' => $revision_date_author_short, 2276 'restoreLink' => urldecode( $restore_link ), 2277 'revision_toload' => true, 2281 2278 'previous_revision_id' => $previous_revision_id 2282 2279 ); … … 2286 2283 endforeach; 2287 2284 2288 echo json_encode( $all therevisions );2285 echo json_encode( $all_the_revisions ); 2289 2286 exit(); 2290 2287 }
Note: See TracChangeset
for help on using the changeset viewer.