Changeset 24664
- Timestamp:
- 07/11/2013 10:56:48 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/revision.php
r24663 r24664 62 62 } 63 63 64 function wp_prepare_revisions_for_js( $post, $selected_revision_id ) {64 function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) { 65 65 $post = get_post( $post ); 66 66 $revisions = array(); … … 99 99 } 100 100 101 // Now, grab the initial diff 102 if ( ! $from ) { // Single mode 103 $initial_revisions = array_reverse( array_keys( array_slice( $revisions, array_search( $selected_revision_id, array_keys( $revisions ) ), 2, true ) ) ); 104 $compare_two_mode = false; 105 } else { // Compare two 106 $compare_two_mode = true; 107 $initial_revisions = array( $from, $selected_revision_id ); 108 } 109 $diffs = array( array( 110 'id' => $initial_revisions[0] . ':' . $initial_revisions[1], 111 'fields' => wp_get_revision_ui_diff( $post->ID, $initial_revisions[0], $initial_revisions[1] ), 112 )); 113 101 114 return array( 102 115 'postId' => $post->ID, 103 116 'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ), 104 117 'revisionData' => array_values( $revisions ), 105 'selectedRevision' => $selected_revision_id, 118 'to' => $selected_revision_id, 119 'from' => $from, 120 'diffData' => $diffs, 121 'baseUrl' => parse_url( admin_url( 'revision.php' ), PHP_URL_PATH ), 122 'compareTwoMode' => absint( $compare_two_mode ), // Apparently booleans are not allowed 106 123 ); 107 124 } -
trunk/wp-admin/js/revisions.js
r24661 r24664 18 18 19 19 // wp_localize_script transforms top-level numbers into strings. Undo that. 20 if ( revisions.settings.selectedRevision ) 21 revisions.settings.selectedRevision = parseInt( revisions.settings.selectedRevision, 10 ); 22 20 if ( revisions.settings.to ) 21 revisions.settings.to = parseInt( revisions.settings.to, 10 ); 22 if ( revisions.settings.from ) 23 revisions.settings.from = parseInt( revisions.settings.from, 10 ); 24 25 // wp_localize_script does not allow for top-level booleans. Fix that. 26 if ( revisions.settings.compareTwoMode ) 27 revisions.settings.compareTwoMode = revisions.settings.compareTwoMode === '1'; 23 28 24 29 /** … … 41 46 this.set({ 42 47 max: this.revisions.length - 1, 43 value: this.revisions.indexOf( this.revisions.get( revisions.settings. selectedRevision) ),48 value: this.revisions.indexOf( this.revisions.get( revisions.settings.to ) ), 44 49 compareTwoMode: this.frame.get('compareTwoMode') 45 50 }); … … 315 320 316 321 revisions.model.FrameState = Backbone.Model.extend({ 322 defaults: { 323 compareTwoMode: false 324 }, 325 317 326 initialize: function( attributes, options ) { 318 327 var properties = {}; … … 323 332 this.diffs = new revisions.model.Diffs( [], { revisions: this.revisions }); 324 333 325 // Set the initial revision provided through the settings. 326 properties.to = this.revisions.get( revisions.settings.selectedRevision ); 327 properties.from = this.revisions.prev( properties.to ); 328 properties.compareTwoMode = false; 334 // Set the initial diffs collection provided through the settings 335 this.diffs.set( revisions.settings.diffData ); 336 337 // Set the initial revisions, baseUrl, and mode as provided through settings 338 properties.to = this.revisions.get( revisions.settings.to ); 339 properties.from = this.revisions.get( revisions.settings.from ) || this.revisions.prev( properties.to ); 340 properties.compareTwoMode = revisions.settings.compareTwoMode; 341 properties.baseUrl = revisions.settings.baseUrl; 329 342 this.set( properties ); 330 343 … … 332 345 // the `from` and `to` revisions accurately reflect the hash. 333 346 this.router = new revisions.Router({ model: this }); 334 Backbone.history.start(); 335 347 Backbone.history.start({ pushState: true }); 348 349 // Set up internal listeners 336 350 this.listenTo( this, 'change:from', this.changeRevisionHandler ); 337 351 this.listenTo( this, 'change:to', this.changeRevisionHandler ); … … 938 952 initialize: function( options ) { 939 953 this.model = options.model; 954 this.routes = this.getRoutes(); 940 955 941 956 // Maintain state history when dragging … … 943 958 }, 944 959 945 routes: { 946 'from/:from/to/:to': 'handleRoute', 947 'at/:to': 'handleRoute' 960 getRoutes: function() { 961 var routes = {}; 962 routes[this.baseUrl( '?from=:from&to=:to' )] = 'handleRoute'; 963 routes[this.baseUrl( '?revision=:to' )] = 'handleRoute'; 964 return routes; 965 }, 966 967 baseUrl: function( url ) { 968 return this.model.get('baseUrl') + url; 948 969 }, 949 970 … … 952 973 var to = this.model.get('to').id; 953 974 if ( this.model.get('compareTwoMode' ) ) 954 this.navigate( 'from/' + from + '/to/' + to);975 this.navigate( this.baseUrl( '?from=' + from + '&to=' + to ) ); 955 976 else 956 this.navigate( 'at/' + to);977 this.navigate( this.baseUrl( '?revision=' + to ) ); 957 978 }, 958 979 … … 965 986 a = this.model.revisions.prev( b ); 966 987 b = b ? b.id : 0; 967 a = a ? a.id : 0 988 a = a ? a.id : 0; 968 989 compareTwo = false; 969 990 } else { … … 985 1006 }); 986 1007 } 987 revisions.settings. selectedRevision= to;1008 revisions.settings.to = to; 988 1009 } 989 1010 }); -
trunk/wp-admin/revision.php
r24643 r24664 12 12 require ABSPATH . 'wp-admin/includes/revision.php'; 13 13 14 wp_reset_vars( array( 'revision', 'action' ) );14 wp_reset_vars( array( 'revision', 'action', 'from', 'to' ) ); 15 15 16 16 $revision_id = absint( $revision ); 17 $from = absint( $from ); 18 if ( ! $revision_id ) 19 $revision_id = absint( $to ); 17 20 $redirect = 'edit.php'; 18 21 … … 80 83 81 84 wp_enqueue_script( 'revisions' ); 82 wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $post, $revision_id ) );85 wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $post, $revision_id, $from ) ); 83 86 84 87 /* Revisions Help Tab */ -
trunk/wp-includes/link-template.php
r24593 r24664 898 898 return; 899 899 900 if ( 'display' == $context ) 900 if ( 'revision' === $post->post_type ) 901 $action = ''; 902 elseif ( 'display' == $context ) 901 903 $action = '&action=edit'; 902 904 else
Note: See TracChangeset
for help on using the changeset viewer.