Changeset 23735
- Timestamp:
- 03/16/2013 09:15:43 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/ajax-actions.php
r23729 r23735 1044 1044 1045 1045 $do_autosave = (bool) $_POST['autosave']; 1046 $do_lock = true;1047 1046 $data = ''; 1048 1047 $supplemental = array(); 1049 1048 $id = $revision_id = 0; 1050 1049 1051 /* translators: draft saved date format, see http://php.net/date */ 1052 $draft_saved_date_format = __('g:i:s a'); 1053 /* translators: %s: date and time */ 1054 $message = sprintf( __('Draft saved at %s.'), date_i18n( $draft_saved_date_format ) ); 1050 if ( ! $user_id = get_current_user_id() ) 1051 wp_die('-1'); 1055 1052 1056 1053 $post_id = (int) $_POST['post_id']; … … 1059 1056 if ( 'auto-draft' == $post->post_status ) 1060 1057 $_POST['post_status'] = 'draft'; 1061 1062 if ( $last = wp_check_post_lock( $post->ID ) ) {1063 // This will change after we have per-user autosaves1064 $do_autosave = $do_lock = false;1065 1066 $last_user = get_userdata( $last );1067 $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );1068 $data = __( 'Autosave disabled.' );1069 1070 $supplemental['disable_autosave'] = 'disable';1071 }1072 1058 1073 1059 if ( 'page' == $post->post_type ) { … … 1080 1066 1081 1067 if ( $do_autosave ) { 1082 // Drafts and auto-drafts are just overwritten by autosave 1083 if ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status) {1068 // Drafts and auto-drafts are just overwritten by autosave for the same user 1069 if ( $user_id == $post->post_author && ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status ) ) { 1084 1070 $id = edit_post(); 1085 } else { // Non drafts are not overwritten. The autosave is stored in a special post revision .1071 } else { // Non drafts are not overwritten. The autosave is stored in a special post revision for each user. 1086 1072 $revision_id = wp_create_post_autosave( $post->ID ); 1087 1073 if ( is_wp_error($revision_id) ) … … 1090 1076 $id = $post->ID; 1091 1077 } 1092 $data = $message; 1078 1079 if ( is_wp_error($id) ) { 1080 // is_wp_error($id) overwrites $data in WP_Ajax_Response but no point in doing wp_create_nonce('update-post_' . $id) below 1081 // todo: Needs review. The errors generated in WP_Ajax_Response and parsed with wpAjax.parseAjaxResponse() haven't been used for many years. 1082 $data = $id; 1083 $id = 0; 1084 } else { 1085 /* translators: draft saved date format, see http://php.net/date */ 1086 $draft_saved_date_format = __('g:i:s a'); 1087 /* translators: %s: date and time */ 1088 $data = sprintf( __('Draft saved at %s.'), date_i18n( $draft_saved_date_format ) ); 1089 } 1093 1090 } else { 1094 1091 if ( ! empty( $_POST['auto_draft'] ) ) … … 1104 1101 $supplemental['replace-closedpostboxesnonce'] = wp_create_nonce('closedpostboxes'); 1105 1102 $supplemental['replace-_ajax_linking_nonce'] = wp_create_nonce( 'internal-linking' ); 1106 if ( $id ) { 1107 if ( $_POST['post_type'] == 'post' ) 1108 $supplemental['replace-_wpnonce'] = wp_create_nonce('update-post_' . $id); 1109 elseif ( $_POST['post_type'] == 'page' ) 1110 $supplemental['replace-_wpnonce'] = wp_create_nonce('update-page_' . $id); 1111 } 1103 if ( $id ) 1104 $supplemental['replace-_wpnonce'] = wp_create_nonce('update-post_' . $id); 1112 1105 } 1113 1106 -
trunk/wp-admin/includes/post.php
r23733 r23735 1281 1281 return $translated; 1282 1282 1283 // Only store one autosave. If there is already an autosave, overwrite it. 1284 if ( $old_autosave = wp_get_post_autosave( $post_id ) ) { 1283 $post_author = get_current_user_id(); 1284 1285 // Store one autosave per author. If there is already an autosave, overwrite it. 1286 if ( $old_autosave = wp_get_post_autosave( $post_id, $post_author ) ) { 1285 1287 $new_autosave = _wp_post_revision_fields( $_POST, true ); 1286 1288 $new_autosave['ID'] = $old_autosave->ID; 1287 $new_autosave['post_author'] = get_current_user_id();1289 $new_autosave['post_author'] = $post_author; 1288 1290 return wp_update_post( $new_autosave ); 1289 1291 } … … 1340 1342 } 1341 1343 1342 if ( 'draft' == $post->post_status ) { 1344 $user_id = get_current_user_id(); 1345 if ( 'draft' == $post->post_status && $user_id == $post->post_author ) { 1343 1346 $id = edit_post(); 1344 1347 } else { // Non drafts are not overwritten. The autosave is stored in a special post revision. … … 1351 1354 wp_die( $id->get_error_message() ); 1352 1355 1353 if ( $_POST['post_status'] == 'draft' ) {1356 if ( $_POST['post_status'] == 'draft' && $user_id == $post->post_author ) { 1354 1357 $url = add_query_arg( 'preview', 'true', get_permalink($id) ); 1355 1358 } else { -
trunk/wp-includes/js/autosave.js
r23705 r23735 1 var autosave, autosaveLast = '', autosavePeriodical, autosave OldMessage = '', autosaveDelayPreview = false, notSaved = true, blockSave = false, fullscreen, autosaveLockRelease = true;1 var autosave, autosaveLast = '', autosavePeriodical, autosaveDelayPreview = false, notSaved = true, blockSave = false, fullscreen, autosaveLockRelease = true; 2 2 3 3 jQuery(document).ready( function($) { … … 131 131 }); 132 132 133 function autosave_parse_response( response) {134 var res = wpAjax.parseAjaxResponse(response, 'autosave'), message = '', postID, sup;133 function autosave_parse_response( response ) { 134 var res = wpAjax.parseAjaxResponse(response, 'autosave'), post_id, sup; 135 135 136 136 if ( res && res.responses && res.responses.length ) { 137 message = res.responses[0].data; // The saved message or error.138 // someone else is editing: disable autosave, set errors139 137 if ( res.responses[0].supplemental ) { 140 138 sup = res.responses[0].supplemental; 141 if ( 'disable' == sup['disable_autosave'] ) { 142 autosave = function() {}; 143 autosaveLockRelease = false; 144 res = { errors: true }; 145 } 146 147 if ( sup['active-post-lock'] ) { 148 jQuery('#active_post_lock').val( sup['active-post-lock'] ); 149 } 150 151 if ( sup['alert'] ) { 152 jQuery('#autosave-alert').remove(); 153 jQuery('#titlediv').after('<div id="autosave-alert" class="error below-h2"><p>' + sup['alert'] + '</p></div>'); 154 } 155 156 jQuery.each(sup, function(selector, value) { 157 if ( selector.match(/^replace-/) ) { 158 jQuery('#'+selector.replace('replace-', '')).val(value); 159 } 139 140 jQuery.each( sup, function( selector, value ) { 141 if ( selector.match(/^replace-/) ) 142 jQuery( '#' + selector.replace('replace-', '') ).val( value ); 160 143 }); 161 144 } 162 145 163 // if no errors: add slug UI 146 // if no errors: add slug UI and update autosave-message 164 147 if ( !res.errors ) { 165 postID = parseInt( res.responses[0].id, 10 ); 166 if ( !isNaN(postID) && postID > 0 ) { 167 autosave_update_slug(postID); 168 } 169 } 170 } 171 if ( message ) { // update autosave message 172 jQuery('.autosave-message').html(message); 173 } else if ( autosaveOldMessage && res ) { 174 jQuery('.autosave-message').html( autosaveOldMessage ); 175 } 148 if ( post_id = parseInt( res.responses[0].id, 10 ) ) 149 autosave_update_slug( post_id ); 150 151 if ( res.responses[0].data ) // update autosave message 152 jQuery('.autosave-message').text( res.responses[0].data ); 153 } 154 } 155 176 156 return res; 177 157 } … … 187 167 function autosave_saved_new(response) { 188 168 blockSave = false; 189 var res = autosave_parse_response(response), post ID;169 var res = autosave_parse_response(response), post_id; 190 170 191 171 if ( res && res.responses.length && !res.errors ) { 192 172 // An ID is sent only for real auto-saves, not for autosave=0 "keepalive" saves 193 postID = parseInt( res.responses[0].id, 10 ); 194 if ( !isNaN(postID) && postID > 0 ) { 173 post_id = parseInt( res.responses[0].id, 10 ); 174 175 if ( post_id ) { 195 176 notSaved = false; 196 177 jQuery('#auto_draft').val('0'); // No longer an auto-draft 197 178 } 179 198 180 autosave_enable_buttons(); 181 199 182 if ( autosaveDelayPreview ) { 200 183 autosaveDelayPreview = false; … … 287 270 } 288 271 289 autosaveOldMessage = jQuery('#autosave').html();290 272 jQuery.ajax({ 291 273 data: post_data, -
trunk/wp-includes/revision.php
r23594 r23735 136 136 * 137 137 * Returns a post object containing the information that was autosaved for the 138 * specified post. 139 * 140 * @package WordPress 141 * @subpackage Post_Revisions 142 * @since 2.6.0 143 * 138 * specified post. If the optional $user_id is passed, returns the autosave for that user 139 * otherwise returns the latest autosave. 140 * 141 * @package WordPress 142 * @subpackage Post_Revisions 143 * @since 2.6.0 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 ) { 148 149 if ( !$post = get_post( $post_id ) ) 150 return false; 151 152 $q = array( 153 'name' => "{$post->ID}-autosave", 154 'post_parent' => $post->ID, 155 'post_type' => 'revision', 156 'post_status' => 'inherit' 157 ); 158 159 // Use WP_Query so that the result gets cached 160 $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]; 150 function wp_get_post_autosave( $post_id, $user_id = 0 ) { 151 $revisions = wp_get_post_revisions($post_id); 152 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; 157 158 return $revision; 159 break; 160 } 161 } 168 162 169 163 return false; 170 }171 172 /**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 164 } 184 165 … … 196 177 if ( !$post = wp_get_post_revision( $post ) ) 197 178 return false; 179 198 180 return (int) $post->post_parent; 199 181 } … … 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 … … 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; … … 250 235 if ( $revision_id ) 251 236 do_action( '_wp_put_post_revision', $revision_id ); 237 252 238 return $revision_id; 253 239 } … … 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 ) … … 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(); … … 386 371 if ( !$revisions = get_children( $args ) ) 387 372 return array(); 373 388 374 return $revisions; 389 375 }
Note: See TracChangeset
for help on using the changeset viewer.