Make WordPress Core

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

File patch-core-21397-4.diff, 6.5 KB (added by koke, 11 years ago)
  • 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',
     
    12711273
    12721274                $post = get_post( $post_id, ARRAY_A );
    12731275
     1276    if ( isset( $content_struct['only_if_no_new_revision'] ) ) {
     1277      // if there's a newer revision, return an error
     1278      if ( mysql2date( 'U', $post['post_modified_gmt'] ) > $content_struct['only_if_no_new_revision']->getTimestamp() ) {
     1279        return new IXR_Error( 409, __( 'There is a revision of this post that is more recent' ) );
     1280      }
     1281    }
     1282
    12741283                if ( empty( $post['ID'] ) )
    12751284                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
    12761285
     
    12871296                $this->escape( $post );
    12881297                $merged_content_struct = array_merge( $post, $content_struct );
    12891298
     1299                $id = $post_id;
     1300                if ( isset( $content_struct['return_preview_url'] ) && ( 'draft' != $post['post_status'] ) ) {
     1301                        $id = wp_create_post_autosave( $post_id, $merged_content_struct );
     1302                        if ( is_wp_error( $id ) )
     1303                                return new IXR_Error( 500, $id->get_error_message() );
     1304
     1305                        if ( ! $id )
     1306                                return new IXR_Error( 401, __( 'Sorry, your entry could not be posted. Something wrong happened.' ) );
     1307                }
     1308
    12901309                $retval = $this->_insert_post( $user, $merged_content_struct );
    12911310                if ( $retval instanceof IXR_Error )
    12921311                        return $retval;
    12931312
     1313                if ( isset( $content_struct['return_preview_url'] ) && $content_struct['return_preview_url'] ) {
     1314                        if ( $post['post_status'] == 'draft'  ) {
     1315                                $url = add_query_arg( 'preview', 'true', get_permalink($id) );
     1316                        } else {
     1317                                $nonce = wp_create_nonce('post_preview_' . $id);
     1318                                $url = add_query_arg( array( 'preview' => 'true', 'preview_id' => $id, 'preview_nonce' => $nonce ), get_permalink($id) );
     1319                        }
     1320
     1321                        return array( 'preview_url' => $url );
     1322                }
    12941323                return true;
    12951324        }
    12961325
     
    34953524                return $struct;
    34963525        }
    34973526
     3527        /**
     3528         * Retrieve revisions for a specific post.
     3529         *
     3530         * @since 3.5.0
     3531         *
     3532         * The optional $fields parameter specifies what fields will be included
     3533         * in the response array.
     3534         *
     3535         * @uses wp_get_post_revisions()
     3536         * @see wp_getPost() for more on $fields
     3537         *
     3538         * @param array $args Method parameters. Contains:
     3539         *  - int     $blog_id
     3540         *  - string  $username
     3541         *  - string  $password
     3542         *  - int     $post_id
     3543         *  - array   $fields
     3544         * @return array contains a collection of posts.
     3545         */
     3546        function wp_getRevisions( $args ) {
     3547                if ( ! $this->minimum_args( $args, 4 ) )
     3548                        return $this->error;
     3549                $this->escape( $args );
     3550
     3551                $blog_id    = (int) $args[0];
     3552                $username   = $args[1];
     3553                $password   = $args[2];
     3554                $post_id    = (int) $args[3];
     3555
     3556                if ( isset( $args[4] ) )
     3557                        $fields = $args[4];
     3558                else
     3559                        $fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post' ), 'wp.getRevisions' );
     3560
     3561                if ( ! $user = $this->login( $username, $password ) )
     3562                        return $this->error;
     3563
     3564                do_action( 'xmlrpc_call', 'wp.getRevisions' );
     3565
     3566    $post_type = get_post_type_object( 'post' );
     3567
     3568                if ( ! current_user_can( $post_type->cap->edit_posts ) )
     3569                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type' ));
     3570
     3571                $posts_list = wp_get_post_revisions( $post_id );
     3572
     3573                if ( ! $posts_list )
     3574                        return array();
     3575
     3576                // holds all the posts data
     3577                $struct = array();
     3578
     3579                foreach ( $posts_list as $post ) {
     3580      $post_data = get_object_vars( $post );
     3581                        $post_type = get_post_type_object( $post_data['post_type'] );
     3582                        if ( ! current_user_can( $post_type->cap->edit_post, $post_data['ID'] ) )
     3583                                continue;
     3584
     3585                        $struct[] = $this->_prepare_post( $post_data, $fields );
     3586                }
     3587
     3588                return $struct;
     3589        }
     3590
     3591        /**
     3592         * Restore a post revision
     3593         *
     3594         * @since 3.5.0
     3595         *
     3596         * @uses wp_restore_post_revision()
     3597         *
     3598         * @param array $args Method parameters. Contains:
     3599         *  - int     $blog_id
     3600         *  - string  $username
     3601         *  - string  $password
     3602         *  - int     $post_id
     3603         * @return bool false if there was an error restoring, true if success.
     3604         */
     3605        function wp_restoreRevision( $args ) {
     3606                if ( ! $this->minimum_args( $args, 3 ) )
     3607                        return $this->error;
     3608
     3609                $this->escape( $args );
     3610
     3611                $blog_id    = (int) $args[0];
     3612                $username   = $args[1];
     3613                $password   = $args[2];
     3614                $post_id    = (int) $args[3];
     3615
     3616                if ( ! $user = $this->login( $username, $password ) )
     3617                        return $this->error;
     3618
     3619                do_action( 'xmlrpc_call', 'wp.restoreRevision' );
     3620
     3621                $post = get_post( $post_id, ARRAY_A );
     3622    $post_type = get_post_type_object( $post['post_type'] );
     3623
     3624                if ( ! current_user_can( $post_type->cap->edit_posts ) )
     3625                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type' ));
     3626
     3627                $post = wp_restore_post_revision( $post_id );
     3628
     3629                return (bool)$post;
     3630        }
     3631
    34983632        /* Blogger API functions.
    34993633         * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
    35003634         */
  • wp-admin/includes/post.php

     
    12341234 *
    12351235 * @return unknown
    12361236 */
    1237 function wp_create_post_autosave( $post_id ) {
    1238         $translated = _wp_translate_postdata( true );
    1239         if ( is_wp_error( $translated ) )
    1240                 return $translated;
     1237function wp_create_post_autosave( $post_id, $post_data = null ) {
     1238        if ( empty($post_data) ) {
     1239                $post_data = _wp_translate_postdata( true, $_POST );
     1240                if ( is_wp_error( $post_data ) )
     1241                        return $post_data;
     1242        }
    12411243
    12421244        // Only store one autosave. If there is already an autosave, overwrite it.
    12431245        if ( $old_autosave = wp_get_post_autosave( $post_id ) ) {
    1244                 $new_autosave = _wp_post_revision_fields( $_POST, true );
     1246                $new_autosave = _wp_post_revision_fields( $post_data, true );
    12451247                $new_autosave['ID'] = $old_autosave->ID;
    12461248                $new_autosave['post_author'] = get_current_user_id();
    12471249                return wp_update_post( $new_autosave );
    12481250        }
    12491251
    12501252        // _wp_put_post_revision() expects unescaped.
    1251         $_POST = stripslashes_deep($_POST);
     1253        $post_data = stripslashes_deep($post_data);
    12521254
    12531255        // Otherwise create the new autosave as a special post revision
    1254         return _wp_put_post_revision( $_POST, true );
     1256        return _wp_put_post_revision( $post_data, true );
    12551257}
    12561258
    12571259/**