WordPress.org

Make WordPress Core

Changeset 8011


Ignore:
Timestamp:
05/29/2008 10:21:36 PM (11 years ago)
Author:
ryan
Message:

Post revisions API cleanup from mdawaffe. see #6775

Location:
trunk
Files:
8 edited

Legend:

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

    r7971 r8011  
    520520                $id = edit_post();
    521521            } else { // Non drafts are not overwritten.  The autosave is stored in a special post revision.
    522                 $revision_id = wp_create_autosave( $post->ID );
     522                $revision_id = wp_create_post_autosave( $post->ID );
    523523                if ( is_wp_error($revision_id) )
    524524                    $id = $revision_id;
  • trunk/wp-admin/edit-form-advanced.php

    r7967 r8011  
    2222    $form_action = 'editpost';
    2323    $form_extra = "<input type='hidden' id='post_ID' name='post_ID' value='$post_ID' />";
    24     $autosave = wp_get_autosave( $post_id );
     24    $autosave = wp_get_post_autosave( $post_id );
    2525    if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt ) > mysql2date( 'U', $post->post_modified_gmt ) )
    2626        $notice = sprintf( $notices[1], get_edit_post_link( $autosave->ID ) );
  • trunk/wp-admin/edit-page-form.php

    r7948 r8011  
    2020    $nonce_action = 'update-page_' . $post_ID;
    2121    $form_extra = "<input type='hidden' id='post_ID' name='post_ID' value='$post_ID' />";
    22     $autosave = wp_get_autosave( $post_id );
     22    $autosave = wp_get_post_autosave( $post_id );
    2323    if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt ) > mysql2date( 'U', $post->post_modified_gmt ) )
    2424        $notice = sprintf( $notices[1], get_edit_post_link( $autosave->ID ) );
  • trunk/wp-admin/includes/post.php

    r7980 r8011  
    650650
    651651/**
    652  * wp_create_autosave() - creates autosave data for the specified post from $_POST data
     652 * wp_create_post_autosave() - creates autosave data for the specified post from $_POST data
    653653 *
    654654 * @package WordPress
     
    657657 *
    658658 * @uses _wp_translate_postdata()
    659  * @uses _wp_revision_fields()
     659 * @uses _wp_post_revision_fields()
    660660 */
    661 function wp_create_autosave( $post_id ) {
     661function wp_create_post_autosave( $post_id ) {
    662662    $translated = _wp_translate_postdata( true );
    663663    if ( is_wp_error( $translated ) )
     
    665665
    666666    // Only store one autosave.  If there is already an autosave, overwrite it.
    667     if ( $old_autosave = wp_get_autosave( $post_id ) ) {
    668         $new_autosave = _wp_revision_fields( $_POST, true );
     667    if ( $old_autosave = wp_get_post_autosave( $post_id ) ) {
     668        $new_autosave = _wp_post_revision_fields( $_POST, true );
    669669        $new_autosave['ID'] = $old_autosave->ID;
    670670        return wp_update_post( $new_autosave );
     
    672672
    673673    // Otherwise create the new autosave as a special post revision
    674     return _wp_put_revision( $_POST, true );
    675 }
     674    return _wp_put_post_revision( $_POST, true );
     675}
  • trunk/wp-admin/revision.php

    r7913 r8011  
    22
    33require_once('admin.php');
    4 
    5 if ( !constant('WP_POST_REVISIONS') ) {
    6     wp_redirect( 'edit.php' );
    7     exit;
    8 }
    94
    105wp_reset_vars(array('revision', 'left', 'right', 'action'));
     
    1914case 'delete' : // stubs
    2015case 'edit' :
    21     $redirect = remove_query_arg( 'action' );
     16    if ( constant('WP_POST_REVISIONS') ) // stub
     17        $redirect = remove_query_arg( 'action' );
     18    else // Revisions disabled
     19        $redirect = 'edit.php';
    2220    break;
    2321case 'restore' :
     22    if ( !$revision = wp_get_post_revision( $revision_id ) )
     23        break;
    2424    if ( !current_user_can( 'edit_post', $revision->post_parent ) )
    2525        break;
    26     if ( !$revision = wp_get_revision( $revision_id ) )
    27         break;
    2826    if ( !$post = get_post( $revision->post_parent ) )
    2927        break;
    3028
     29    if ( !constant('WP_POST_REVISIONS') && !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave
     30        break;
     31
    3132    check_admin_referer( "restore-post_$post->ID|$revision->ID" );
    3233
    33     wp_restore_revision( $revision->ID );
     34    wp_restore_post_revision( $revision->ID );
    3435    $redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) );
    3536    break;
     
    5859        break; // Don't diff two unrelated revisions
    5960
     61    if ( !constant('WP_POST_REVISIONS') ) { // Revisions disabled
     62        if (
     63            // we're not looking at an autosave
     64            ( !wp_is_post_autosave( $left_revision ) && !wp_is_post_autosave( $right_revision ) )
     65        ||
     66            // we're not comparing an autosave to the current post
     67            ( $post->ID !== $left_revision->ID && $post->ID !== $right_revision->ID )
     68        )
     69            break;
     70    }
     71
    6072    if (
    6173        // They're the same
     
    6375    ||
    6476        // Neither is a revision
    65         ( !wp_get_revision( $left_revision->ID ) && !wp_get_revision( $right_revision->ID ) )
     77        ( !wp_get_post_revision( $left_revision->ID ) && !wp_get_post_revision( $right_revision->ID ) )
    6678    )
    6779        break;
     
    7789case 'view' :
    7890default :
    79     if ( !$revision = wp_get_revision( $revision_id ) )
     91    if ( !$revision = wp_get_post_revision( $revision_id ) )
    8092        break;
    8193    if ( !$post = get_post( $revision->post_parent ) )
     
    8395
    8496    if ( !current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) )
     97        break;
     98
     99    if ( !constant('WP_POST_REVISIONS') && !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave
    85100        break;
    86101
     
    114129
    115130// Converts post_author ID# into name
    116 add_filter( '_wp_revision_field_post_author', 'get_author_name' );
     131add_filter( '_wp_post_revision_field_post_author', 'get_author_name' );
    117132
    118133require_once( 'admin-header.php' );
     
    138153// use get_post_to_edit filters?
    139154$identical = true;
    140 foreach ( _wp_revision_fields() as $field => $field_title ) :
     155foreach ( _wp_post_revision_fields() as $field => $field_title ) :
    141156    if ( 'diff' == $action ) {
    142         $left_content = apply_filters( "_wp_revision_field_$field", $left_revision->$field, $field );
    143         $right_content = apply_filters( "_wp_revision_field_$field", $right_revision->$field, $field );
     157        $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field );
     158        $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field );
    144159        if ( !$content = wp_text_diff( $left_content, $right_content ) )
    145160            continue; // There is no difference between left and right
    146161        $identical = false;
    147162    } else {
    148         add_filter( "_wp_revision_field_$field", 'htmlspecialchars' );
    149         $content = apply_filters( "_wp_revision_field_$field", $revision->$field, $field );
     163        add_filter( "_wp_post_revision_field_$field", 'htmlspecialchars' );
     164        $content = apply_filters( "_wp_post_revision_field_$field", $revision->$field, $field );
    150165    }
    151166    ?>
     
    180195<?php
    181196
    182 wp_list_post_revisions( $post, array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left ) );
     197$args = array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left );
     198if ( !constant( 'WP_POST_REVISIONS' ) )
     199    $args['type'] = 'autosave';
     200
     201wp_list_post_revisions( $post, $args );
    183202
    184203require_once( 'admin-footer.php' );
  • trunk/wp-includes/default-filters.php

    r7970 r8011  
    180180add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 );
    181181add_action( 'shutdown', 'wp_ob_end_flush_all', 1);
    182 add_action( 'pre_post_update', 'wp_save_revision' );
     182add_action( 'pre_post_update', 'wp_save_post_revision' );
    183183add_action('publish_post', '_publish_post_hook', 5, 1);
    184184add_action('future_post', '_future_post_hook', 5, 2);
  • trunk/wp-includes/post-template.php

    r7913 r8011  
    594594        $date = "<a href='$link'>$date</a>";
    595595
    596     if ( 'revision' != $revision->post_type )
     596    if ( !wp_is_post_revision( $revision ) )
    597597        $date = sprintf( $currentf, $date );
    598     elseif ( "{$revision->post_parent}-autosave" == $revision->post_name )
     598    elseif ( wp_is_post_autosave( $revision ) )
    599599        $date = sprintf( $autosavef, $date );
    600600
     
    629629        return;
    630630
    631     if ( !$revisions = wp_get_post_revisions( $post->ID ) )
    632         return;
    633 
    634     $defaults = array( 'parent' => false, 'right' => false, 'left' => false, 'format' => 'list' );
     631    $defaults = array( 'parent' => false, 'right' => false, 'left' => false, 'format' => 'list', 'type' => 'all' );
    635632    extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );
     633
     634    switch ( $type ) {
     635    case 'autosave' :
     636        if ( !$autosave = wp_get_post_autosave( $post->ID ) )
     637            return;
     638        $revisions = array( $autosave );
     639        break;
     640    case 'revision' : // just revisions - remove autosave later
     641    case 'all' :
     642    default :
     643        if ( !$revisions = wp_get_post_revisions( $post->ID ) )
     644            return;
     645        break;
     646    }
    636647
    637648    $titlef = _c( '%1$s by %2$s|post revision 1:datetime, 2:name' );
     
    645656    foreach ( $revisions as $revision ) {
    646657        if ( !current_user_can( 'read_post', $revision->ID ) )
     658            continue;
     659        if ( 'revision' === $type && wp_is_post_autosave( $revision ) )
    647660            continue;
    648661
  • trunk/wp-includes/post.php

    r7995 r8011  
    957957    // Do raw query.  wp_get_post_revisions() is filtered
    958958    $revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid ) );
    959     // Use wp_delete_post (via wp_delete_revision) again.  Ensures any meta/misplaced data gets cleaned up.
     959    // Use wp_delete_post (via wp_delete_post_revision) again.  Ensures any meta/misplaced data gets cleaned up.
    960960    foreach ( $revision_ids as $revision_id )
    961         wp_delete_revision( $revision_id );
     961        wp_delete_post_revision( $revision_id );
    962962
    963963    // Point all attachments to this post up one level
     
    29522952
    29532953/**
    2954  * _wp_revision_fields() - determines which fields of posts are to be saved in revisions
     2954 * _wp_post_revision_fields() - determines which fields of posts are to be saved in revisions
    29552955 *
    29562956 * Does two things. If passed a post *array*, it will return a post array ready to be
     
    29662966 * @return array post array ready to be inserted as a post revision or array of fields that can be versioned
    29672967 */
    2968 function _wp_revision_fields( $post = null, $autosave = false ) {
     2968function _wp_post_revision_fields( $post = null, $autosave = false ) {
    29692969    static $fields = false;
    29702970
     
    29792979
    29802980        // Runs only once
    2981         $fields = apply_filters( '_wp_revision_fields', $fields );
     2981        $fields = apply_filters( '_wp_post_revision_fields', $fields );
    29822982
    29832983        // WP uses these internally either in versioning or elsewhere - they cannot be versioned
     
    30043004
    30053005/**
    3006  * wp_save_revision() - Saves an already existing post as a post revision.  Typically used immediately prior to post updates.
     3006 * wp_save_post_revision() - Saves an already existing post as a post revision.  Typically used immediately prior to post updates.
    30073007 *
    30083008 * @package WordPress
     
    30103010 * @since 2.6
    30113011 *
    3012  * @uses _wp_put_revision()
     3012 * @uses _wp_put_post_revision()
    30133013 *
    30143014 * @param int $post_id The ID of the post to save as a revision
    30153015 * @return mixed null or 0 if error, new revision ID if success
    30163016 */
    3017 function wp_save_revision( $post_id ) {
    3018     // We do autosaves manually with wp_create_autosave()
     3017function wp_save_post_revision( $post_id ) {
     3018    // We do autosaves manually with wp_create_post_autosave()
    30193019    if ( @constant( 'DOING_AUTOSAVE' ) )
    30203020        return;
     
    30303030        return;
    30313031
    3032     $return = _wp_put_revision( $post );
     3032    $return = _wp_put_post_revision( $post );
    30333033
    30343034    // WP_POST_REVISIONS = true (default), -1
     
    30503050        if ( false !== strpos( $revisions[$i]->post_name, 'autosave' ) )
    30513051            continue;
    3052         wp_delete_revision( $revisions[$i]->ID );
     3052        wp_delete_post_revision( $revisions[$i]->ID );
    30533053    }
    30543054
     
    30573057
    30583058/**
    3059  * wp_get_autosave() - returns the autosaved data of the specified post.
     3059 * wp_get_post_autosave() - returns the autosaved data of the specified post.
    30603060 *
    30613061 * Returns a post object containing the information that was autosaved for the specified post.
     
    30683068 * @return object|bool the autosaved data or false on failure or when no autosave exists
    30693069 */
    3070 function wp_get_autosave( $post_id ) {
     3070function wp_get_post_autosave( $post_id ) {
    30713071    global $wpdb;
    30723072    if ( !$post = get_post( $post_id ) )
     
    30833083    $autosave_query = new WP_Query;
    30843084
    3085     add_action( 'parse_query', '_wp_get_autosave_hack' );
     3085    add_action( 'parse_query', '_wp_get_post_autosave_hack' );
    30863086    $autosave = $autosave_query->query( $q );
    3087     remove_action( 'parse_query', '_wp_get_autosave_hack' );
     3087    remove_action( 'parse_query', '_wp_get_post_autosave_hack' );
    30883088
    30893089    if ( $autosave && is_array($autosave) && is_object($autosave[0]) )
     
    30943094
    30953095// Internally used to hack WP_Query into submission
    3096 function _wp_get_autosave_hack( $query ) {
     3096function _wp_get_post_autosave_hack( $query ) {
    30973097    $query->is_single = false;
    30983098}
    30993099
    3100 /**
    3101  * _wp_put_revision() - Inserts post data into the posts table as a post revision
     3100
     3101/**
     3102 * wp_is_post_revision() - Determines if the specified post is a revision.
     3103 *
     3104 * @package WordPress
     3105 * @subpackage Post Revisions
     3106 * @since 2.6
     3107 *
     3108 * @param int|object $post post ID or post object
     3109 * @return bool|int false if not a revision, ID of revision's parent otherwise
     3110 */
     3111function wp_is_post_revision( $post ) {
     3112    if ( !$post = wp_get_post_revision( $post ) )
     3113        return false;
     3114    return (int) $post->post_parent;
     3115}
     3116
     3117/**
     3118 * wp_is_post_autosave() - Determines if the specified post is an autosave.
     3119 *
     3120 * @package WordPress
     3121 * @subpackage Post Revisions
     3122 * @since 2.6
     3123 *
     3124 * @param int|object $post post ID or post object
     3125 * @return bool|int false if not a revision, ID of autosave's parent otherwise
     3126 */
     3127function wp_is_post_autosave( $post ) {
     3128    if ( !$post = wp_get_post_revision( $post ) )
     3129        return false;
     3130    if ( "{$post->post_parent}-autosave" !== $post->post_name )
     3131        return false;
     3132    return (int) $post->post_parent;
     3133}
     3134
     3135/**
     3136 * _wp_put_post_revision() - Inserts post data into the posts table as a post revision
    31023137 *
    31033138 * @package WordPress
     
    31113146 * @return mixed null or 0 if error, new revision ID if success
    31123147 */
    3113 function _wp_put_revision( $post = null, $autosave = false ) {
     3148function _wp_put_post_revision( $post = null, $autosave = false ) {
    31143149    if ( is_object($post) )
    31153150        $post = get_object_vars( $post );
     
    31223157        return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) );
    31233158
    3124     $post = _wp_revision_fields( $post, $autosave );
     3159    $post = _wp_post_revision_fields( $post, $autosave );
    31253160
    31263161    $revision_id = wp_insert_post( $post );
     
    31293164
    31303165    if ( $revision_id )
    3131         do_action( '_wp_put_revision', $revision_id );
     3166        do_action( '_wp_put_post_revision', $revision_id );
    31323167    return $revision_id;
    31333168}
    31343169
    31353170/**
    3136  * wp_get_revision() - Gets a post revision
     3171 * wp_get_post_revision() - Gets a post revision
    31373172 *
    31383173 * @package WordPress
     
    31473182 * @return mixed null if error or post object if success
    31483183 */
    3149 function &wp_get_revision(&$post, $output = OBJECT, $filter = 'raw') {
     3184function &wp_get_post_revision(&$post, $output = OBJECT, $filter = 'raw') {
    31503185    $null = null;
    31513186    if ( !$revision = get_post( $post, OBJECT, $filter ) )
     
    31683203
    31693204/**
    3170  * wp_restore_revision() - Restores a post to the specified revision
     3205 * wp_restore_post_revision() - Restores a post to the specified revision
    31713206 *
    31723207 * Can restore a past using all fields of the post revision, or only selected fields.
     
    31763211 * @since 2.6
    31773212 *
    3178  * @uses wp_get_revision()
     3213 * @uses wp_get_post_revision()
    31793214 * @uses wp_update_post()
    31803215 *
     
    31833218 * @return mixed null if error, false if no fields to restore, (int) post ID if success
    31843219 */
    3185 function wp_restore_revision( $revision_id, $fields = null ) {
    3186     if ( !$revision = wp_get_revision( $revision_id, ARRAY_A ) )
     3220function wp_restore_post_revision( $revision_id, $fields = null ) {
     3221    if ( !$revision = wp_get_post_revision( $revision_id, ARRAY_A ) )
    31873222        return $revision;
    31883223
    31893224    if ( !is_array( $fields ) )
    3190         $fields = array_keys( _wp_revision_fields() );
     3225        $fields = array_keys( _wp_post_revision_fields() );
    31913226
    31923227    $update = array();
     
    32043239
    32053240    if ( $post_id )
    3206         do_action( 'wp_restore_revision', $post_id, $revision['ID'] );
     3241        do_action( 'wp_restore_post_revision', $post_id, $revision['ID'] );
    32073242
    32083243    return $post_id;
     
    32103245
    32113246/**
    3212  * wp_delete_revision() - Deletes a revision.
     3247 * wp_delete_post_revision() - Deletes a revision.
    32133248 *
    32143249 * Deletes the row from the posts table corresponding to the specified revision
     
    32183253 * @since 2.6
    32193254 *
    3220  * @uses wp_get_revision()
     3255 * @uses wp_get_post_revision()
    32213256 * @uses wp_delete_post()
    32223257 *
     
    32253260 * @return mixed null if error, false if no fields to restore, (int) post ID if success
    32263261 */
    3227 function wp_delete_revision( $revision_id ) {
    3228     if ( !$revision = wp_get_revision( $revision_id ) )
     3262function wp_delete_post_revision( $revision_id ) {
     3263    if ( !$revision = wp_get_post_revision( $revision_id ) )
    32293264        return $revision;
    32303265
     
    32343269
    32353270    if ( $delete )
    3236         do_action( 'wp_delete_revision', $revision->ID, $revision );
     3271        do_action( 'wp_delete_post_revision', $revision->ID, $revision );
    32373272
    32383273    return $delete;
Note: See TracChangeset for help on using the changeset viewer.