Ticket #21397: patch-core-21397-4.diff
File patch-core-21397-4.diff, 6.5 KB (added by , 11 years ago) |
---|
-
wp-includes/class-wp-xmlrpc-server.php
82 82 'wp.getPostFormats' => 'this:wp_getPostFormats', 83 83 'wp.getPostType' => 'this:wp_getPostType', 84 84 'wp.getPostTypes' => 'this:wp_getPostTypes', 85 'wp.getRevisions' => 'this:wp_getRevisions', 86 'wp.restoreRevision' => 'this:wp_restoreRevision', 85 87 86 88 // Blogger API 87 89 'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs', … … 1271 1273 1272 1274 $post = get_post( $post_id, ARRAY_A ); 1273 1275 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 1274 1283 if ( empty( $post['ID'] ) ) 1275 1284 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); 1276 1285 … … 1287 1296 $this->escape( $post ); 1288 1297 $merged_content_struct = array_merge( $post, $content_struct ); 1289 1298 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 1290 1309 $retval = $this->_insert_post( $user, $merged_content_struct ); 1291 1310 if ( $retval instanceof IXR_Error ) 1292 1311 return $retval; 1293 1312 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 } 1294 1323 return true; 1295 1324 } 1296 1325 … … 3495 3524 return $struct; 3496 3525 } 3497 3526 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 3498 3632 /* Blogger API functions. 3499 3633 * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/ 3500 3634 */ -
wp-admin/includes/post.php
1234 1234 * 1235 1235 * @return unknown 1236 1236 */ 1237 function wp_create_post_autosave( $post_id ) { 1238 $translated = _wp_translate_postdata( true ); 1239 if ( is_wp_error( $translated ) ) 1240 return $translated; 1237 function 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 } 1241 1243 1242 1244 // Only store one autosave. If there is already an autosave, overwrite it. 1243 1245 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 ); 1245 1247 $new_autosave['ID'] = $old_autosave->ID; 1246 1248 $new_autosave['post_author'] = get_current_user_id(); 1247 1249 return wp_update_post( $new_autosave ); 1248 1250 } 1249 1251 1250 1252 // _wp_put_post_revision() expects unescaped. 1251 $ _POST = stripslashes_deep($_POST);1253 $post_data = stripslashes_deep($post_data); 1252 1254 1253 1255 // 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 ); 1255 1257 } 1256 1258 1257 1259 /**