Make WordPress Core


Ignore:
Timestamp:
06/26/2013 09:06:50 PM (13 years ago)
Author:
markjaquith
Message:

Cleanup of the revisions screen, both on the PHP API side, and the JS.

  • Much simpler PHP API
  • Cleaner and more Backbone-y JS API
  • Consequently, does batch queries; this now scales up to hundreds of revisions

Currently missing, but much easier considering the cleaned up base:

  • Compare two mode
  • RTL

props koopersmith, nacin, adamsilverstein, ocean90. see #24425

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/revision.php

    r24414 r24520  
    598598    return true;
    599599}
    600 
    601 /**
    602  * Displays a human readable HTML representation of the difference between two strings.
    603  * similar to wp_text_diff, but tracks and returns could of lines added and removed
    604  *
    605  * @since 3.6.0
    606  *
    607  * @see wp_parse_args() Used to change defaults to user defined settings.
    608  * @uses Text_Diff
    609  * @uses WP_Text_Diff_Renderer_Table
    610  *
    611  * @param string $left_string "old" (left) version of string
    612  * @param string $right_string "new" (right) version of string
    613  * @param string|array $args Optional. Change 'title', 'title_left', and 'title_right' defaults.
    614  * @return array contains html, linesadded & linesdeletd, empty string if strings are equivalent.
    615  */
    616 function wp_text_diff_with_count( $left_string, $right_string, $args = null ) {
    617     $defaults = array( 'title' => '', 'title_left' => '', 'title_right' => '' );
    618     $args = wp_parse_args( $args, $defaults );
    619 
    620     if ( ! class_exists( 'WP_Text_Diff_Renderer_Table' ) )
    621             require( ABSPATH . WPINC . '/wp-diff.php' );
    622 
    623     $left_string  = normalize_whitespace( $left_string );
    624     $right_string = normalize_whitespace( $right_string );
    625 
    626     $left_lines  = explode( "\n", $left_string );
    627     $right_lines = explode( "\n", $right_string) ;
    628 
    629     $text_diff = new Text_Diff($left_lines, $right_lines  );
    630     $lines_added = $text_diff->countAddedLines();
    631     $lines_deleted = $text_diff->countDeletedLines();
    632 
    633     $renderer  = new WP_Text_Diff_Renderer_Table();
    634     $diff = $renderer->render( $text_diff );
    635 
    636     if ( !$diff )
    637             return '';
    638 
    639         $r  = "<table class='diff'>\n";
    640 
    641     if ( ! empty( $args[ 'show_split_view' ] ) ) {
    642         $r .= "<col class='content diffsplit left' /><col class='content diffsplit middle' /><col class='content diffsplit right' />";
    643     } else {
    644         $r .= "<col class='content' />";
    645     }
    646 
    647     if ( $args['title'] || $args['title_left'] || $args['title_right'] )
    648         $r .= "<thead>";
    649     if ( $args['title'] )
    650         $r .= "<tr class='diff-title'><th colspan='4'>$args[title]</th></tr>\n";
    651     if ( $args['title_left'] || $args['title_right'] ) {
    652         $r .= "<tr class='diff-sub-title'>\n";
    653         $r .= "\t<td></td><th>$args[title_left]</th>\n";
    654         $r .= "\t<td></td><th>$args[title_right]</th>\n";
    655         $r .= "</tr>\n";
    656     }
    657     if ( $args['title'] || $args['title_left'] || $args['title_right'] )
    658         $r .= "</thead>\n";
    659 
    660     $r .= "<tbody>\n$diff\n</tbody>\n";
    661     $r .= "</table>";
    662 
    663     return array( 'html' => $r, 'lines_added' => $lines_added, 'lines_deleted' => $lines_deleted );
    664 }
Note: See TracChangeset for help on using the changeset viewer.