Ticket #21397: 21397.6.diff

File 21397.6.diff, 4.7 KB (added by markoheijnen, 8 months ago)

Used feedback of Nacin. Only need to check ->getTimestamp()

  • 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_modified_since'] ) ) { 
     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 
     3517                $this->escape( $args ); 
     3518 
     3519                $blog_id    = (int) $args[0]; 
     3520                $username   = $args[1]; 
     3521                $password   = $args[2]; 
     3522                $post_id    = (int) $args[3]; 
     3523 
     3524                if ( isset( $args[4] ) ) 
     3525                        $fields = $args[4]; 
     3526                else 
     3527                        $fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post_date', 'post_date_gmt' ), 'wp.getRevisions' ); 
     3528 
     3529                if ( ! $user = $this->login( $username, $password ) ) 
     3530                        return $this->error; 
     3531 
     3532                do_action( 'xmlrpc_call', 'wp.getRevisions' ); 
     3533 
     3534                if ( ! current_user_can( 'edit_post', $post_id ) ) 
     3535                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type' ) ); 
     3536 
     3537                if ( ! $post = get_post( $post_id ) ) 
     3538                        return new IXR_Error( 403, __( 'Invalid post ID' ) ); 
     3539 
     3540                // Revisions disabled and we're not looking at an autosave 
     3541                if ( ! WP_POST_REVISIONS || ! post_type_supports( $post->post_type, 'revisions') ) 
     3542                        return new IXR_Error( 401, __( 'Sorry, revisions is disabled for this post type.' ) ); 
     3543 
     3544                $revisions = wp_get_post_revisions( $post_id ); 
     3545 
     3546                if ( ! $revisions ) 
     3547                        return array(); 
     3548 
     3549                $struct = array(); 
     3550 
     3551                foreach ( $revisions as $revision ) { 
     3552                        if ( ! current_user_can( 'read_post', $revision->ID ) ) 
     3553                                continue; 
     3554 
     3555                        // Skip all autosave posts 
     3556                        if ( wp_is_post_autosave( $revision ) ) 
     3557                                continue; 
     3558 
     3559                        $struct[] = $this->_prepare_post( get_object_vars( $revision ), $fields ); 
     3560                } 
     3561 
     3562                return $struct; 
     3563        } 
     3564 
     3565        /** 
     3566         * Restore a post revision 
     3567         * 
     3568         * @since 3.5.0 
     3569         * 
     3570         * @uses wp_restore_post_revision() 
     3571         * 
     3572         * @param array $args Method parameters. Contains: 
     3573         *  - int     $blog_id 
     3574         *  - string  $username 
     3575         *  - string  $password 
     3576         *  - int     $post_id 
     3577         * @return bool false if there was an error restoring, true if success. 
     3578         */ 
     3579        function wp_restoreRevision( $args ) { 
     3580                if ( ! $this->minimum_args( $args, 3 ) ) 
     3581                        return $this->error; 
     3582 
     3583                $this->escape( $args ); 
     3584 
     3585                $blog_id     = (int) $args[0]; 
     3586                $username    = $args[1]; 
     3587                $password    = $args[2]; 
     3588                $revision_id = (int) $args[3]; 
     3589 
     3590                if ( ! $user = $this->login( $username, $password ) ) 
     3591                        return $this->error; 
     3592 
     3593                do_action( 'xmlrpc_call', 'wp.restoreRevision' ); 
     3594 
     3595                if ( ! $revision = wp_get_post_revision( $revision_id ) ) 
     3596                        return new IXR_Error( 403, __( 'Invalid post ID' )); 
     3597 
     3598                if ( ! current_user_can( 'edit_post', $revision->post_parent ) ) 
     3599                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); 
     3600 
     3601                if ( ! $post = get_post( $revision->post_parent ) ) 
     3602                        return new IXR_Error( 401, __( 'Sorry, the post that belongs to this revision is removed' ) ); 
     3603 
     3604                // Revisions disabled and we're not looking at an autosave 
     3605                if ( ( ! WP_POST_REVISIONS || ! post_type_supports( $post->post_type, 'revisions') ) && ! wp_is_post_autosave( $revision ) ) 
     3606                        return new IXR_Error( 401, __( 'Sorry, revisions is disabled for this post type.' ) ); 
     3607 
     3608                $post = wp_restore_post_revision( $post_id ); 
     3609 
     3610                return (bool)$post; 
     3611        } 
     3612 
    34853613        /* Blogger API functions. 
    34863614         * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/ 
    34873615         */