Make WordPress Core


Ignore:
Timestamp:
02/28/2013 03:14:34 PM (11 years ago)
Author:
westi
Message:

Revisions: First pass an implementing a new UI/UX for reviewing the revisions of posts. See #23497 props adamsilverstein for the initial patch.

This implements a new revisions ui using Backbone and preserves all the old methods of "integration" so the change should be transparent to plugins using revisi
ons with CPTs.

This is the first pass and so there are a number of things still to be resolved, more details in the ticket. Feedback welcomed.

File:
1 edited

Legend:

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

    r23404 r23506  
    99/** WordPress Administration Bootstrap */
    1010require_once('./admin.php');
    11 
    12 wp_enqueue_script('list-revisions');
    13 
    14 wp_reset_vars(array('revision', 'left', 'right', 'action'));
     11wp_reset_vars( array( 'revision', 'action' ) );
    1512
    1613$revision_id = absint($revision);
    17 $left        = absint($left);
    18 $right       = absint($right);
    19 
    2014$redirect = 'edit.php';
    2115
     
    3428        break;
    3529    }
    36 
    37     check_admin_referer( "restore-post_$post->ID|$revision->ID" );
     30    check_admin_referer( "restore-post_{$post->ID}|{$revision->ID}" );
    3831
    3932    wp_restore_post_revision( $revision->ID );
    4033    $redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) );
    4134    break;
    42 case 'diff' :
    43     if ( !$left_revision  = get_post( $left ) )
    44         break;
    45     if ( !$right_revision = get_post( $right ) )
    46         break;
    47 
    48     if ( !current_user_can( 'read_post', $left_revision->ID ) || !current_user_can( 'read_post', $right_revision->ID ) )
    49         break;
    50 
    51     // If we're comparing a revision to itself, redirect to the 'view' page for that revision or the edit page for that post
    52     if ( $left_revision->ID == $right_revision->ID ) {
    53         $redirect = get_edit_post_link( $left_revision->ID );
    54         include( './js/revisions-js.php' );
    55         break;
    56     }
    57 
    58     // Don't allow reverse diffs?
    59     if ( strtotime($right_revision->post_modified_gmt) < strtotime($left_revision->post_modified_gmt) ) {
    60         $redirect = add_query_arg( array( 'left' => $right, 'right' => $left ) );
    61         break;
    62     }
    63 
    64     if ( $left_revision->ID == $right_revision->post_parent ) // right is a revision of left
    65         $post =& $left_revision;
    66     elseif ( $left_revision->post_parent == $right_revision->ID ) // left is a revision of right
    67         $post =& $right_revision;
    68     elseif ( $left_revision->post_parent == $right_revision->post_parent ) // both are revisions of common parent
    69         $post = get_post( $left_revision->post_parent );
    70     else
    71         break; // Don't diff two unrelated revisions
    72 
    73     if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) { // Revisions disabled
    74         if (
    75             // we're not looking at an autosave
    76             ( !wp_is_post_autosave( $left_revision ) && !wp_is_post_autosave( $right_revision ) )
    77         ||
    78             // we're not comparing an autosave to the current post
    79             ( $post->ID !== $left_revision->ID && $post->ID !== $right_revision->ID )
    80         ) {
    81             $redirect = 'edit.php?post_type=' . $post->post_type;
    82             break;
    83         }
    84     }
    85 
    86     if (
    87         // They're the same
    88         $left_revision->ID == $right_revision->ID
    89     ||
    90         // Neither is a revision
    91         ( !wp_get_post_revision( $left_revision->ID ) && !wp_get_post_revision( $right_revision->ID ) )
    92     )
    93         break;
    94 
    95     $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
    96     $h2 = sprintf( __( 'Compare Revisions of &#8220;%1$s&#8221;' ), $post_title );
    97     $title = __( 'Revisions' );
    98 
    99     $left  = $left_revision->ID;
    100     $right = $right_revision->ID;
    101 
    102     $redirect = false;
    103     break;
    10435case 'view' :
     36case 'edit' :
    10537default :
    10638    if ( !$revision = wp_get_post_revision( $revision_id ) )
     
    12052    $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
    12153    $revision_title = wp_post_revision_title( $revision, false );
    122     $h2 = sprintf( __( 'Revision for &#8220;%1$s&#8221; created on %2$s' ), $post_title, $revision_title );
     54    $h2 = sprintf( __( 'Compare Revisions of &#8220;%1$s&#8221;' ), $post_title );
    12355    $title = __( 'Revisions' );
    124 
    125     // Sets up the diff radio buttons
    126     $left  = $revision->ID;
    127     $right = $post->ID;
    12856
    12957    $redirect = false;
     
    14674    $parent_file = $submenu_file = 'edit.php';
    14775
     76wp_enqueue_style( 'revisions' );
     77wp_enqueue_script( 'revisions' );
     78
    14879require_once( './admin-header.php' );
    14980
     81//TODO - Some of the translations below split things into multiple strings that are contextually related and this makes it pretty impossible for RTL translation.
     82//TODO can we pass the context in a better way
    15083?>
     84<script type="text/javascript">
     85var wpRevisionsSettings = <?php echo json_encode( array( 'post_id' => $post->ID, 'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ) ) ); ?>;
     86</script>
    15187
     88<div id="backbonerevisionsoptions"></div>
     89
     90<br class="clear"/>
    15291<div class="wrap">
    153 
    154 <h2 class="long-header"><?php echo $h2; ?></h2>
    155 
    156 <table class="form-table ie-fixed">
    157     <col class="th" />
    158 <?php if ( 'diff' == $action ) : ?>
    159 <tr id="revision">
    160     <th scope="row"></th>
    161     <th scope="col" class="th-full">
    162         <span class="alignleft"><?php printf( __('Older: %s'), wp_post_revision_title( $left_revision ) ); ?></span>
    163         <span class="alignright"><?php printf( __('Newer: %s'), wp_post_revision_title( $right_revision ) ); ?></span>
    164     </th>
    165 </tr>
    166 <?php endif;
    167 
    168 // use get_post_to_edit filters?
    169 $identical = true;
    170 foreach ( _wp_post_revision_fields() as $field => $field_title ) :
    171     if ( 'diff' == $action ) {
    172         $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field, $left_revision, 'left' );
    173         $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field, $right_revision, 'right' );
    174         if ( !$content = wp_text_diff( $left_content, $right_content ) )
    175             continue; // There is no difference between left and right
    176         $identical = false;
    177     } else {
    178         add_filter( "_wp_post_revision_field_$field", 'htmlspecialchars' );
    179         $content = apply_filters( "_wp_post_revision_field_$field", $revision->$field, $field, $revision, '' );
    180     }
    181     ?>
    182 
    183     <tr id="revision-field-<?php echo $field; ?>">
    184         <th scope="row"><?php echo esc_html( $field_title ); ?></th>
    185         <td><div class="pre"><?php echo $content; ?></div></td>
    186     </tr>
    187 
    188     <?php
    189 
    190 endforeach;
    191 
    192 if ( 'diff' == $action && $identical ) :
    193 
    194     ?>
    195 
    196     <tr><td colspan="2"><div class="updated"><p><?php _e( 'These revisions are identical.' ); ?></p></div></td></tr>
    197 
    198     <?php
    199 
    200 endif;
    201 
     92    <div class="icon32 icon32-posts-post" id="icon-edit"><br></div>
     93    <div class="revisiondiffcontainer diffsplit currentversion rightmodelloading">
     94        <div id="modelsloading" class="updated message"><span class="spinner" ></span> <?php _e( 'Calculating revision diffs' ); ?></div>
     95        <h2 class="long-header"><?php echo $h2; ?></h2>
     96        <div id="backbonerevisionsinteract"></div>
     97        <div id="backbonerevisionsdiff"></div>
     98<hr />
     99<?php
     100    $comparetworevisionslink = get_edit_post_link( $revision->ID );
    202101?>
    203 
    204 </table>
    205 
    206 <br class="clear" />
    207 
    208 <h3><?php echo $title; ?></h3>
    209 
    210 <?php
    211 
    212 $args = array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left );
    213 if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') )
    214     $args['type'] = 'autosave';
    215 
    216 wp_list_post_revisions( $post, $args );
    217 
    218 ?>
    219 
     102    </div>
    220103</div>
    221104
     105<script id="tmpl-revision" type="text/html">
     106    <div id="diffsubheader">
     107        <span id="diff_from_current_revision"><?php _e( 'Current version' ); ?><?php _e( '- compared to -' ); ?></span>
     108        <div id="difftitlefrom">{{{ data.revision_from_date_author }}} <?php _e( '- compared to -' ); ?></div>
     109        <div id="difftitle">{{{ data.revision_date_author }}}</div>
     110        <div id="diffcancel"><input class="button" onClick="document.location='<?php echo get_edit_post_link( $post->ID ); ?>'" type="submit" id="cancel" value="<?php esc_attr_e( 'Cancel' )?>" /></div>
     111        <div id="diffrestore"><input class="button button-primary" onClick="document.location='{{{ data.restoreaction }}}'" type="submit" id="restore" value="<?php esc_attr_e( 'Restore' )?>" /></div>
     112        <div id="comparetworevisions"><input type="checkbox" id="comparetwo" value="comparetwo" {{{ data.comparetwochecked }}} name="comparetwo"/> <?php esc_attr_e( 'Compare two revisions' )?></div>
     113    </div>
     114    <div id="removedandadded">
     115        <div id="removed"><?php _e( 'Removed -' ); ?></div>
     116        <div id="added"><?php _e( 'Added +' ); ?></div>
     117    </div
     118    <div>{{{ data.revisiondiff }}}</div>
     119</script>
     120
     121<script id="tmpl-revisionvinteract" type="text/html">
     122    <div id="diffheader">
     123<div id="diffprevious"><input class="button" type="submit" id="previous" value="Previous" /></div>
     124            <div id="diffnext"><input class="button" type="submit" id="next" value="Next" /></div>
     125            <div id="diffslider">
     126    <div id="revisioncount">
     127                    <?php _e( 'Comparing' ); ?>
     128                    <span id="diff_left_count"> <?php _e( 'revision' ); ?></span> <span id="diff_left_count_inner"></span>
     129                    <span id="diff_left_current_revision"><?php _e( 'current version' ); ?></span>
     130                    <span id="diff_revision_from">{{{ data.diff_revision_from }}}</span>
     131                    <?php _e( ' to revision' ); ?>
     132                    <span id="diff_count">{{{ data.current_diff }}}</span>
     133                    <?php _e( ' of ' ); ?>
     134                    <span id="diff_max" ></span>
     135                </div>
     136
     137            <div id="slider"></div>
     138        </div>
     139    </div>
     140</script>
    222141<?php
     142/*
     143TODO Convert these into screen options
     144<script id="tmpl-revisionoptions" type="text/html">
     145    <div id="revisionoptions">
     146        <div id="showsplitviewoption">
     147            <input type='checkbox' id="show_split_view" checked="checked" value="1" /> <?php _e( 'Show split diff view' ); ?>
     148        </div>
     149        <div id="toggleshowautosavesoption">
     150            <input type='checkbox' id="toggleshowautosaves" value="1" /> <?php _e( 'Show autosaves' ); ?>
     151        </div>
     152    </div>
     153</script>
     154*/
    223155require_once( './admin-footer.php' );
Note: See TracChangeset for help on using the changeset viewer.