Ticket #21397: 21397.5.diff

File 21397.5.diff, 5.4 KB (added by JustinSainton, 8 months ago)
Line 
1Index: wp-admin/includes/post.php
2===================================================================
3--- wp-admin/includes/post.php  (revision 21959)
4+++ wp-admin/includes/post.php  (working copy)
5@@ -1238,24 +1238,26 @@
6  *
7  * @return unknown
8  */
9-function wp_create_post_autosave( $post_id ) {
10-       $translated = _wp_translate_postdata( true );
11-       if ( is_wp_error( $translated ) )
12-               return $translated;
13+function wp_create_post_autosave( $post_id, $post_data = null ) {
14+       if ( empty($post_data) ) {
15+               $post_data = _wp_translate_postdata( true, $_POST );
16+               if ( is_wp_error( $post_data ) )
17+                       return $post_data;
18+       }
19 
20        // Only store one autosave. If there is already an autosave, overwrite it.
21        if ( $old_autosave = wp_get_post_autosave( $post_id ) ) {
22-               $new_autosave = _wp_post_revision_fields( $_POST, true );
23+               $new_autosave = _wp_post_revision_fields( $post_data, true );
24                $new_autosave['ID'] = $old_autosave->ID;
25                $new_autosave['post_author'] = get_current_user_id();
26                return wp_update_post( $new_autosave );
27        }
28 
29        // _wp_put_post_revision() expects unescaped.
30-       $_POST = stripslashes_deep($_POST);
31+       $post_data = stripslashes_deep($post_data);
32 
33        // Otherwise create the new autosave as a special post revision
34-       return _wp_put_post_revision( $_POST, true );
35+       return _wp_put_post_revision( $post_data, true );
36 }
37 
38 /**
39Index: wp-includes/class-wp-xmlrpc-server.php
40===================================================================
41--- wp-includes/class-wp-xmlrpc-server.php      (revision 21959)
42+++ wp-includes/class-wp-xmlrpc-server.php      (working copy)
43@@ -82,6 +82,8 @@
44                        'wp.getPostFormats'     => 'this:wp_getPostFormats',
45                        'wp.getPostType'                => 'this:wp_getPostType',
46                        'wp.getPostTypes'               => 'this:wp_getPostTypes',
47+                       'wp.getRevisions'               => 'this:wp_getRevisions',
48+                       'wp.restoreRevision'    => 'this:wp_restoreRevision',
49 
50                        // Blogger API
51                        'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
52@@ -1255,6 +1257,13 @@
53 
54                $post = get_post( $post_id, ARRAY_A );
55 
56+    if ( isset( $content_struct['only_if_no_new_revision'] ) ) {
57+      // if there's a newer revision, return an error
58+      if ( mysql2date( 'U', $post['post_modified_gmt'] ) > $content_struct['only_if_no_new_revision']->getTimestamp() ) {
59+        return new IXR_Error( 409, __( 'There is a revision of this post that is more recent' ) );
60+      }
61+    }
62+
63                if ( empty( $post['ID'] ) )
64                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
65 
66@@ -3482,6 +3491,111 @@
67                return $struct;
68        }
69 
70+       /**
71+        * Retrieve revisions for a specific post.
72+        *
73+        * @since 3.5.0
74+        *
75+        * The optional $fields parameter specifies what fields will be included
76+        * in the response array.
77+        *
78+        * @uses wp_get_post_revisions()
79+        * @see wp_getPost() for more on $fields
80+        *
81+        * @param array $args Method parameters. Contains:
82+        *  - int     $blog_id
83+        *  - string  $username
84+        *  - string  $password
85+        *  - int     $post_id
86+        *  - array   $fields
87+        * @return array contains a collection of posts.
88+        */
89+       function wp_getRevisions( $args ) {
90+               if ( ! $this->minimum_args( $args, 4 ) )
91+                       return $this->error;
92+               $this->escape( $args );
93+
94+               $blog_id    = (int) $args[0];
95+               $username   = $args[1];
96+               $password   = $args[2];
97+               $post_id    = (int) $args[3];
98+
99+               if ( isset( $args[4] ) )
100+                       $fields = $args[4];
101+               else
102+                       $fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post_date', 'post_date_gmt' ), 'wp.getRevisions' );
103+
104+               if ( ! $user = $this->login( $username, $password ) )
105+                       return $this->error;
106+
107+               do_action( 'xmlrpc_call', 'wp.getRevisions' );
108+
109+    $post_type = get_post_type_object( 'post' );
110+
111+               if ( ! current_user_can( $post_type->cap->edit_posts ) )
112+                       return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type' ));
113+
114+               $posts_list = wp_get_post_revisions( $post_id );
115+
116+               if ( ! $posts_list )
117+                       return array();
118+
119+               // holds all the posts data
120+               $struct = array();
121+
122+               foreach ( $posts_list as $post ) {
123+      $post_data = get_object_vars( $post );
124+                       $post_type = get_post_type_object( $post_data['post_type'] );
125+                       if ( ! current_user_can( $post_type->cap->edit_post, $post_data['ID'] ) )
126+                               continue;
127+
128+                       $struct[] = $this->_prepare_post( $post_data, $fields );
129+               }
130+
131+               return $struct;
132+       }
133+
134+       /**
135+        * Restore a post revision
136+        *
137+        * @since 3.5.0
138+        *
139+        * @uses wp_restore_post_revision()
140+        *
141+        * @param array $args Method parameters. Contains:
142+        *  - int     $blog_id
143+        *  - string  $username
144+        *  - string  $password
145+        *  - int     $post_id
146+        * @return bool false if there was an error restoring, true if success.
147+        */
148+       function wp_restoreRevision( $args ) {
149+               if ( ! $this->minimum_args( $args, 3 ) )
150+                       return $this->error;
151+
152+               $this->escape( $args );
153+
154+               $blog_id    = (int) $args[0];
155+               $username   = $args[1];
156+               $password   = $args[2];
157+               $post_id    = (int) $args[3];
158+
159+               if ( ! $user = $this->login( $username, $password ) )
160+                       return $this->error;
161+
162+               do_action( 'xmlrpc_call', 'wp.restoreRevision' );
163+
164+               $post = get_post( $post_id, ARRAY_A );
165+               $post_type = get_post_type_object( $post['post_type'] );
166+
167+               if ( ! current_user_can( $post_type->cap->edit_post( $post->ID ) ) )
168+                       return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type' ));
169+
170+               $post = wp_restore_post_revision( $post_id );
171+
172+               return (bool)$post;
173+       }
174+
175        /* Blogger API functions.
176         * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
177         */