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
Built from https://develop.svn.wordpress.org/trunk@50034


git-svn-id: http://core.svn.wordpress.org/trunk@49735 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
joedolson 2021-01-27 21:53:58 +00:00
parent 830d3942a0
commit 35aaaacc04
4 changed files with 24 additions and 17 deletions

View File

@ -86,6 +86,8 @@ function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
$args = array(
'show_split_view' => true,
'title_left' => __( 'Removed' ),
'title_right' => __( 'Added' ),
);
/**

View File

@ -176,7 +176,7 @@ class WP_Text_Diff_Renderer_Table extends Text_Diff_Renderer {
}
if ( $this->_show_split_view ) {
$r .= '<tr>' . $this->emptyLine() . $this->emptyLine() . $this->addedLine( $line ) . "</tr>\n";
$r .= '<tr>' . $this->emptyLine() . $this->addedLine( $line ) . "</tr>\n";
} else {
$r .= '<tr>' . $this->addedLine( $line ) . "</tr>\n";
}
@ -201,7 +201,7 @@ class WP_Text_Diff_Renderer_Table extends Text_Diff_Renderer {
$line = apply_filters( 'process_text_diff_html', $processed_line, $line, 'deleted' );
}
if ( $this->_show_split_view ) {
$r .= '<tr>' . $this->deletedLine( $line ) . $this->emptyLine() . $this->emptyLine() . "</tr>\n";
$r .= '<tr>' . $this->deletedLine( $line ) . $this->emptyLine() . "</tr>\n";
} else {
$r .= '<tr>' . $this->deletedLine( $line ) . "</tr>\n";
}
@ -226,7 +226,7 @@ class WP_Text_Diff_Renderer_Table extends Text_Diff_Renderer {
$line = apply_filters( 'process_text_diff_html', $processed_line, $line, 'unchanged' );
}
if ( $this->_show_split_view ) {
$r .= '<tr>' . $this->contextLine( $line ) . $this->emptyLine() . $this->contextLine( $line ) . "</tr>\n";
$r .= '<tr>' . $this->contextLine( $line ) . $this->contextLine( $line ) . "</tr>\n";
} else {
$r .= '<tr>' . $this->contextLine( $line ) . "</tr>\n";
}
@ -319,7 +319,7 @@ class WP_Text_Diff_Renderer_Table extends Text_Diff_Renderer {
$r .= $this->_deleted( array( $orig_line ), false );
} else { // A true changed row.
if ( $this->_show_split_view ) {
$r .= '<tr>' . $this->deletedLine( $orig_line ) . $this->emptyLine() . $this->addedLine( $final_line ) . "</tr>\n";
$r .= '<tr>' . $this->deletedLine( $orig_line ) . $this->addedLine( $final_line ) . "</tr>\n";
} else {
$r .= '<tr>' . $this->deletedLine( $orig_line ) . '</tr><tr>' . $this->addedLine( $final_line ) . "</tr>\n";
}

View File

@ -2838,27 +2838,32 @@ if ( ! function_exists( 'wp_text_diff' ) ) :
return '';
}
$r = "<table class='diff'>\n";
$is_split_view = ! empty( $args['show_split_view'] );
$is_split_view_class = $is_split_view ? ' is-split-view' : '';
if ( ! empty( $args['show_split_view'] ) ) {
$r .= "<col class='content diffsplit left' /><col class='content diffsplit middle' /><col class='content diffsplit right' />";
} else {
$r .= "<col class='content' />";
$r = "<table class='diff$is_split_view_class'>\n";
if ( $args['title'] ) {
$r .= "<caption class='diff-title'>$args[title]</caption>\n";
}
if ( $args['title'] || $args['title_left'] || $args['title_right'] ) {
if ( $args['title_left'] || $args['title_right'] ) {
$r .= '<thead>';
}
if ( $args['title'] ) {
$r .= "<tr class='diff-title'><th colspan='4'>$args[title]</th></tr>\n";
}
if ( $args['title_left'] || $args['title_right'] ) {
$th_or_td_left = empty( $args['title_left'] ) ? 'td' : 'th';
$th_or_td_right = empty( $args['title_right'] ) ? 'td' : 'th';
$r .= "<tr class='diff-sub-title'>\n";
$r .= "\t<td></td><th>$args[title_left]</th>\n";
$r .= "\t<td></td><th>$args[title_right]</th>\n";
$r .= "\t<$th_or_td_left>$args[title_left]</$th_or_td_left>\n";
if ( $is_split_view ) {
$r .= "\t<$th_or_td_right>$args[title_right]</$th_or_td_right>\n";
}
$r .= "</tr>\n";
}
if ( $args['title'] || $args['title_left'] || $args['title_right'] ) {
if ( $args['title_left'] || $args['title_right'] ) {
$r .= "</thead>\n";
}

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.7-alpha-50033';
$wp_version = '5.7-alpha-50034';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.