Make WordPress Core

Ticket #21397: 21397.5.diff

File 21397.5.diff, 5.4 KB (added by JustinSainton, 12 years ago)
  • wp-admin/includes/post.php

     
    12381238 *
    12391239 * @return unknown
    12401240 */
    1241 function wp_create_post_autosave( $post_id ) {
    1242         $translated = _wp_translate_postdata( true );
    1243         if ( is_wp_error( $translated ) )
    1244                 return $translated;
     1241function wp_create_post_autosave( $post_id, $post_data = null ) {
     1242        if ( empty($post_data) ) {
     1243                $post_data = _wp_translate_postdata( true, $_POST );
     1244                if ( is_wp_error( $post_data ) )
     1245                        return $post_data;
     1246        }
    12451247
    12461248        // Only store one autosave. If there is already an autosave, overwrite it.
    12471249        if ( $old_autosave = wp_get_post_autosave( $post_id ) ) {
    1248                 $new_autosave = _wp_post_revision_fields( $_POST, true );
     1250                $new_autosave = _wp_post_revision_fields( $post_data, true );
    12491251                $new_autosave['ID'] = $old_autosave->ID;
    12501252                $new_autosave['post_author'] = get_current_user_id();
    12511253                return wp_update_post( $new_autosave );
    12521254        }
    12531255
    12541256        // _wp_put_post_revision() expects unescaped.
    1255         $_POST = stripslashes_deep($_POST);
     1257        $post_data = stripslashes_deep($post_data);
    12561258
    12571259        // Otherwise create the new autosave as a special post revision
    1258         return _wp_put_post_revision( $_POST, true );
     1260        return _wp_put_post_revision( $post_data, true );
    12591261}
    12601262
    12611263/**
  • wp-includes/class-wp-xmlrpc-server.php

     
    8282                        'wp.getPostFormats'     => 'this:wp_getPostFormats',
    8383                        'wp.getPostType'                => 'this:wp_getPostType',
    8484                        'wp.getPostTypes'               => 'this:wp_getPostTypes',
     85                        'wp.getRevisions'               => 'this:wp_getRevisions',
     86                        'wp.restoreRevision'    => 'this:wp_restoreRevision',
    8587
    8688                        // Blogger API
    8789                        'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
     
    12551257
    12561258                $post = get_post( $post_id, ARRAY_A );
    12571259
     1260    if ( isset( $content_struct['only_if_no_new_revision'] ) ) {
     1261      // if there's a newer revision, return an error
     1262      if ( mysql2date( 'U', $post['post_modified_gmt'] ) > $content_struct['only_if_no_new_revision']->getTimestamp() ) {
     1263        return new IXR_Error( 409, __( 'There is a revision of this post that is more recent' ) );
     1264      }
     1265    }
     1266
    12581267                if ( empty( $post['ID'] ) )
    12591268                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
    12601269
     
    34823491                return $struct;
    34833492        }
    34843493
     3494        /**
     3495         * Retrieve revisions for a specific post.
     3496         *
     3497         * @since 3.5.0
     3498         *
     3499         * The optional $fields parameter specifies what fields will be included
     3500         * in the response array.
     3501         *
     3502         * @uses wp_get_post_revisions()
     3503         * @see wp_getPost() for more on $fields
     3504         *
     3505         * @param array $args Method parameters. Contains:
     3506         *  - int     $blog_id
     3507         *  - string  $username
     3508         *  - string  $password
     3509         *  - int     $post_id
     3510         *  - array   $fields
     3511         * @return array contains a collection of posts.
     3512         */
     3513        function wp_getRevisions( $args ) {
     3514                if ( ! $this->minimum_args( $args, 4 ) )
     3515                        return $this->error;
     3516                $this->escape( $args );
     3517
     3518                $blog_id    = (int) $args[0];
     3519                $username   = $args[1];
     3520                $password   = $args[2];
     3521                $post_id    = (int) $args[3];
     3522
     3523                if ( isset( $args[4] ) )
     3524                        $fields = $args[4];
     3525                else
     3526                        $fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post_date', 'post_date_gmt' ), 'wp.getRevisions' );
     3527
     3528                if ( ! $user = $this->login( $username, $password ) )
     3529                        return $this->error;
     3530
     3531                do_action( 'xmlrpc_call', 'wp.getRevisions' );
     3532
     3533    $post_type = get_post_type_object( 'post' );
     3534
     3535                if ( ! current_user_can( $post_type->cap->edit_posts ) )
     3536                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type' ));
     3537
     3538                $posts_list = wp_get_post_revisions( $post_id );
     3539
     3540                if ( ! $posts_list )
     3541                        return array();
     3542
     3543                // holds all the posts data
     3544                $struct = array();
     3545
     3546                foreach ( $posts_list as $post ) {
     3547      $post_data = get_object_vars( $post );
     3548                        $post_type = get_post_type_object( $post_data['post_type'] );
     3549                        if ( ! current_user_can( $post_type->cap->edit_post, $post_data['ID'] ) )
     3550                                continue;
     3551
     3552                        $struct[] = $this->_prepare_post( $post_data, $fields );
     3553                }
     3554
     3555                return $struct;
     3556        }
     3557
     3558        /**
     3559         * Restore a post revision
     3560         *
     3561         * @since 3.5.0
     3562         *
     3563         * @uses wp_restore_post_revision()
     3564         *
     3565         * @param array $args Method parameters. Contains:
     3566         *  - int     $blog_id
     3567         *  - string  $username
     3568         *  - string  $password
     3569         *  - int     $post_id
     3570         * @return bool false if there was an error restoring, true if success.
     3571         */
     3572        function wp_restoreRevision( $args ) {
     3573                if ( ! $this->minimum_args( $args, 3 ) )
     3574                        return $this->error;
     3575
     3576                $this->escape( $args );
     3577
     3578                $blog_id    = (int) $args[0];
     3579                $username   = $args[1];
     3580                $password   = $args[2];
     3581                $post_id    = (int) $args[3];
     3582
     3583                if ( ! $user = $this->login( $username, $password ) )
     3584                        return $this->error;
     3585
     3586                do_action( 'xmlrpc_call', 'wp.restoreRevision' );
     3587
     3588                $post = get_post( $post_id, ARRAY_A );
     3589                $post_type = get_post_type_object( $post['post_type'] );
     3590
     3591                if ( ! current_user_can( $post_type->cap->edit_post( $post->ID ) ) )
     3592                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type' ));
     3593
     3594                $post = wp_restore_post_revision( $post_id );
     3595
     3596                return (bool)$post;
     3597        }
     3598
    34853599        /* Blogger API functions.
    34863600         * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
    34873601         */