Make WordPress Core


Ignore:
Timestamp:
01/29/2020 12:43:23 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Docs: Improve inline comments per the documentation standards.

Includes minor code layout fixes for better readability.

See #48303.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-text-diff-renderer-table.php

    r46729 r47122  
    250250        $r = '';
    251251
    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         */
    259261        list($orig_matches, $final_matches, $orig_rows, $final_rows) = $this->interleave_changed_lines( $orig, $final );
    260262
    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.
    262264        $orig_diffs  = array();
    263265        $final_diffs = array();
    264266
    265         // Compute word diffs for each matched pair using the inline diff
     267        // Compute word diffs for each matched pair using the inline diff.
    266268        foreach ( $orig_matches as $o => $f ) {
    267269            if ( is_numeric( $o ) && is_numeric( $f ) ) {
     
    270272                $diff      = $renderer->render( $text_diff );
    271273
    272                 // If they're too different, don't include any <ins> or <dels>
     274                // If they're too different, don't include any <ins> or <del>'s.
    273275                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>.
    275277                    $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.
    278280                    $stripped_diff = strlen( strip_tags( $diff ) ) * 2 - $stripped_matches;
    279281                    $diff_ratio    = $stripped_matches / $stripped_diff;
     
    283285                }
    284286
    285                 // Un-inline the diffs by removing del or ins
     287                // Un-inline the diffs by removing <del> or <ins>.
    286288                $orig_diffs[ $o ]  = preg_replace( '|<ins>.*?</ins>|', '', $diff );
    287289                $final_diffs[ $f ] = preg_replace( '|<del>.*?</del>|', '', $diff );
     
    375377            $f           = (int) $f;
    376378
    377             // Already have better matches for these guys
     379            // Already have better matches for these guys.
    378380            if ( isset( $orig_matches[ $o ] ) && isset( $final_matches[ $f ] ) ) {
    379381                continue;
    380382            }
    381383
    382             // First match for these guys. Must be best match
     384            // First match for these guys. Must be best match.
    383385            if ( ! isset( $orig_matches[ $o ] ) && ! isset( $final_matches[ $f ] ) ) {
    384386                $orig_matches[ $o ]  = $f;
     
    387389            }
    388390
    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.
    390392            if ( isset( $orig_matches[ $o ] ) ) {
    391393                $final_matches[ $f ] = 'x';
    392394            } 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.
    394396                $orig_matches[ $o ] = 'x';
    395397            }
    396398        }
    397399
    398         // We read the text in this order
     400        // We read the text in this order.
    399401        ksort( $orig_matches );
    400402        ksort( $final_matches );
     
    422424        }
    423425
    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.
    425427        $diff_count = count( $orig_rows ) - count( $final_rows );
    426428        if ( $diff_count < 0 ) {
Note: See TracChangeset for help on using the changeset viewer.