wp/wp-includes/class-wp-text-diff-renderer-table.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
--- a/wp/wp-includes/class-wp-text-diff-renderer-table.php	Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-includes/class-wp-text-diff-renderer-table.php	Tue Dec 15 13:49:49 2020 +0100
@@ -100,7 +100,7 @@
 	/**
 	 * @ignore
 	 *
-	 * @param array $lines
+	 * @param array  $lines
 	 * @param string $prefix
 	 */
 	public function _lines( $lines, $prefix = ' ' ) {
@@ -113,7 +113,7 @@
 	 * @return string
 	 */
 	public function addedLine( $line ) {
-		return "<td class='diff-addedline'>{$line}</td>";
+		return "<td class='diff-addedline'><span aria-hidden='true' class='dashicons dashicons-plus'></span><span class='screen-reader-text'>" . __( 'Added:' ) . " </span>{$line}</td>";
 
 	}
 
@@ -124,7 +124,7 @@
 	 * @return string
 	 */
 	public function deletedLine( $line ) {
-		return "<td class='diff-deletedline'>{$line}</td>";
+		return "<td class='diff-deletedline'><span aria-hidden='true' class='dashicons dashicons-minus'></span><span class='screen-reader-text'>" . __( 'Deleted:' ) . " </span>{$line}</td>";
 	}
 
 	/**
@@ -134,7 +134,7 @@
 	 * @return string
 	 */
 	public function contextLine( $line ) {
-		return "<td class='diff-context'>{$line}</td>";
+		return "<td class='diff-context'><span class='screen-reader-text'>" . __( 'Unchanged:' ) . " </span>{$line}</td>";
 	}
 
 	/**
@@ -150,7 +150,7 @@
 	 * @ignore
 	 *
 	 * @param array $lines
-	 * @param bool $encode
+	 * @param bool  $encode
 	 * @return string
 	 */
 	public function _added( $lines, $encode = true ) {
@@ -168,9 +168,9 @@
 				 *
 				 * @since 4.1.0
 				 *
-				 * @param String $processed_line The processed diffed line.
-				 * @param String $line           The unprocessed diffed line.
-				 * @param string null            The line context. Values are 'added', 'deleted' or 'unchanged'.
+				 * @param string $processed_line The processed diffed line.
+				 * @param string $line           The unprocessed diffed line.
+				 * @param string $context        The line context. Values are 'added', 'deleted' or 'unchanged'.
 				 */
 				$line = apply_filters( 'process_text_diff_html', $processed_line, $line, 'added' );
 			}
@@ -188,7 +188,7 @@
 	 * @ignore
 	 *
 	 * @param array $lines
-	 * @param bool $encode
+	 * @param bool  $encode
 	 * @return string
 	 */
 	public function _deleted( $lines, $encode = true ) {
@@ -213,7 +213,7 @@
 	 * @ignore
 	 *
 	 * @param array $lines
-	 * @param bool $encode
+	 * @param bool  $encode
 	 * @return string
 	 */
 	public function _context( $lines, $encode = true ) {
@@ -249,32 +249,34 @@
 	public function _changed( $orig, $final ) {
 		$r = '';
 
-		// Does the aforementioned additional processing
-		// *_matches tell what rows are "the same" in orig and final. Those pairs will be diffed to get word changes
-		//	match is numeric: an index in other column
-		//	match is 'X': no match. It is a new row
-		// *_rows are column vectors for the orig column and the final column.
-		//	row >= 0: an indix of the $orig or $final array
-		//	row  < 0: a blank row for that column
+		/*
+		 * Does the aforementioned additional processing:
+		 * *_matches tell what rows are "the same" in orig and final. Those pairs will be diffed to get word changes.
+		 * - match is numeric: an index in other column.
+		 * - match is 'X': no match. It is a new row.
+		 * *_rows are column vectors for the orig column and the final column.
+		 * - row >= 0: an indix of the $orig or $final array.
+		 * - row < 0: a blank row for that column.
+		 */
 		list($orig_matches, $final_matches, $orig_rows, $final_rows) = $this->interleave_changed_lines( $orig, $final );
 
-		// These will hold the word changes as determined by an inline diff
+		// These will hold the word changes as determined by an inline diff.
 		$orig_diffs  = array();
 		$final_diffs = array();
 
-		// Compute word diffs for each matched pair using the inline diff
+		// Compute word diffs for each matched pair using the inline diff.
 		foreach ( $orig_matches as $o => $f ) {
 			if ( is_numeric( $o ) && is_numeric( $f ) ) {
 				$text_diff = new Text_Diff( 'auto', array( array( $orig[ $o ] ), array( $final[ $f ] ) ) );
 				$renderer  = new $this->inline_diff_renderer;
 				$diff      = $renderer->render( $text_diff );
 
-				// If they're too different, don't include any <ins> or <dels>
+				// If they're too different, don't include any <ins> or <del>'s.
 				if ( preg_match_all( '!(<ins>.*?</ins>|<del>.*?</del>)!', $diff, $diff_matches ) ) {
-					// length of all text between <ins> or <del>
+					// Length of all text between <ins> or <del>.
 					$stripped_matches = strlen( strip_tags( join( ' ', $diff_matches[0] ) ) );
-					// since we count lengith of text between <ins> or <del> (instead of picking just one),
-					//	we double the length of chars not in those tags.
+					// Since we count length of text between <ins> or <del> (instead of picking just one),
+					// we double the length of chars not in those tags.
 					$stripped_diff = strlen( strip_tags( $diff ) ) * 2 - $stripped_matches;
 					$diff_ratio    = $stripped_matches / $stripped_diff;
 					if ( $diff_ratio > $this->_diff_threshold ) {
@@ -282,7 +284,7 @@
 					}
 				}
 
-				// Un-inline the diffs by removing del or ins
+				// Un-inline the diffs by removing <del> or <ins>.
 				$orig_diffs[ $o ]  = preg_replace( '|<ins>.*?</ins>|', '', $diff );
 				$final_diffs[ $f ] = preg_replace( '|<del>.*?</del>|', '', $diff );
 			}
@@ -335,24 +337,24 @@
 	 * @param array $orig  Lines of the original version of the text.
 	 * @param array $final Lines of the final version of the text.
 	 * @return array {
-	 *    Array containing results of comparing the original text to the final text.
+	 *     Array containing results of comparing the original text to the final text.
 	 *
-	 *    @type array $orig_matches  Associative array of original matches. Index == row
-	 *                               number of `$orig`, value == corresponding row number
-	 *                               of that same line in `$final` or 'x' if there is no
-	 *                               corresponding row (indicating it is a deleted line).
-	 *    @type array $final_matches Associative array of final matches. Index == row
-	 *                               number of `$final`, value == corresponding row number
-	 *                               of that same line in `$orig` or 'x' if there is no
-	 *                               corresponding row (indicating it is a new line).
-	 *    @type array $orig_rows     Associative array of interleaved rows of `$orig` with
-	 *                               blanks to keep matches aligned with side-by-side diff
-	 *                               of `$final`. A value >= 0 corresponds to index of `$orig`.
-	 *                               Value < 0 indicates a blank row.
-	 *    @type array $final_rows    Associative array of interleaved rows of `$final` with
-	 *                               blanks to keep matches aligned with side-by-side diff
-	 *                               of `$orig`. A value >= 0 corresponds to index of `$final`.
-	 *                               Value < 0 indicates a blank row.
+	 *     @type array $orig_matches  Associative array of original matches. Index == row
+	 *                                number of `$orig`, value == corresponding row number
+	 *                                of that same line in `$final` or 'x' if there is no
+	 *                                corresponding row (indicating it is a deleted line).
+	 *     @type array $final_matches Associative array of final matches. Index == row
+	 *                                number of `$final`, value == corresponding row number
+	 *                                of that same line in `$orig` or 'x' if there is no
+	 *                                corresponding row (indicating it is a new line).
+	 *     @type array $orig_rows     Associative array of interleaved rows of `$orig` with
+	 *                                blanks to keep matches aligned with side-by-side diff
+	 *                                of `$final`. A value >= 0 corresponds to index of `$orig`.
+	 *                                Value < 0 indicates a blank row.
+	 *     @type array $final_rows    Associative array of interleaved rows of `$final` with
+	 *                                blanks to keep matches aligned with side-by-side diff
+	 *                                of `$orig`. A value >= 0 corresponds to index of `$final`.
+	 *                                Value < 0 indicates a blank row.
 	 * }
 	 */
 	public function interleave_changed_lines( $orig, $final ) {
@@ -374,34 +376,35 @@
 			$o           = (int) $o;
 			$f           = (int) $f;
 
-			// Already have better matches for these guys
+			// Already have better matches for these guys.
 			if ( isset( $orig_matches[ $o ] ) && isset( $final_matches[ $f ] ) ) {
 				continue;
 			}
 
-			// First match for these guys. Must be best match
+			// First match for these guys. Must be best match.
 			if ( ! isset( $orig_matches[ $o ] ) && ! isset( $final_matches[ $f ] ) ) {
 				$orig_matches[ $o ]  = $f;
 				$final_matches[ $f ] = $o;
 				continue;
 			}
 
-			// Best match of this final is already taken?  Must mean this final is a new row.
+			// Best match of this final is already taken? Must mean this final is a new row.
 			if ( isset( $orig_matches[ $o ] ) ) {
 				$final_matches[ $f ] = 'x';
 			} elseif ( isset( $final_matches[ $f ] ) ) {
-				// Best match of this orig is already taken?  Must mean this orig is a deleted row.
+				// Best match of this orig is already taken? Must mean this orig is a deleted row.
 				$orig_matches[ $o ] = 'x';
 			}
 		}
 
-		// We read the text in this order
+		// We read the text in this order.
 		ksort( $orig_matches );
 		ksort( $final_matches );
 
 		// Stores rows and blanks for each column.
-		$orig_rows  = $orig_rows_copy = array_keys( $orig_matches );
-		$final_rows = array_keys( $final_matches );
+		$orig_rows      = array_keys( $orig_matches );
+		$orig_rows_copy = $orig_rows;
+		$final_rows     = array_keys( $final_matches );
 
 		// Interleaves rows with blanks to keep matches aligned.
 		// We may end up with some extraneous blank rows, but we'll just ignore them later.
@@ -420,7 +423,7 @@
 			}
 		}
 
-		// Pad the ends with blank rows if the columns aren't the same length
+		// Pad the ends with blank rows if the columns aren't the same length.
 		$diff_count = count( $orig_rows ) - count( $final_rows );
 		if ( $diff_count < 0 ) {
 			while ( $diff_count < 0 ) {
@@ -499,7 +502,7 @@
 	 * @return mixed Property.
 	 */
 	public function __get( $name ) {
-		if ( in_array( $name, $this->compat_fields ) ) {
+		if ( in_array( $name, $this->compat_fields, true ) ) {
 			return $this->$name;
 		}
 	}
@@ -514,7 +517,7 @@
 	 * @return mixed Newly-set property.
 	 */
 	public function __set( $name, $value ) {
-		if ( in_array( $name, $this->compat_fields ) ) {
+		if ( in_array( $name, $this->compat_fields, true ) ) {
 			return $this->$name = $value;
 		}
 	}
@@ -528,7 +531,7 @@
 	 * @return bool Whether the property is set.
 	 */
 	public function __isset( $name ) {
-		if ( in_array( $name, $this->compat_fields ) ) {
+		if ( in_array( $name, $this->compat_fields, true ) ) {
 			return isset( $this->$name );
 		}
 	}
@@ -541,7 +544,7 @@
 	 * @param string $name Property to unset.
 	 */
 	public function __unset( $name ) {
-		if ( in_array( $name, $this->compat_fields ) ) {
+		if ( in_array( $name, $this->compat_fields, true ) ) {
 			unset( $this->$name );
 		}
 	}