Make WordPress Core

Ticket #21397: patch-core-21397-3.diff

File patch-core-21397-3.diff, 4.2 KB (added by koke, 12 years ago)
  • wp-includes/class-wp-xmlrpc-server.php

    diff --git a/wp-includes/class-wp-xmlrpc-server.php b/wp-includes/class-wp-xmlrpc-server.php
    index 300f5f5..d3d5b68 100644
    a b class wp_xmlrpc_server extends IXR_Server { 
    7878                        'wp.getPostFormats'     => 'this:wp_getPostFormats',
    7979                        'wp.getPostType'                => 'this:wp_getPostType',
    8080                        'wp.getPostTypes'               => 'this:wp_getPostTypes',
     81                        'wp.getRevisions'               => 'this:wp_getRevisions',
     82                        'wp.restoreRevision'    => 'this:wp_restoreRevision',
    8183
    8284                        // Blogger API
    8385                        'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
    class wp_xmlrpc_server extends IXR_Server { 
    12041206
    12051207                $post = get_post( $post_id, ARRAY_A );
    12061208
     1209    if ( isset( $content_struct['only_if_no_new_revision'] ) ) {
     1210      // if there's a newer revision, return an error
     1211      if ( mysql2date( 'U', $post['post_modified_gmt'] ) > $content_struct['only_if_no_new_revision']->getTimestamp() ) {
     1212        return new IXR_Error( 409, __( 'There is a revision of this post that is more recent' ) );
     1213      }
     1214    }
     1215
    12071216                if ( empty( $post['ID'] ) )
    12081217                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
    12091218
    class wp_xmlrpc_server extends IXR_Server { 
    31713180                return $struct;
    31723181        }
    31733182
     3183        /**
     3184         * Retrieve revisions for a specific post.
     3185         *
     3186         * @since 3.5.0
     3187         *
     3188         * The optional $fields parameter specifies what fields will be included
     3189         * in the response array.
     3190         *
     3191         * @uses wp_get_post_revisions()
     3192         * @see wp_getPost() for more on $fields
     3193         *
     3194         * @param array $args Method parameters. Contains:
     3195         *  - int     $blog_id
     3196         *  - string  $username
     3197         *  - string  $password
     3198         *  - int     $post_id
     3199         *  - array   $fields
     3200         * @return array contains a collection of posts.
     3201         */
     3202        function wp_getRevisions( $args ) {
     3203                if ( ! $this->minimum_args( $args, 4 ) )
     3204                        return $this->error;
     3205                $this->escape( $args );
     3206
     3207                $blog_id    = (int) $args[0];
     3208                $username   = $args[1];
     3209                $password   = $args[2];
     3210                $post_id    = (int) $args[3];
     3211
     3212                if ( isset( $args[4] ) )
     3213                        $fields = $args[4];
     3214                else
     3215                        $fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post' ), 'wp.getRevisions' );
     3216
     3217                if ( ! $user = $this->login( $username, $password ) )
     3218                        return $this->error;
     3219
     3220                do_action( 'xmlrpc_call', 'wp.getRevisions' );
     3221
     3222    $post_type = get_post_type_object( 'post' );
     3223
     3224                if ( ! current_user_can( $post_type->cap->edit_posts ) )
     3225                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type' ));
     3226
     3227                $posts_list = wp_get_post_revisions( $post_id );
     3228
     3229                if ( ! $posts_list )
     3230                        return array();
     3231
     3232                // holds all the posts data
     3233                $struct = array();
     3234
     3235                foreach ( $posts_list as $post ) {
     3236      $post_data = get_object_vars( $post );
     3237                        $post_type = get_post_type_object( $post_data['post_type'] );
     3238                        if ( ! current_user_can( $post_type->cap->edit_post, $post_data['ID'] ) )
     3239                                continue;
     3240
     3241                        $struct[] = $this->_prepare_post( $post_data, $fields );
     3242                }
     3243
     3244                return $struct;
     3245        }
     3246
     3247        /**
     3248         * Restore a post revision
     3249         *
     3250         * @since 3.5.0
     3251         *
     3252         * @uses wp_restore_post_revision()
     3253         *
     3254         * @param array $args Method parameters. Contains:
     3255         *  - int     $blog_id
     3256         *  - string  $username
     3257         *  - string  $password
     3258         *  - int     $post_id
     3259         * @return bool false if there was an error restoring, true if success.
     3260         */
     3261        function wp_restoreRevision( $args ) {
     3262                if ( ! $this->minimum_args( $args, 3 ) )
     3263                        return $this->error;
     3264
     3265                $this->escape( $args );
     3266
     3267                $blog_id    = (int) $args[0];
     3268                $username   = $args[1];
     3269                $password   = $args[2];
     3270                $post_id    = (int) $args[3];
     3271
     3272                if ( ! $user = $this->login( $username, $password ) )
     3273                        return $this->error;
     3274
     3275                do_action( 'xmlrpc_call', 'wp.restoreRevision' );
     3276
     3277                $post = get_post( $post_id, ARRAY_A );
     3278    $post_type = get_post_type_object( $post['post_type'] );
     3279
     3280                if ( ! current_user_can( $post_type->cap->edit_posts ) )
     3281                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type' ));
     3282
     3283                $post = wp_restore_post_revision( $post_id );
     3284
     3285                return (bool)$post;
     3286        }
     3287
    31743288        /* Blogger API functions.
    31753289         * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
    31763290         */