- Timestamp:
- 01/29/2020 12:43:23 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-text-diff-renderer-table.php
r46729 r47122 250 250 $r = ''; 251 251 252 // Does the aforementioned additional processing 253 // *_matches tell what rows are "the same" in orig and final. Those pairs will be diffed to get word changes 254 // match is numeric: an index in other column 255 // match is 'X': no match. It is a new row 256 // *_rows are column vectors for the orig column and the final column. 257 // row >= 0: an indix of the $orig or $final array 258 // row < 0: a blank row for that column 252 /* 253 * Does the aforementioned additional processing: 254 * *_matches tell what rows are "the same" in orig and final. Those pairs will be diffed to get word changes. 255 * - match is numeric: an index in other column. 256 * - match is 'X': no match. It is a new row. 257 * *_rows are column vectors for the orig column and the final column. 258 * - row >= 0: an indix of the $orig or $final array. 259 * - row < 0: a blank row for that column. 260 */ 259 261 list($orig_matches, $final_matches, $orig_rows, $final_rows) = $this->interleave_changed_lines( $orig, $final ); 260 262 261 // These will hold the word changes as determined by an inline diff 263 // These will hold the word changes as determined by an inline diff. 262 264 $orig_diffs = array(); 263 265 $final_diffs = array(); 264 266 265 // Compute word diffs for each matched pair using the inline diff 267 // Compute word diffs for each matched pair using the inline diff. 266 268 foreach ( $orig_matches as $o => $f ) { 267 269 if ( is_numeric( $o ) && is_numeric( $f ) ) { … … 270 272 $diff = $renderer->render( $text_diff ); 271 273 272 // If they're too different, don't include any <ins> or <del s>274 // If they're too different, don't include any <ins> or <del>'s. 273 275 if ( preg_match_all( '!(<ins>.*?</ins>|<del>.*?</del>)!', $diff, $diff_matches ) ) { 274 // length of all text between <ins> or <del>276 // Length of all text between <ins> or <del>. 275 277 $stripped_matches = strlen( strip_tags( join( ' ', $diff_matches[0] ) ) ); 276 // since we count lengith of text between <ins> or <del> (instead of picking just one),277 // we double the length of chars not in those tags.278 // Since we count length of text between <ins> or <del> (instead of picking just one), 279 // we double the length of chars not in those tags. 278 280 $stripped_diff = strlen( strip_tags( $diff ) ) * 2 - $stripped_matches; 279 281 $diff_ratio = $stripped_matches / $stripped_diff; … … 283 285 } 284 286 285 // Un-inline the diffs by removing del or ins287 // Un-inline the diffs by removing <del> or <ins>. 286 288 $orig_diffs[ $o ] = preg_replace( '|<ins>.*?</ins>|', '', $diff ); 287 289 $final_diffs[ $f ] = preg_replace( '|<del>.*?</del>|', '', $diff ); … … 375 377 $f = (int) $f; 376 378 377 // Already have better matches for these guys 379 // Already have better matches for these guys. 378 380 if ( isset( $orig_matches[ $o ] ) && isset( $final_matches[ $f ] ) ) { 379 381 continue; 380 382 } 381 383 382 // First match for these guys. Must be best match 384 // First match for these guys. Must be best match. 383 385 if ( ! isset( $orig_matches[ $o ] ) && ! isset( $final_matches[ $f ] ) ) { 384 386 $orig_matches[ $o ] = $f; … … 387 389 } 388 390 389 // Best match of this final is already taken? Must mean this final is a new row.391 // Best match of this final is already taken? Must mean this final is a new row. 390 392 if ( isset( $orig_matches[ $o ] ) ) { 391 393 $final_matches[ $f ] = 'x'; 392 394 } elseif ( isset( $final_matches[ $f ] ) ) { 393 // Best match of this orig is already taken? Must mean this orig is a deleted row.395 // Best match of this orig is already taken? Must mean this orig is a deleted row. 394 396 $orig_matches[ $o ] = 'x'; 395 397 } 396 398 } 397 399 398 // We read the text in this order 400 // We read the text in this order. 399 401 ksort( $orig_matches ); 400 402 ksort( $final_matches ); … … 422 424 } 423 425 424 // Pad the ends with blank rows if the columns aren't the same length 426 // Pad the ends with blank rows if the columns aren't the same length. 425 427 $diff_count = count( $orig_rows ) - count( $final_rows ); 426 428 if ( $diff_count < 0 ) {
Note: See TracChangeset
for help on using the changeset viewer.