Make WordPress Core

Changeset 50034


Ignore:
Timestamp:
01/27/2021 09:52:10 PM (4 years ago)
Author:
joedolson
Message:

Revisions: Generate correct number of columns in wp_text_diff.

The function wp_text_diff generated an invalid table structure if the $args parameter contained any values. This patch corrects the structure generated by wp_text_diff and related usages so that the column count matches the data generated. Additionally, this patch passes arguments to the Revisions screen so that the screen has column headings that reflect the content in each column. Improves the accessibility and usability of the Revisions table.

Props joedolson, mehulkaklotar, afercia, adamsilverstein, zodiac1978, jeremyfelt
Fixes #25473

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/revision.php

    r49927 r50034  
    8787        $args = array(
    8888            'show_split_view' => true,
     89            'title_left'      => __( 'Removed' ),
     90            'title_right'     => __( 'Added' ),
    8991        );
    9092
  • trunk/src/wp-includes/class-wp-text-diff-renderer-table.php

    r49193 r50034  
    177177
    178178            if ( $this->_show_split_view ) {
    179                 $r .= '<tr>' . $this->emptyLine() . $this->emptyLine() . $this->addedLine( $line ) . "</tr>\n";
     179                $r .= '<tr>' . $this->emptyLine() . $this->addedLine( $line ) . "</tr>\n";
    180180            } else {
    181181                $r .= '<tr>' . $this->addedLine( $line ) . "</tr>\n";
     
    202202            }
    203203            if ( $this->_show_split_view ) {
    204                 $r .= '<tr>' . $this->deletedLine( $line ) . $this->emptyLine() . $this->emptyLine() . "</tr>\n";
     204                $r .= '<tr>' . $this->deletedLine( $line ) . $this->emptyLine() . "</tr>\n";
    205205            } else {
    206206                $r .= '<tr>' . $this->deletedLine( $line ) . "</tr>\n";
     
    227227            }
    228228            if ( $this->_show_split_view ) {
    229                 $r .= '<tr>' . $this->contextLine( $line ) . $this->emptyLine() . $this->contextLine( $line ) . "</tr>\n";
     229                $r .= '<tr>' . $this->contextLine( $line ) . $this->contextLine( $line ) . "</tr>\n";
    230230            } else {
    231231                $r .= '<tr>' . $this->contextLine( $line ) . "</tr>\n";
     
    320320            } else { // A true changed row.
    321321                if ( $this->_show_split_view ) {
    322                     $r .= '<tr>' . $this->deletedLine( $orig_line ) . $this->emptyLine() . $this->addedLine( $final_line ) . "</tr>\n";
     322                    $r .= '<tr>' . $this->deletedLine( $orig_line ) . $this->addedLine( $final_line ) . "</tr>\n";
    323323                } else {
    324324                    $r .= '<tr>' . $this->deletedLine( $orig_line ) . '</tr><tr>' . $this->addedLine( $final_line ) . "</tr>\n";
  • trunk/src/wp-includes/pluggable.php

    r49844 r50034  
    28392839        }
    28402840
    2841         $r = "<table class='diff'>\n";
    2842 
    2843         if ( ! empty( $args['show_split_view'] ) ) {
    2844             $r .= "<col class='content diffsplit left' /><col class='content diffsplit middle' /><col class='content diffsplit right' />";
    2845         } else {
    2846             $r .= "<col class='content' />";
    2847         }
    2848 
    2849         if ( $args['title'] || $args['title_left'] || $args['title_right'] ) {
     2841        $is_split_view       = ! empty( $args['show_split_view'] );
     2842        $is_split_view_class = $is_split_view ? ' is-split-view' : '';
     2843
     2844        $r = "<table class='diff$is_split_view_class'>\n";
     2845
     2846        if ( $args['title'] ) {
     2847            $r .= "<caption class='diff-title'>$args[title]</caption>\n";
     2848        }
     2849
     2850        if ( $args['title_left'] || $args['title_right'] ) {
    28502851            $r .= '<thead>';
    28512852        }
    2852         if ( $args['title'] ) {
    2853             $r .= "<tr class='diff-title'><th colspan='4'>$args[title]</th></tr>\n";
    2854         }
     2853
    28552854        if ( $args['title_left'] || $args['title_right'] ) {
     2855            $th_or_td_left  = empty( $args['title_left'] ) ? 'td' : 'th';
     2856            $th_or_td_right = empty( $args['title_right'] ) ? 'td' : 'th';
     2857
    28562858            $r .= "<tr class='diff-sub-title'>\n";
    2857             $r .= "\t<td></td><th>$args[title_left]</th>\n";
    2858             $r .= "\t<td></td><th>$args[title_right]</th>\n";
     2859            $r .= "\t<$th_or_td_left>$args[title_left]</$th_or_td_left>\n";
     2860            if ( $is_split_view ) {
     2861                $r .= "\t<$th_or_td_right>$args[title_right]</$th_or_td_right>\n";
     2862            }
    28592863            $r .= "</tr>\n";
    28602864        }
    2861         if ( $args['title'] || $args['title_left'] || $args['title_right'] ) {
     2865
     2866        if ( $args['title_left'] || $args['title_right'] ) {
    28622867            $r .= "</thead>\n";
    28632868        }
Note: See TracChangeset for help on using the changeset viewer.