Introduce normalize_whitespace(). Use it instead of wp_text_diff() when checking for identical autosave revisions. Props tellyworth. fixes #7691

git-svn-id: http://svn.automattic.com/wordpress/trunk@9302 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-10-23 20:03:16 +00:00
parent 77f5447071
commit 33f8a5e080
3 changed files with 11 additions and 8 deletions

View File

@ -45,7 +45,7 @@ if ( 0 == $post_ID ) {
// Detect if there exists an autosave newer than the post and if that autosave is different than the post
if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt ) > mysql2date( 'U', $post->post_modified_gmt ) ) {
foreach ( _wp_post_revision_fields() as $autosave_field => $_autosave_field ) {
if ( wp_text_diff( $autosave->$autosave_field, $post->$autosave_field ) ) {
if ( normalize_whitespace( $autosave->$autosave_field ) != normalize_whitespace( $post->$autosave_field ) ) {
$notice = sprintf( $notices[1], get_edit_post_link( $autosave->ID ) );
break;
}

View File

@ -2144,4 +2144,12 @@ function _links_add_target( $m, $target ) {
return '<' . $tag . $link . ' target="' . $target . '">';
}
// normalize EOL characters and strip duplicate whitespace
function normalize_whitespace( $str ) {
$str = trim($str);
$str = str_replace("\r", "\n", $str);
$str = preg_replace( array( '/\n+/', '/[ \t]+/' ), array( "\n", ' ' ), $str );
return $str;
}
?>

View File

@ -1663,13 +1663,8 @@ function wp_text_diff( $left_string, $right_string, $args = null ) {
if ( !class_exists( 'WP_Text_Diff_Renderer_Table' ) )
require( ABSPATH . WPINC . '/wp-diff.php' );
// Normalize whitespace
$left_string = trim($left_string);
$right_string = trim($right_string);
$left_string = str_replace("\r", "\n", $left_string);
$right_string = str_replace("\r", "\n", $right_string);
$left_string = preg_replace( array( '/\n+/', '/[ \t]+/' ), array( "\n", ' ' ), $left_string );
$right_string = preg_replace( array( '/\n+/', '/[ \t]+/' ), array( "\n", ' ' ), $right_string );
$left_string = normalize_whitespace($left_string);
$right_string = normalize_whitespace($right_string);
$left_lines = split("\n", $left_string);
$right_lines = split("\n", $right_string);