Make WordPress Core


Ignore:
Timestamp:
05/08/2008 05:25:07 PM (18 years ago)
Author:
ryan
Message:

Move autosave to post revisions. Props mdawaffe. see #6775

File:
1 edited

Legend:

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

    r7747 r7907  
    33require_once('admin.php');
    44
    5 $parent_file = 'edit.php';
    6 $submenu_file = 'edit.php';
    7 
    8 wp_reset_vars(array('revision', 'diff', 'restore'));
    9 
     5wp_reset_vars(array('revision', 'left', 'right', 'action'));
    106$revision_id = absint($revision);
    117$diff        = absint($diff);
     8$left        = absint($left);
     9$right       = absint($right);
    1210
    13 if ( $diff ) {
    14     $restore = false;
    15     $revision = get_post( $revision_id );
    16     $post = 'revision' == $revision->post_type ? get_post( $revision->post_parent ) : get_post( $revision_id );
    17     $left_revision = get_post( $diff );
     11
     12$parent_file = $redirect = 'edit.php';
     13$submenu_file = 'edit.php';
     14$title = __( 'Post Revision' );
     15
     16
     17switch ( $action ) :
     18case 'delete' : // stubs
     19case 'edit' :
     20    $redirect = remove_query_arg( 'action' );
     21    break;
     22case 'restore' :
     23    if ( !current_user_can( 'edit_post', $revision->post_parent ) )
     24        break;
     25    if ( !$revision = wp_get_revision( $revision_id ) )
     26        break;
     27    if ( !$post = get_post( $revision->post_parent ) )
     28        break;
     29
     30    check_admin_referer( "restore-post_$post->ID|$revision->ID" );
     31
     32    wp_restore_revision( $revision->ID );
     33    $redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) );
     34    break;
     35case 'diff' :
     36    if ( !$left_revision  = get_post( $left ) )
     37        break;
     38    if ( !$right_revision = get_post( $right ) )
     39        break;
     40
     41    if ( !current_user_can( 'edit_post', $left_revision->ID ) || !current_user_can( 'edit_post', $right_revision->ID ) )
     42        break;
    1843
    1944    // Don't allow reverse diffs?
    20     if ( strtotime($revision->post_modified_gmt) < strtotime($left_revision->post_modified_gmt) ) {
    21         wp_redirect( add_query_arg( array( 'diff' => $revision->ID, 'revision' => $diff ) ) );
    22         exit;
     45    if ( strtotime($right_revision->post_modified_gmt) < strtotime($left_revision->post_modified_gmt) ) {
     46        $redirect = add_query_arg( array( 'left' => $right, 'right' => $left ) );
     47        break;
    2348    }
    2449
    25     $h2 = __( 'Compare Revisions of &#8220;%1$s&#8221;' );
    26     $right = $revision->ID;
    27     $left  = $left_revision->ID;
     50    if ( $left_revision->ID == $right_revision->post_parent ) // right is a revision of left
     51        $post =& $left_revision;
     52    elseif ( $left_revision->post_parent == $right_revision->ID ) // left is a revision of right
     53        $post =& $right_revision;
     54    elseif ( $left_revision->post_parent == $right_revision->post_parent ) // both are revisions of common parent
     55        $post = get_post( $left_revision->post_parent );
     56    else
     57        break; // Don't diff two unrelated revisions
    2858
    2959    if (
    3060        // They're the same
    31         $left_revision->ID == $revision->ID
    32     ||
    33         // They don't have a comment parent (and we're not comparing a revision to it's post)
    34         ( $left_revision->ID != $revision->post_parent && $left_revision->post_parent != $revision->ID && $left_revision->post_parent != $revision->post_parent )
     61        $left_revision->ID == $right_revision->ID
    3562    ||
    3663        // Neither is a revision
    37         ( !wp_get_revision( $left_revision->ID ) && !wp_get_revision( $revision->ID ) )
    38     ) {
    39         wp_redirect( get_edit_post_link( $revision->ID, 'url' ) );
    40         exit();
    41     }
    42 } else {
    43     $revision = wp_get_revision( $revision_id );
    44     $post = get_post( $revision->post_parent );
    45     $h2 = __( 'Post Revision for &#8220;%1$s&#8221; created on %2$s' );
     64        ( !wp_get_revision( $left_revision->ID ) && !wp_get_revision( $right_revision->ID ) )
     65    )
     66        break;
     67   
     68    $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
     69    $h2 = sprintf( __( 'Compare Revisions of &#8220;%1$s&#8221;' ), $post_title );
     70
     71    $left  = $left_revision->ID;
     72    $right = $right_revision->ID;
     73
     74    $redirect = false;
     75    break;
     76case 'view' :
     77default :
     78    if ( !$revision = wp_get_revision( $revision_id ) )
     79        break;
     80    if ( !$post = get_post( $revision->post_parent ) )
     81        break;
     82
     83    if ( !current_user_can( 'edit_post', $revision->ID ) || !current_user_can( 'edit_post', $post->ID ) )
     84        break;
     85
     86    $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
     87    $revision_title = wp_post_revision_title( $revision, false );
     88    $h2 = sprintf( __( 'Post Revision for &#8220;%1$s&#8221; created on %2$s' ), $post_title, $revision_title );
     89
     90    // Sets up the diff radio buttons
     91    $left  = $revision->ID;
    4692    $right = $post->ID;
    47     $left  = $revision->ID;
    48 }
    4993
    50 if ( !$revision || !$post ) {
    51     wp_redirect("edit.php");
    52     exit();
    53 }
     94    $redirect = false;
     95    break;
     96endswitch;
    5497
    55 if ( $restore && current_user_can( 'edit_post', $revision->post_parent ) ) {
    56     check_admin_referer( "restore-post_$post->ID|$revision->ID" );
    57     wp_restore_revision( $revision->ID );
    58     wp_redirect( add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) ) );
     98if ( $redirect ) {
     99    wp_redirect( $redirect );
    59100    exit;
    60101}
    61102
     103// Converts post_author ID# into name
    62104add_filter( '_wp_revision_field_post_author', 'get_author_name' );
    63 
    64 $title = __( 'Post Revision' );
    65105
    66106require_once( 'admin-header.php' );
    67107
    68 $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
    69 $revision_time = wp_post_revision_time( $revision );
    70108?>
    71109
    72110<div class="wrap">
    73111
    74 <h2 style="padding-right: 0"><?php printf( $h2, $post_title, $revision_time ); ?></h2>
     112<h2 class="long-header"><?php echo $h2; ?></h2>
    75113
    76114<table class="form-table ie-fixed">
    77115    <col class="th" />
    78 <?php if ( $diff ) : ?>
    79 
     116<?php if ( 'diff' == $action ) : ?>
    80117<tr id="revision">
    81118    <th scope="row"></th>
    82     <th scope="col" class="th-full"><?php printf( __('Older: %s'), wp_post_revision_time( $left_revision ) ); ?></td>
    83     <th scope="col" class="th-full"><?php printf( __('Newer: %s'), wp_post_revision_time( $revision ) ); ?></td>
     119    <th scope="col" class="th-full">
     120        <span class="alignleft"><?php printf( __('Older: %s'), wp_post_revision_title( $left_revision ) ); ?></span>
     121        <span class="alignright"><?php printf( __('Newer: %s'), wp_post_revision_title( $right_revision ) ); ?></span>
     122    </td>
    84123</tr>
    85 
    86124<?php endif;
    87125
    88 // use get_post_to_edit ?
     126// use get_post_to_edit filters?
    89127$identical = true;
    90128foreach ( _wp_revision_fields() as $field => $field_title ) :
    91     if ( !$diff )
     129    if ( 'diff' == $action ) {
     130        $left_content = apply_filters( "_wp_revision_field_$field", $left_revision->$field, $field );
     131        $right_content = apply_filters( "_wp_revision_field_$field", $right_revision->$field, $field );
     132        if ( !$content = wp_text_diff( $left_content, $right_content ) )
     133            continue; // There is no difference between left and right
     134        $identical = false;
     135    } else {
    92136        add_filter( "_wp_revision_field_$field", 'htmlspecialchars' );
    93     $content = apply_filters( "_wp_revision_field_$field", $revision->$field, $field );
    94     if ( $diff ) {
    95         $left_content = apply_filters( "_wp_revision_field_$field", $left_revision->$field, $field );
    96         if ( !$content = wp_text_diff( $left_content, $content ) )
    97             continue;
     137        $content = apply_filters( "_wp_revision_field_$field", $revision->$field, $field );
    98138    }
    99     $identical = false;
    100139    ?>
    101140
    102     <tr id="revision-field-<?php echo $field; ?>"?>
     141    <tr id="revision-field-<?php echo $field; ?>">
    103142        <th scope="row"><?php echo wp_specialchars( $field_title ); ?></th>
    104         <td colspan="2"><pre><?php echo $content; ?></pre></td>
     143        <td><pre><?php echo $content; ?></pre></td>
    105144    </tr>
    106145
     
    109148endforeach;
    110149
    111 if ( $diff && $identical ) :
     150if ( 'diff' == $action && $identical ) :
    112151
    113152    ?>
    114153
    115     <tr><td colspan="3"><div class="updated"><p><?php _e( 'These revisions are identical' ); ?></p></div></td></tr>
     154    <tr><td colspan="2"><div class="updated"><p><?php _e( 'These revisions are identical.' ); ?></p></div></td></tr>
    116155
    117156    <?php
     
    128167
    129168<?php
    130     wp_list_post_revisions( $post, array( 'format' => 'form-table', 'exclude' => $revision->ID, 'parent' => true, 'right' => $right, 'left' => $left ) );
    131169
    132     require_once( 'admin-footer.php' );
     170wp_list_post_revisions( $post, array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left ) );
     171
     172require_once( 'admin-footer.php' );
Note: See TracChangeset for help on using the changeset viewer.