WordPress 4.1.1-scripts
[autoinstalls/wordpress.git] / wp-includes / wp-diff.php
index 4901a4376bf8ae008f011ff475f28ca8e67bc786..77efd45533c27a5534cc4713d16354721e5ee729 100644 (file)
@@ -153,8 +153,25 @@ class WP_Text_Diff_Renderer_Table extends Text_Diff_Renderer {
        public function _added( $lines, $encode = true ) {
                $r = '';
                foreach ($lines as $line) {
-                       if ( $encode )
-                               $line = htmlspecialchars( $line );
+                       if ( $encode ) {
+                               $processed_line = htmlspecialchars( $line );
+
+                               /**
+                                * Contextually filter a diffed line.
+                                *
+                                * Filters TextDiff processing of diffed line. By default, diffs are processed with
+                                * htmlspecialchars. Use this filter to remove or change the processing. Passes a context
+                                * indicating if the line is added, deleted or unchanged.
+                                *
+                                * @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'.
+                                */
+                               $line = apply_filters( 'process_text_diff_html', $processed_line, $line, 'added' );
+                       }
+
                        if ( $this->_show_split_view ) {
                                $r .= '<tr>' . $this->emptyLine() . $this->emptyLine() . $this->addedLine( $line ) . "</tr>\n";
                        } else {
@@ -175,8 +192,12 @@ class WP_Text_Diff_Renderer_Table extends Text_Diff_Renderer {
        public function _deleted( $lines, $encode = true ) {
                $r = '';
                foreach ($lines as $line) {
-                       if ( $encode )
-                               $line = htmlspecialchars( $line );
+                       if ( $encode ) {
+                               $processed_line = htmlspecialchars( $line );
+
+                               /** This filter is documented in wp-includes/wp-diff.php */
+                               $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";
                        } else {
@@ -198,8 +219,12 @@ class WP_Text_Diff_Renderer_Table extends Text_Diff_Renderer {
        public function _context( $lines, $encode = true ) {
                $r = '';
                foreach ($lines as $line) {
-                       if ( $encode )
-                               $line = htmlspecialchars( $line );
+                       if ( $encode ) {
+                               $processed_line = htmlspecialchars( $line );
+
+                               /** This filter is documented in wp-includes/wp-diff.php */
+                               $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";
                        } else {
@@ -309,9 +334,9 @@ class WP_Text_Diff_Renderer_Table extends Text_Diff_Renderer {
         *
         * @since 2.6.0
         *
-        * @param unknown_type $orig
-        * @param unknown_type $final
-        * @return unknown
+        * @param array $orig
+        * @param array $final
+        * @return array
         */
        public function interleave_changed_lines( $orig, $final ) {