Changeset 42343 for trunk/src/wp-admin/includes/revision.php
- Timestamp:
- 11/30/2017 11:09:33 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/revision.php
r41559 r42343 21 21 */ 22 22 function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) { 23 if ( ! $post = get_post( $post ) ) 23 if ( ! $post = get_post( $post ) ) { 24 24 return false; 25 } 25 26 26 27 if ( $compare_from ) { 27 if ( ! $compare_from = get_post( $compare_from ) ) 28 if ( ! $compare_from = get_post( $compare_from ) ) { 28 29 return false; 30 } 29 31 } else { 30 32 // If we're dealing with the first revision... … … 32 34 } 33 35 34 if ( ! $compare_to = get_post( $compare_to ) ) 36 if ( ! $compare_to = get_post( $compare_to ) ) { 35 37 return false; 38 } 36 39 37 40 // If comparing revisions, make sure we're dealing with the right post parent. 38 41 // The parent post may be a 'revision' when revisions are disabled and we're looking at autosaves. 39 if ( $compare_from && $compare_from->post_parent !== $post->ID && $compare_from->ID !== $post->ID ) 42 if ( $compare_from && $compare_from->post_parent !== $post->ID && $compare_from->ID !== $post->ID ) { 40 43 return false; 41 if ( $compare_to->post_parent !== $post->ID && $compare_to->ID !== $post->ID ) 44 } 45 if ( $compare_to->post_parent !== $post->ID && $compare_to->ID !== $post->ID ) { 42 46 return false; 47 } 43 48 44 49 if ( $compare_from && strtotime( $compare_from->post_date_gmt ) > strtotime( $compare_to->post_date_gmt ) ) { 45 $temp = $compare_from;50 $temp = $compare_from; 46 51 $compare_from = $compare_to; 47 $compare_to = $temp;52 $compare_to = $temp; 48 53 } 49 54 50 55 // Add default title if title field is empty 51 if ( $compare_from && empty( $compare_from->post_title ) ) 56 if ( $compare_from && empty( $compare_from->post_title ) ) { 52 57 $compare_from->post_title = __( '(no title)' ); 53 if ( empty( $compare_to->post_title ) ) 58 } 59 if ( empty( $compare_to->post_title ) ) { 54 60 $compare_to->post_title = __( '(no title)' ); 61 } 55 62 56 63 $return = array(); … … 77 84 78 85 $args = array( 79 'show_split_view' => true 86 'show_split_view' => true, 80 87 ); 81 88 … … 104 111 // It's a better user experience to still show the Title, even if it didn't change. 105 112 // No, you didn't see this. 106 $diff = '<table class="diff"><colgroup><col class="content diffsplit left"><col class="content diffsplit middle"><col class="content diffsplit right"></colgroup><tbody><tr>';113 $diff = '<table class="diff"><colgroup><col class="content diffsplit left"><col class="content diffsplit middle"><col class="content diffsplit right"></colgroup><tbody><tr>'; 107 114 $diff .= '<td>' . esc_html( $compare_from->post_title ) . '</td><td></td><td>' . esc_html( $compare_to->post_title ) . '</td>'; 108 115 $diff .= '</tr></tbody>'; … … 112 119 if ( $diff ) { 113 120 $return[] = array( 114 'id' => $field,121 'id' => $field, 115 122 'name' => $name, 116 123 'diff' => $diff, … … 144 151 */ 145 152 function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) { 146 $post = get_post( $post );153 $post = get_post( $post ); 147 154 $authors = array(); 148 155 $now_gmt = time(); 149 156 150 $revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC', 'check_enabled' => false ) ); 157 $revisions = wp_get_post_revisions( 158 $post->ID, array( 159 'order' => 'ASC', 160 'check_enabled' => false, 161 ) 162 ); 151 163 // If revisions are disabled, we only want autosaves and the current post. 152 164 if ( ! wp_revisions_enabled( $post ) ) { 153 165 foreach ( $revisions as $revision_id => $revision ) { 154 if ( ! wp_is_post_autosave( $revision ) ) 166 if ( ! wp_is_post_autosave( $revision ) ) { 155 167 unset( $revisions[ $revision_id ] ); 168 } 156 169 } 157 170 $revisions = array( $post->ID => $post ) + $revisions; … … 163 176 164 177 $can_restore = current_user_can( 'edit_post', $post->ID ); 165 $current_id = false;178 $current_id = false; 166 179 167 180 foreach ( $revisions as $revision ) { 168 $modified = strtotime( $revision->post_modified );181 $modified = strtotime( $revision->post_modified ); 169 182 $modified_gmt = strtotime( $revision->post_modified_gmt . ' +0000' ); 170 183 if ( $can_restore ) { 171 $restore_link = str_replace( '&', '&', wp_nonce_url( 172 add_query_arg( 173 array( 'revision' => $revision->ID, 174 'action' => 'restore' ), 184 $restore_link = str_replace( 185 '&', '&', wp_nonce_url( 186 add_query_arg( 187 array( 188 'revision' => $revision->ID, 189 'action' => 'restore', 190 ), 175 191 admin_url( 'revision.php' ) 176 ), 177 "restore-post_{$revision->ID}" 178 ) ); 192 ), 193 "restore-post_{$revision->ID}" 194 ) 195 ); 179 196 } 180 197 181 198 if ( ! isset( $authors[ $revision->post_author ] ) ) { 182 199 $authors[ $revision->post_author ] = array( 183 'id' => (int) $revision->post_author,200 'id' => (int) $revision->post_author, 184 201 'avatar' => $show_avatars ? get_avatar( $revision->post_author, 32 ) : '', 185 'name' => get_the_author_meta( 'display_name', $revision->post_author ),202 'name' => get_the_author_meta( 'display_name', $revision->post_author ), 186 203 ); 187 204 } 188 205 189 206 $autosave = (bool) wp_is_post_autosave( $revision ); 190 $current = ! $autosave && $revision->post_modified_gmt === $post->post_modified_gmt;207 $current = ! $autosave && $revision->post_modified_gmt === $post->post_modified_gmt; 191 208 if ( $current && ! empty( $current_id ) ) { 192 209 // If multiple revisions have the same post_modified_gmt, highest ID is current. 193 210 if ( $current_id < $revision->ID ) { 194 211 $revisions[ $current_id ]['current'] = false; 195 $current_id = $revision->ID;212 $current_id = $revision->ID; 196 213 } else { 197 214 $current = false; … … 254 271 'restoreUrl' => false, 255 272 ); 256 $current_id = $post->ID;273 $current_id = $post->ID; 257 274 } 258 275 … … 289 306 $from = absint( $from ); 290 307 291 $diffs = array( array( 292 'id' => $from . ':' . $selected_revision_id, 293 'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ), 294 )); 308 $diffs = array( 309 array( 310 'id' => $from . ':' . $selected_revision_id, 311 'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ), 312 ), 313 ); 295 314 296 315 return array( 297 'postId' 298 'nonce' 299 'revisionData' 300 'to' 301 'from' 302 'diffData' 303 'baseUrl' 304 'compareTwoMode' 305 'revisionIds' 316 'postId' => $post->ID, 317 'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ), 318 'revisionData' => array_values( $revisions ), 319 'to' => $selected_revision_id, 320 'from' => $from, 321 'diffData' => $diffs, 322 'baseUrl' => parse_url( admin_url( 'revision.php' ), PHP_URL_PATH ), 323 'compareTwoMode' => absint( $compare_two_mode ), // Apparently booleans are not allowed 324 'revisionIds' => array_keys( $revisions ), 306 325 ); 307 326 } … … 358 377 <div class="author-info"> 359 378 <# if ( data.attributes.autosave ) { #> 360 <span class="byline"><?php printf( __( 'Autosave by %s' ), 361 '<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span> 379 <span class="byline"> 380 <?php 381 printf( 382 __( 'Autosave by %s' ), 383 '<span class="author-name">{{ data.attributes.author.name }}</span>' 384 ); 385 ?> 386 </span> 362 387 <# } else if ( data.attributes.current ) { #> 363 <span class="byline"><?php printf( __( 'Current Revision by %s' ), 364 '<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span> 388 <span class="byline"> 389 <?php 390 printf( 391 __( 'Current Revision by %s' ), 392 '<span class="author-name">{{ data.attributes.author.name }}</span>' 393 ); 394 ?> 395 </span> 365 396 <# } else { #> 366 <span class="byline"><?php printf( __( 'Revision by %s' ), 367 '<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span> 397 <span class="byline"> 398 <?php 399 printf( 400 __( 'Revision by %s' ), 401 '<span class="author-name">{{ data.attributes.author.name }}</span>' 402 ); 403 ?> 404 </span> 368 405 <# } #> 369 406 <span class="time-ago">{{ data.attributes.timeAgo }}</span> … … 400 437 <# }); #> 401 438 </div> 402 </script><?php 439 </script> 440 <?php 403 441 }
Note: See TracChangeset
for help on using the changeset viewer.