Make WordPress Core


Ignore:
Timestamp:
03/07/2013 03:32:26 PM (12 years ago)
Author:
westi
Message:

Revisions: Updates to the new Revisions UI.

Various Updates including:

  • i18n fixes
  • Added tracking of what revision ID was restored
  • async fetching of diffs so that slider works sooner even with many revisions

See #23497 props adamsilverstein, ethitter

File:
1 edited

Legend:

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

    r23581 r23639  
    1111wp_reset_vars( array( 'revision', 'action' ) );
    1212
    13 $revision_id = absint($revision);
     13$revision_id = absint( $revision );
    1414$redirect = 'edit.php';
    1515
    1616switch ( $action ) :
    1717case 'restore' :
    18     if ( !$revision = wp_get_post_revision( $revision_id ) )
     18    if ( ! $revision = wp_get_post_revision( $revision_id ) )
    1919        break;
    20     if ( !current_user_can( 'edit_post', $revision->post_parent ) )
     20    if ( ! current_user_can( 'edit_post', $revision->post_parent ) )
    2121        break;
    22     if ( !$post = get_post( $revision->post_parent ) )
     22    if ( ! $post = get_post( $revision->post_parent ) )
    2323        break;
    2424
    2525    // Revisions disabled and we're not looking at an autosave
    26     if ( ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) {
     26    if ( ( ! WP_POST_REVISIONS || ! post_type_supports( $post->post_type, 'revisions' ) ) && ! wp_is_post_autosave( $revision ) ) {
    2727        $redirect = 'edit.php?post_type=' . $post->post_type;
    2828        break;
    2929    }
    3030    check_admin_referer( "restore-post_{$post->ID}|{$revision->ID}" );
     31
     32    //store revision event in post meta
     33    $restore_details = array(
     34        'restored_revision_id' => $revision->ID,
     35        'restored_by_user' => get_current_user_id(),
     36        'restored_time' => time()
     37    );
     38    update_post_meta( $post->ID, '_post_restored_from', $restore_details );
    3139
    3240    wp_restore_post_revision( $revision->ID );
     
    3644case 'edit' :
    3745default :
    38     if ( !$revision = wp_get_post_revision( $revision_id ) )
     46    if ( ! $revision = wp_get_post_revision( $revision_id ) )
    3947        break;
    40     if ( !$post = get_post( $revision->post_parent ) )
     48    if ( ! $post = get_post( $revision->post_parent ) )
    4149        break;
    4250
    43     if ( !current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) )
     51    if ( ! current_user_can( 'read_post', $revision->ID ) || ! current_user_can( 'read_post', $post->ID ) )
    4452        break;
    4553
     
    6068
    6169// Empty post_type means either malformed object found, or no valid parent was found.
    62 if ( !$redirect && empty($post->post_type) )
     70if ( ! $redirect && empty( $post->post_type ) )
    6371    $redirect = 'edit.php';
    6472
    65 if ( !empty($redirect) ) {
     73if ( ! empty( $redirect ) ) {
    6674    wp_redirect( $redirect );
    6775    exit;
     
    6977
    7078// This is so that the correct "Edit" menu item is selected.
    71 if ( !empty($post->post_type) && 'post' != $post->post_type )
     79if ( ! empty( $post->post_type ) && 'post' != $post->post_type )
    7280    $parent_file = $submenu_file = 'edit.php?post_type=' . $post->post_type;
    7381else
     
    8492var wpRevisionsSettings = <?php echo json_encode( array( 'post_id' => $post->ID, 'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ) ) ); ?>;
    8593</script>
     94<?php
     95    $comparetworevisionslink = get_edit_post_link( $revision->ID );
     96?>
    8697
    8798<div id="backbonerevisionsoptions"></div>
    88 
    89 <br class="clear"/>
    9099<div class="wrap">
    91100    <div class="icon32 icon32-posts-post" id="icon-edit"><br></div>
     
    95104        <div id="backbonerevisionsinteract"></div>
    96105        <div id="backbonerevisionsdiff"></div>
    97 <hr />
    98 <?php
    99     $comparetworevisionslink = get_edit_post_link( $revision->ID );
    100 ?>
     106        <hr />
    101107    </div>
    102108</div>
     
    108114        <div id="difftitle">{{{ data.revision_date_author }}}</div>
    109115        <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>
    110         <div id="diffrestore"><input class="button button-primary" onClick="document.location='{{{ data.restoreaction }}}'" type="submit" id="restore" value="<?php esc_attr_e( 'Restore' )?>" /></div>
    111         <div id="comparetworevisions"><input type="checkbox" id="comparetwo" value="comparetwo" {{{ data.comparetwochecked }}} name="comparetwo"/> <?php esc_attr_e( 'Compare two revisions' )?></div>
    112     </div>
     116        <div id="diffrestore"><input class="button button-primary" onClick="document.location='{{{ data.restoreaction }}}'" type="submit" id="restore" value="<?php esc_attr_e( 'Restore revision ID' )?>" /></div>
     117        <div id="comparetworevisions"><input type="checkbox" id="comparetwo" value="comparetwo" {{{ data.comparetwochecked }}} name="comparetwo"/> <label for="comparetwo"><?php esc_attr_e( 'Compare two revisions' ); ?></a></div>    </div>
    113118    <div id="removedandadded">
    114119        <div id="removed"><?php _e( 'Removed -' ); ?></div>
     
    120125<script id="tmpl-revisionvinteract" type="text/html">
    121126    <div id="diffheader">
    122 <div id="diffprevious"><input class="button" type="submit" id="previous" value="Previous" /></div>
    123             <div id="diffnext"><input class="button" type="submit" id="next" value="Next" /></div>
     127<div id="diffprevious"><input class="button" type="submit" id="previous" value="<?php esc_attr_e( 'Previous' ); ?>" /></div>
     128            <div id="diffnext"><input class="button" type="submit" id="next" value="<?php esc_attr_e( 'Next' ); ?>" /></div>
    124129            <div id="diffslider">
    125130    <div id="revisioncount">
Note: See TracChangeset for help on using the changeset viewer.