Introduce two new filters to the post revisions screen:

* `process_text_diff_html` for contextually filtering a diffed line. Allows for the line to be processed in a different manner to the default `htmlspecialchars`.
 * `revision_text_diff_options` for filtering the options passed to `wp_text_diff()` when viewing a post revision.

Fixes #24908
Props adamsilverstein


git-svn-id: https://develop.svn.wordpress.org/trunk@30396 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn
2014-11-19 23:20:07 +00:00
parent 8e3b2a3b00
commit b670f503e5
2 changed files with 51 additions and 7 deletions

View 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,11 @@ 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 +218,11 @@ 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 {