Ticket #23665: 23665-2.patch
File 23665-2.patch, 7.5 KB (added by , 12 years ago) |
---|
-
wp-admin/includes/ajax-actions.php
1038 1038 $do_autosave = (bool) $_POST['autosave']; 1039 1039 $do_lock = true; 1040 1040 1041 if ( ! $user_id = get_current_user_id() ) 1042 wp_die('-1'); 1043 1041 1044 $data = $alert = ''; 1042 1045 /* translators: draft saved date format, see http://php.net/date */ 1043 1046 $draft_saved_date_format = __('g:i:s a'); … … 1057 1060 $_POST['post_status'] = 'draft'; 1058 1061 1059 1062 if ( $last = wp_check_post_lock( $post->ID ) ) { 1060 $do_ autosave = $do_lock = false;1063 $do_lock = false; 1061 1064 1062 1065 $last_user = get_userdata( $last ); 1063 1066 $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' ); 1064 $data = __( 'Autosave disabled.' );1065 1066 $supplemental['disable_autosave'] = 'disable';1067 1067 $alert .= sprintf( __( '%s is currently editing this article. If you update it, you will overwrite the changes.' ), esc_html( $last_user_name ) ); 1068 1068 } 1069 1069 … … 1076 1076 } 1077 1077 1078 1078 if ( $do_autosave ) { 1079 // Drafts and auto-drafts are just overwritten by autosave 1080 if ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status) {1079 // Drafts and auto-drafts are just overwritten by autosave for the same user 1080 if ( $user_id == $post->post_author && ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status ) ) { 1081 1081 $id = edit_post(); 1082 } else { // Non drafts are not overwritten. The autosave is stored in a special post revision .1082 } else { // Non drafts are not overwritten. The autosave is stored in a special post revision for each user. 1083 1083 $revision_id = wp_create_post_autosave( $post->ID ); 1084 1084 if ( is_wp_error($revision_id) ) 1085 1085 $id = $revision_id; -
wp-admin/includes/post.php
1236 1236 if ( is_wp_error( $translated ) ) 1237 1237 return $translated; 1238 1238 1239 // Only store one autosave. If there is already an autosave, overwrite it. 1240 if ( $old_autosave = wp_get_post_autosave( $post_id ) ) { 1239 $post_author = get_current_user_id(); 1240 1241 // Store one autosave per author. If there is already an autosave, overwrite it. 1242 if ( $old_autosave = wp_get_post_autosave( $post_id, $post_author ) ) { 1241 1243 $new_autosave = _wp_post_revision_fields( $_POST, true ); 1242 1244 $new_autosave['ID'] = $old_autosave->ID; 1243 $new_autosave['post_author'] = get_current_user_id();1245 $new_autosave['post_author'] = $post_author; 1244 1246 return wp_update_post( $new_autosave ); 1245 1247 } 1246 1248 … … 1295 1297 wp_die(__('You are not allowed to edit this post.')); 1296 1298 } 1297 1299 1298 if ( 'draft' == $post->post_status ) { 1300 $user_id = get_current_user_id(); 1301 if ( 'draft' == $post->post_status && $user_id == $post->post_author ) { 1299 1302 $id = edit_post(); 1300 1303 } else { // Non drafts are not overwritten. The autosave is stored in a special post revision. 1301 1304 $id = wp_create_post_autosave( $post->ID ); … … 1306 1309 if ( is_wp_error($id) ) 1307 1310 wp_die( $id->get_error_message() ); 1308 1311 1309 if ( $_POST['post_status'] == 'draft' ) {1312 if ( $_POST['post_status'] == 'draft' && $user_id == $post->post_author ) { 1310 1313 $url = add_query_arg( 'preview', 'true', get_permalink($id) ); 1311 1314 } else { 1312 1315 $nonce = wp_create_nonce('post_preview_' . $id); -
wp-admin/post.php
169 169 add_action('admin_notices', '_admin_notice_post_locked' ); 170 170 } else { 171 171 $active_post_lock = wp_set_post_lock( $post->ID ); 172 173 if ( 'attachment' !== $post_type )174 wp_enqueue_script('autosave');175 172 } 176 173 174 if ( 'attachment' !== $post_type ) 175 wp_enqueue_script('autosave'); 176 177 177 $title = $post_type_object->labels->edit_item; 178 178 $post = get_post($post_id, OBJECT, 'edit'); 179 179 -
wp-includes/revision.php
135 135 * Retrieve the autosaved data of the specified post. 136 136 * 137 137 * Returns a post object containing the information that was autosaved for the 138 * specified post. 138 * specified post. If the optional $user_id is passed, returns the autosave for that user 139 * otherwise returns the latest autosave. 139 140 * 140 141 * @package WordPress 141 142 * @subpackage Post_Revisions 142 143 * @since 2.6.0 143 * 144 * @uses wp_get_post_revisions() 145 * 144 146 * @param int $post_id The post ID. 147 * @param int $user_id optional The post author ID. 145 148 * @return object|bool The autosaved data or false on failure or when no autosave exists. 146 149 */ 147 function wp_get_post_autosave( $post_id ) { 150 function wp_get_post_autosave( $post_id, $user_id = 0 ) { 151 $revisions = wp_get_post_revisions($post_id); 148 152 149 if ( !$post = get_post( $post_id ) ) 150 return false; 153 foreach ( $revisions as $revision ) { 154 if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) { 155 if ( $user_id && $user_id != $revision->post_author ) 156 continue; 151 157 152 $q = array( 153 'name' => "{$post->ID}-autosave", 154 'post_parent' => $post->ID, 155 'post_type' => 'revision', 156 'post_status' => 'inherit' 157 ); 158 return $revision; 159 break; 160 } 161 } 158 162 159 // Use WP_Query so that the result gets cached160 $autosave_query = new WP_Query;161 162 add_action( 'parse_query', '_wp_get_post_autosave_hack' );163 $autosave = $autosave_query->query( $q );164 remove_action( 'parse_query', '_wp_get_post_autosave_hack' );165 166 if ( $autosave && is_array($autosave) && is_object($autosave[0]) )167 return $autosave[0];168 169 163 return false; 170 164 } 171 165 172 166 /** 173 * Internally used to hack WP_Query into submission.174 *175 * @package WordPress176 * @subpackage Post_Revisions177 * @since 2.6.0178 *179 * @param object $query WP_Query object180 */181 function _wp_get_post_autosave_hack( $query ) {182 $query->is_single = false;183 }184 185 /**186 167 * Determines if the specified post is a revision. 187 168 * 188 169 * @package WordPress … … 195 176 function wp_is_post_revision( $post ) { 196 177 if ( !$post = wp_get_post_revision( $post ) ) 197 178 return false; 179 198 180 return (int) $post->post_parent; 199 181 } 200 182 … … 211 193 function wp_is_post_autosave( $post ) { 212 194 if ( !$post = wp_get_post_revision( $post ) ) 213 195 return false; 214 if ( "{$post->post_parent}-autosave" !== $post->post_name ) 215 return false; 216 return (int) $post->post_parent; 196 197 if ( false !== strpos( $post->post_name, "{$post->post_parent}-autosave" ) ) 198 return (int) $post->post_parent; 199 200 return false; 217 201 } 218 202 219 203 /** … … 234 218 $post = get_object_vars( $post ); 235 219 elseif ( !is_array($post) ) 236 220 $post = get_post($post, ARRAY_A); 221 237 222 if ( !$post || empty($post['ID']) ) 238 223 return; 239 224 … … 249 234 250 235 if ( $revision_id ) 251 236 do_action( '_wp_put_post_revision', $revision_id ); 237 252 238 return $revision_id; 253 239 } 254 240 … … 312 298 $fields = array_keys( _wp_post_revision_fields() ); 313 299 314 300 $update = array(); 315 foreach( array_intersect( array_keys( $revision ), $fields ) as $field ) 301 foreach( array_intersect( array_keys( $revision ), $fields ) as $field ) { 316 302 $update[$field] = $revision[$field]; 303 } 317 304 318 305 if ( !$update ) 319 306 return false; … … 374 361 * @return array empty if no revisions 375 362 */ 376 363 function wp_get_post_revisions( $post_id = 0, $args = null ) { 377 if ( ! WP_POST_REVISIONS )378 return array();379 364 if ( ( !$post = get_post( $post_id ) ) || empty( $post->ID ) ) 380 365 return array(); 381 366 … … 385 370 386 371 if ( !$revisions = get_children( $args ) ) 387 372 return array(); 373 388 374 return $revisions; 389 375 } 390 376