WordPress.org

Make WordPress Core

Ticket #6775: 6775.7.diff

File 6775.7.diff, 20.1 KB (added by mdawaffe, 11 years ago)
  • wp-includes/default-filters.php

     
    179179add_action('init', 'smilies_init', 5);
    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);
    185185add_action('future_page', '_future_post_hook', 5, 2);
  • wp-includes/post-template.php

     
    593593        if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
    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
    601601        return $date;
     
    628628        if ( !$post = get_post( $post_id ) )
    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 );
    636633
     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        }
     647
    637648        $titlef = _c( '%1$s by %2$s|post revision 1:datetime, 2:name' );
    638649
    639650        if ( $parent )
     
    645656        foreach ( $revisions as $revision ) {
    646657                if ( !current_user_can( 'read_post', $revision->ID ) )
    647658                        continue;
     659                if ( 'revision' === $type && wp_is_post_autosave( $revision ) )
     660                        continue;
    648661
    649662                $date = wp_post_revision_title( $revision );
    650663                $name = get_author_name( $revision->post_author );
  • wp-includes/post.php

     
    956956
    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
    964964        $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) );
     
    29512951/* Post Revisions */
    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
    29572957 * insterted into the posts table as a post revision.
     
    29652965 * @param bool $autosave optional Is the revision an autosave?
    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
    29712971        if ( !$fields ) {
     
    29782978                );
    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
    29842984                foreach ( array( 'ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count' ) as $protect )
     
    30033003}
    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
    30093009 * @subpackage Post Revisions
    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;
    30213021
     
    30293029        if ( !in_array( $post['post_type'], array( 'post', 'page' ) ) )
    30303030                return;
    30313031
    3032         $return = _wp_put_revision( $post );
     3032        $return = _wp_put_post_revision( $post );
    30333033
    30343034        // WP_POST_REVISIONS = true (default), -1
    30353035        if ( !is_numeric( WP_POST_REVISIONS ) || WP_POST_REVISIONS < 0 )
     
    30493049        for ( $i = 0; isset($revisions[$i]); $i++ ) {
    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
    30553055        return $return;
    30563056}
    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.
    30623062 *
     
    30673067 * @param int $post_id The post ID
    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 ) )
    30733073                return false;
     
    30823082        // Use WP_Query so that the result gets cached
    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]) )
    30903090                return $autosave[0];
     
    30933093}
    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
    31003101/**
    3101  * _wp_put_revision() - Inserts post data into the posts table as a post revision
     3102 * wp_is_post_revision() - Determines if the specified post is a revision.
    31023103 *
    31033104 * @package WordPress
    31043105 * @subpackage Post Revisions
    31053106 * @since 2.6
    31063107 *
     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
     3137 *
     3138 * @package WordPress
     3139 * @subpackage Post Revisions
     3140 * @since 2.6
     3141 *
    31073142 * @uses wp_insert_post()
    31083143 *
    31093144 * @param int|object|array $post post ID, post object OR post array
    31103145 * @param bool $autosave optional Is the revision an autosave?
    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 );
    31163151        elseif ( !is_array($post) )
     
    31213156        if ( isset($post['post_type']) && 'revision' == $post_post['type'] )
    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 );
    31273162        if ( is_wp_error($revision_id) )
    31283163                return $revision_id;
    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
    31393174 * @subpackage Post Revisions
     
    31463181 * @param string $filter optional sanitation filter.  @see sanitize_post()
    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 ) )
    31523187                return $revision;
     
    31673202}
    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.
    31733208 *
     
    31753210 * @subpackage Post Revisions
    31763211 * @since 2.6
    31773212 *
    3178  * @uses wp_get_revision()
     3213 * @uses wp_get_post_revision()
    31793214 * @uses wp_update_post()
    31803215 *
    31813216 * @param int|object $revision_id revision ID or revision object
    31823217 * @param array $fields optional What fields to restore from.  Defaults to all.
    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();
    31933228        foreach( array_intersect( array_keys( $revision ), $fields ) as $field )
     
    32033238                return $post_id;
    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;
    32093244}
    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
    32153250 *
     
    32173252 * @subpackage Post Revisions
    32183253 * @since 2.6
    32193254 *
    3220  * @uses wp_get_revision()
     3255 * @uses wp_get_post_revision()
    32213256 * @uses wp_delete_post()
    32223257 *
    32233258 * @param int|object $revision_id revision ID or revision object
    32243259 * @param array $fields optional What fields to restore from.  Defaults to all.
    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
    32313266        $delete = wp_delete_post( $revision->ID );
     
    32333268                return $delete;
    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;
    32393274}
  • wp-admin/admin-ajax.php

     
    519519                        if ( 'draft' == $post->post_status ) {
    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;
    525525                                else
  • wp-admin/includes/post.php

     
    649649}
    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
    655655 * @subpackage Post Revisions
    656656 * @since 2.6
    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 ) )
    664664                return $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 );
    671671        }
    672672
    673673        // Otherwise create the new autosave as a special post revision
    674         return _wp_put_revision( $_POST, true );
     674        return _wp_put_post_revision( $_POST, true );
    675675}
  • wp-admin/revision.php

     
    22
    33require_once('admin.php');
    44
    5 if ( !constant('WP_POST_REVISIONS') ) {
    6         wp_redirect( 'edit.php' );
    7         exit;
    8 }
    9 
    105wp_reset_vars(array('revision', 'left', 'right', 'action'));
    116$revision_id = absint($revision);
    127$diff        = absint($diff);
     
    1813switch ( $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;
    3637case 'diff' :
     
    5758        else
    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
    6274                $left_revision->ID == $right_revision->ID
    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;
    6880       
     
    7688        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 ) )
    8294                break;
     
    8496        if ( !current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) )
    8597                break;
    8698
     99        if ( !constant('WP_POST_REVISIONS') && !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave
     100                break;
     101
    87102        $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>';
    88103        $revision_title = wp_post_revision_title( $revision, false );
    89104        $h2 = sprintf( __( 'Post Revision for &#8220;%1$s&#8221; created on %2$s' ), $post_title, $revision_title );
     
    113128}
    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' );
    119134
     
    137152
    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        ?>
    152167
     
    179194
    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';
    183200
     201wp_list_post_revisions( $post, $args );
     202
    184203require_once( 'admin-footer.php' );
  • wp-admin/edit-page-form.php

     
    1919        $form_action = 'editpost';
    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 ) );
    2525}
  • wp-admin/edit-form-advanced.php

     
    2121        $post_ID = (int) $post_ID;
    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 ) );
    2727}