From 35aaaacc044c12e1b4c4a3cd3b90578a7e79a65e Mon Sep 17 00:00:00 2001 From: joedolson Date: Wed, 27 Jan 2021 21:53:58 +0000 Subject: [PATCH] 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 --- wp-admin/includes/revision.php | 2 ++ .../class-wp-text-diff-renderer-table.php | 8 ++--- wp-includes/pluggable.php | 29 +++++++++++-------- wp-includes/version.php | 2 +- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/wp-admin/includes/revision.php b/wp-admin/includes/revision.php index e5f480d0ed..496282529c 100644 --- a/wp-admin/includes/revision.php +++ b/wp-admin/includes/revision.php @@ -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' ), ); /** diff --git a/wp-includes/class-wp-text-diff-renderer-table.php b/wp-includes/class-wp-text-diff-renderer-table.php index c55add4885..3db5a51d85 100644 --- a/wp-includes/class-wp-text-diff-renderer-table.php +++ b/wp-includes/class-wp-text-diff-renderer-table.php @@ -176,7 +176,7 @@ class WP_Text_Diff_Renderer_Table extends Text_Diff_Renderer { } if ( $this->_show_split_view ) { - $r .= '' . $this->emptyLine() . $this->emptyLine() . $this->addedLine( $line ) . "\n"; + $r .= '' . $this->emptyLine() . $this->addedLine( $line ) . "\n"; } else { $r .= '' . $this->addedLine( $line ) . "\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 .= '' . $this->deletedLine( $line ) . $this->emptyLine() . $this->emptyLine() . "\n"; + $r .= '' . $this->deletedLine( $line ) . $this->emptyLine() . "\n"; } else { $r .= '' . $this->deletedLine( $line ) . "\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 .= '' . $this->contextLine( $line ) . $this->emptyLine() . $this->contextLine( $line ) . "\n"; + $r .= '' . $this->contextLine( $line ) . $this->contextLine( $line ) . "\n"; } else { $r .= '' . $this->contextLine( $line ) . "\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 .= '' . $this->deletedLine( $orig_line ) . $this->emptyLine() . $this->addedLine( $final_line ) . "\n"; + $r .= '' . $this->deletedLine( $orig_line ) . $this->addedLine( $final_line ) . "\n"; } else { $r .= '' . $this->deletedLine( $orig_line ) . '' . $this->addedLine( $final_line ) . "\n"; } diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index 7dee482170..c53a723fc4 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -2838,27 +2838,32 @@ if ( ! function_exists( 'wp_text_diff' ) ) : return ''; } - $r = "\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 .= ""; - } else { - $r .= ""; + $r = "
\n"; + + if ( $args['title'] ) { + $r .= "\n"; } - if ( $args['title'] || $args['title_left'] || $args['title_right'] ) { + if ( $args['title_left'] || $args['title_right'] ) { $r .= ''; } - if ( $args['title'] ) { - $r .= "\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 .= "\n"; - $r .= "\t\n"; - $r .= "\t\n"; + $r .= "\t<$th_or_td_left>$args[title_left]\n"; + if ( $is_split_view ) { + $r .= "\t<$th_or_td_right>$args[title_right]\n"; + } $r .= "\n"; } - if ( $args['title'] || $args['title_left'] || $args['title_right'] ) { + + if ( $args['title_left'] || $args['title_right'] ) { $r .= "\n"; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 44530b1487..f612b2775a 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.
$args[title]
$args[title]
$args[title_left]$args[title_right]