Ticket #23497: 23497.16.diff
File 23497.16.diff, 29.8 KB (added by , 12 years ago) |
---|
-
wp-includes/post-template.php
1468 1468 else : 1469 1469 echo "<ul class='post-revisions'>\n"; 1470 1470 echo $rows; 1471 if ( $restored_from_meta = get_post_meta( $post->ID, '_post_restored_from', true ) ) { 1472 $author = get_the_author_meta( 'display_name', $restored_from_meta[ 'restored_by_user' ] ); 1473 /* translators: revision date format, see http://php.net/date */ 1474 $datef = _x( 'j F, Y @ G:i:s', 'revision date format'); 1475 $date = date_i18n( $datef, strtotime( $restored_from_meta[ 'restored_time' ] ) ); 1476 $timesince = human_time_diff( $restored_from_meta[ 'restored_time' ], current_time( 'timestamp' ) ) . __( ' ago ' ); 1477 ?> 1478 <hr /> 1479 <div id="revisions-meta-restored"> 1480 <?php 1481 printf( 'Previously restored from Revision ID %d, %s by %s (%s)', 1482 $restored_from_meta[ 'restored_revision_id'], 1483 $timesince, 1484 $author, 1485 $date ); 1486 ?> 1487 </div> 1488 <?php 1471 1489 echo "</ul>"; 1490 } 1491 1472 1492 endif; 1473 1493 1474 1494 } -
wp-includes/pluggable.php
1722 1722 1723 1723 $r = "<table class='diff'>\n"; 1724 1724 1725 if ( isset( $args[ 'showsplitview' ] ) && 'true' == $args[ 'showsplitview' ]) {1725 if ( ! empty( $args[ 'show_split_view' ] ) ) { 1726 1726 $r .= "<col class='content diffsplit left' /><col class='content diffsplit middle' /><col class='content diffsplit right' />"; 1727 1727 } else { 1728 1728 $r .= "<col class='content' />"; -
wp-admin/includes/ajax-actions.php
2131 2131 function wp_ajax_revisions_data() { 2132 2132 check_ajax_referer( 'revisions-ajax-nonce', 'nonce' ); 2133 2133 2134 $compareto = isset( $_GET['compareto'] ) ? absint( $_GET['compareto'] ) : 0; 2135 $showautosaves = isset( $_GET['showautosaves'] ) ? $_GET['showautosaves'] : ''; 2136 $showsplitview = isset( $_GET['showsplitview'] ) ? $_GET['showsplitview'] : ''; 2137 $postid = isset( $_GET['post_id'] ) ? absint( $_GET['post_id'] ) : ''; 2134 $compare_to = isset( $_GET['compare_to'] ) ? absint( $_GET['compare_to'] ) : 0; 2135 $show_autosaves = isset( $_GET['show_autosaves'] ) ? $_GET['show_autosaves'] : ''; 2136 $show_split_view = isset( $_GET['show_split_view'] ) ? $_GET['show_split_view'] : ''; 2137 $post_id = isset( $_GET['post_id'] ) ? absint( $_GET['post_id'] ) : ''; 2138 $right_handle_at = isset( $_GET['right_handle_at'] ) ? $_GET['right_handle_at'] : 0; 2139 $left_handle_at = isset( $_GET['left_handle_at'] ) ? $_GET['left_handle_at'] : 0; 2138 2140 2139 $compare twomode = ( '' == $postid ) ? false : true;2141 $compare_two_mode = ( '' == $post_id ) ? false : true; 2140 2142 // 2141 //TODO: currently code returns all possible comparisons for the indicated 'compare to' revision2143 //TODO: currently code returns all possible comparisons for the indicated 'compare_to' revision 2142 2144 //however, the front end prevents users from pulling the right handle past the left or the left pass the right, 2143 2145 //so only the possible diffs need be generated 2144 2146 // 2145 2147 $alltherevisions = array(); 2146 if ( '' == $post id )2147 $post id = $compareto;2148 if ( '' == $post_id ) 2149 $post_id = $compare_to; 2148 2150 2149 if ( ! current_user_can( 'read_post', $post id ) )2151 if ( ! current_user_can( 'read_post', $post_id ) ) 2150 2152 continue; 2151 2153 2152 if ( ! $revisions = wp_get_post_revisions( $post id ) )2154 if ( ! $revisions = wp_get_post_revisions( $post_id ) ) 2153 2155 return; 2154 2156 2155 2157 2156 2158 //if we are comparing two revisions, the first 'revision' represented by the leftmost 2157 2159 //slider position is the current revision, prepend a comparison to this revision 2158 if ( $compare twomode )2159 array_unshift( $revisions, get_post( $post id ) );2160 if ( $compare_two_mode ) 2161 array_unshift( $revisions, get_post( $post_id ) ); 2160 2162 2161 $count = 1;2163 $count = -1; 2162 2164 foreach ( $revisions as $revision ) : 2163 if ( 'true' != $showautosaves && wp_is_post_autosave( $revision ) ) 2165 if ( ! empty( $show_autosaves ) && wp_is_post_autosave( $revision ) ) 2166 continue; 2167 2168 $revision_from_date_author = ''; 2169 $count++; 2170 // return blank data for diffs to the left of the left handle (for right handel model) 2171 // or to the right of the right handle (for left handel model) 2172 if ( ( 0 != $left_handle_at && $count <= $left_handle_at ) || 2173 ( 0 != $right_handle_at && $count > $right_handle_at )) { 2174 $alltherevisions[] = array ( 2175 'ID' => $revision->ID, 2176 'revision_date_author' => '', 2177 'revisiondiff' => '', 2178 'restoreaction' => '', 2179 'revision_from_date_author' => '' 2180 ); 2181 2164 2182 continue; 2183 } 2184 2165 2185 2166 $revision_from_date_author = ''; 2186 $left_revision = get_post( $compare_to ); 2187 $right_revision = get_post( $revision ); 2167 2188 2189 $author = get_the_author_meta( 'display_name', $revision->post_author ); 2190 /* translators: revision date format, see http://php.net/date */ 2191 $datef = _x( 'j F, Y @ G:i:s', 'revision date format'); 2168 2192 2169 $left_revision = get_post( $compareto ); 2170 $right_revision = get_post( $revision ); 2193 $gravatar = get_avatar( $revision->post_author, 18 ); 2171 2194 2172 $author = get_the_author_meta( 'display_name', $revision->post_author ); 2173 /* translators: revision date format, see http://php.net/date */ 2174 $datef = _x( 'j F, Y @ G:i:s', 'revision date format'); 2195 $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); 2196 $revision_date_author = sprintf( 2197 '%s %s, %s %s (%s)', 2198 $gravatar, 2199 $author, 2200 human_time_diff( strtotime( $revision->post_modified ), current_time( 'timestamp' ) ), 2201 __( ' ago ' ), 2202 $date 2203 ); 2175 2204 2176 $gravatar = get_avatar( $revision->post_author, 18 ); 2205 if ( $compare_two_mode ) { 2206 $compare_to_gravatar = get_avatar( $left_revision->post_author, 18 ); 2207 $compare_to_author = get_the_author_meta( 'display_name', $left_revision->post_author ); 2208 $compare_to_date = date_i18n( $datef, strtotime( $left_revision->post_modified ) ); 2177 2209 2178 $date = date_i18n( $datef, strtotime( $revision->post_modified ) );2179 $revision_date_author = sprintf(2180 '%s %s, %s %s (%s)',2181 $gravatar,2182 $author,2183 human_time_diff( strtotime( $revision->post_modified ), current_time( 'timestamp' )),2184 __( ' ago ' ),2185 $date2186 );2210 $revision_from_date_author = sprintf( 2211 '%s %s, %s %s (%s)', 2212 $compare_to_gravatar, 2213 $compare_to_author, 2214 human_time_diff( strtotime( $left_revision->post_modified ), current_time( 'timestamp' ) ), 2215 __( ' ago ' ), 2216 $compare_to_date 2217 ); 2218 } 2187 2219 2188 if ( $comparetwomode ) { 2189 $compareto_gravatar = get_avatar( $left_revision->post_author, 18 ); 2190 $compareto_author = get_the_author_meta( 'display_name', $left_revision->post_author ); 2191 $compareto_date = date_i18n( $datef, strtotime( $left_revision->post_modified ) ); 2192 2193 $revision_from_date_author = sprintf( 2194 '%s %s, %s %s (%s)', 2195 $compareto_gravatar, 2196 $compareto_author, 2197 human_time_diff( strtotime( $left_revision->post_modified ), current_time( 'timestamp' ) ), 2198 __( ' ago ' ), 2199 $compareto_date 2220 $restoreaction = wp_nonce_url( 2221 add_query_arg( 2222 array( 'revision' => $revision->ID, 2223 'action' => 'restore' ), 2224 '/wp-admin/revision.php' 2225 ), 2226 "restore-post_{$compare_to}|{$revision->ID}" 2200 2227 ); 2201 }2202 2228 2203 $restoreaction = wp_nonce_url(2204 add_query_arg(2205 array( 'revision' => $revision->ID,2206 'action' => 'restore' ),2207 '/wp-admin/revision.php'2208 ),2209 "restore-post_{$compareto}|{$revision->ID}"2210 );2229 // 2230 //make sure the left revision is the most recent 2231 // 2232 if ( strtotime( $right_revision->post_modified_gmt ) < strtotime( $left_revision->post_modified_gmt ) ) { 2233 $temp = $left_revision; 2234 $left_revision = $right_revision; 2235 $right_revision = $temp; 2236 } 2211 2237 2212 // 2213 //make sure the left revision is the most recent 2214 // 2215 if ( strtotime( $right_revision->post_modified_gmt ) < strtotime( $left_revision->post_modified_gmt ) ) { 2216 $temp = $left_revision; 2217 $left_revision = $right_revision; 2218 $right_revision = $temp; 2219 } 2238 // 2239 //compare from left to right, passed from application 2240 // 2241 $content=''; 2242 foreach ( array_keys( _wp_post_revision_fields() ) as $field ) { 2243 $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field, $left_revision, 'left' ); 2244 $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field, $right_revision, 'right' ); 2220 2245 2221 // 2222 //compare from left to right, passed from application 2223 // 2224 $content=''; 2225 foreach ( array_keys( _wp_post_revision_fields() ) as $field ) { 2226 $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field, $left_revision, 'left' ); 2227 $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field, $right_revision, 'right' ); 2246 add_filter( "_wp_post_revision_field_$field", 'wp_kses_post' ); 2228 2247 2229 add_filter( "_wp_post_revision_field_$field", 'wp_kses_post');2248 $args = array(); 2230 2249 2231 $args = array(); 2250 if ( ! empty( $show_split_view ) ) 2251 $args = array( 'show_split_view' => true ); 2232 2252 2233 if ( 'true' == $showsplitview )2234 $args = array( 'showsplitview' => 'true' );2253 $content .= wp_text_diff( $left_content, $right_content, $args ); 2254 } 2235 2255 2236 $content .= wp_text_diff( $left_content, $right_content, $args ); 2237 } 2256 //if we are comparing two revisions 2257 //and we are on the matching revision 2258 //add an error revision indicating unable to compare to self 2259 if ( $compare_two_mode && $compare_to == $revision->ID ) 2260 $alltherevisions[] = array ( 2261 'ID' => $revision->ID, 2262 'revision_date_author' => $revision_date_author, 2263 'revisiondiff' => sprintf('<div id="selfcomparisonerror">%s</div>', __( 'Cannot compare revision to itself' ) ), 2264 'restoreaction' => urldecode( $restoreaction ), 2265 'revision_from_date_author' => '' 2266 ); 2238 2267 2239 //if we are comparing two revisions 2240 //and we are on the matching revision 2241 //add an error revision indicating unable to compare to self 2242 if ( $comparetwomode && $compareto == $revision->ID ) 2243 $alltherevisions[] = array ( 2244 'ID' => $revision->ID, 2245 'revision_date_author' => $revision_date_author, 2246 'revisiondiff' => sprintf('<div id="selfcomparisonerror">%s</div>', __( 'Cannot compare revision to itself' ) ), 2247 'restoreaction' => urldecode( $restoreaction ), 2248 'revision_from_date_author' => '' 2249 ); 2268 //add to the return data only if there is a difference 2269 if ( '' != $content ) 2270 $alltherevisions[] = array ( 2271 'ID' => $revision->ID, 2272 'revision_date_author' => $revision_date_author, 2273 'revisiondiff' => $content, 2274 'restoreaction' => urldecode( $restoreaction ), 2275 'revision_from_date_author' => $revision_from_date_author 2276 ); 2250 2277 2251 //add to the return data only if there is a difference2252 if ( '' != $content )2253 $alltherevisions[] = array (2254 'ID' => $revision->ID,2255 'revision_date_author' => $revision_date_author,2256 'revisiondiff' => $content,2257 'restoreaction' => urldecode( $restoreaction ),2258 'revision_from_date_author' => $revision_from_date_author2259 );2260 2261 2278 endforeach; 2262 2279 2263 2280 echo json_encode( $alltherevisions ); -
wp-admin/js/revisions.js
30 30 _left_diff : 0, 31 31 _right_diff : 1, 32 32 _autosaves : false, 33 _show splitview : true,33 _show_split_view : true, 34 34 _compareoneortwo : 1, 35 left_model_loading : false, //keep track of model loads36 right_model_loading : false, //disallow slider interaction, also repeat loads, while loading35 _left_model_loading : false, //keep track of model loads 36 _right_model_loading : false, //disallow slider interaction, also repeat loads, while loading 37 37 38 38 //TODO add ability to arrive on specific revision 39 39 routes : { … … 45 45 }, 46 46 47 47 start_left_model_loading : function() { 48 this. left_model_loading = true;48 this._left_model_loading = true; 49 49 $('.revisiondiffcontainer').addClass('leftmodelloading'); 50 50 }, 51 51 52 52 stop_left_model_loading : function() { 53 this. left_model_loading = false;53 this._left_model_loading = false; 54 54 $('.revisiondiffcontainer').removeClass('leftmodelloading'); 55 55 }, 56 56 57 57 start_right_model_loading : function() { 58 this. right_model_loading = true;58 this._right_model_loading = true; 59 59 $('.revisiondiffcontainer').addClass('rightmodelloading'); 60 60 }, 61 61 62 62 stop_right_model_loading : function() { 63 this. right_model_loading = false;63 this._right_model_loading = false; 64 64 $('.revisiondiffcontainer').removeClass('rightmodelloading'); 65 65 }, 66 66 … … 74 74 75 75 reloadmodelsingle : function() { 76 76 var self = this; 77 self._revisions.url = ajaxurl + '?action=revisions-data&compare to=' + wpRevisionsSettings.post_id +78 '&show autosaves=' + self.self_autosaves +79 '&show splitview=' + REVAPP._showsplitview +77 self._revisions.url = ajaxurl + '?action=revisions-data&compare_to=' + wpRevisionsSettings.post_id + 78 '&show_autosaves=' + self._autosaves + 79 '&show_split_view=' + REVAPP._show_split_view + 80 80 '&nonce=' + wpRevisionsSettings.nonce; 81 81 self.start_right_model_loading(); 82 82 this._revisions.fetch({ //reload revision data … … 100 100 }); 101 101 }, 102 102 103 reloadleft right: function() {103 reloadleft : function() { 104 104 var self = this; 105 105 self.start_left_model_loading(); 106 self.start_right_model_loading();107 108 106 self._left_handle_revisions = new wp.revisions.Collection(); 109 self._right_handle_revisions = new wp.revisions.Collection();110 111 if ( 0 == self._left_diff ) {112 self._right_handle_revisions.url =113 ajaxurl +114 '?action=revisions-data&compareto=' + wpRevisionsSettings.post_id +115 '&post_id=' + wpRevisionsSettings.post_id +116 '&showautosaves=' + self._autosaves +117 '&showsplitview=' + self._showsplitview +118 '&nonce=' + wpRevisionsSettings.nonce;119 } else {120 self._right_handle_revisions.url =121 ajaxurl +122 '?action=revisions-data&compareto=' + self._revisions.at( self._left_diff - 1 ).get( 'ID' ) +123 '&post_id=' + wpRevisionsSettings.post_id +124 '&showautosaves=' + self._autosaves +125 '&showsplitview=' + self._showsplitview +126 '&nonce=' + wpRevisionsSettings.nonce;127 }128 129 107 self._left_handle_revisions.url = 130 108 ajaxurl + 131 '?action=revisions-data&compare to=' + self._revisions.at( self._right_diff - 1 ).get( 'ID' ) +109 '?action=revisions-data&compare_to=' + self._revisions.at( self._right_diff - 1 ).get( 'ID' ) + 132 110 '&post_id=' + wpRevisionsSettings.post_id + 133 '&showautosaves=' + self._autosaves + 134 '&showsplitview=' + self._showsplitview + 135 '&nonce=' + wpRevisionsSettings.nonce; 111 '&show_autosaves=' + self._autosaves + 112 '&show_split_view=' + self._show_split_view + 113 '&nonce=' + wpRevisionsSettings.nonce + 114 '&right_handle_at=' + (self._right_diff - 1); 136 115 137 116 self._left_handle_revisions.fetch({ 138 117 139 xhr: function() {140 var xhr = $.ajaxSettings.xhr();141 xhr.onprogress = self.handleProgress;142 return xhr;143 },144 145 handleProgress: function(evt){146 var percentComplete = 0;147 if (evt.lengthComputable) {148 percentComplete = evt.loaded / evt.total;149 window.console && console.log( Math.round( percentComplete * 100) + "%" );150 }151 },152 153 118 success : function(){ 154 119 self.stop_left_model_loading(); 155 120 }, … … 159 124 self.stop_left_model_loading(); 160 125 } 161 126 }); 127 }, 162 128 129 reloadright : function() { 130 var self = this; 131 self.start_right_model_loading(); 132 self._right_handle_revisions = new wp.revisions.Collection(); 133 if ( 0 == self._left_diff ) { 134 self._right_handle_revisions.url = 135 ajaxurl + 136 '?action=revisions-data&compare_to=' + wpRevisionsSettings.post_id + 137 '&post_id=' + wpRevisionsSettings.post_id + 138 '&show_autosaves=' + self._autosaves + 139 '&show_split_view=' + self._show_split_view + 140 '&nonce=' + wpRevisionsSettings.nonce; 141 } else { 142 self._right_handle_revisions.url = 143 ajaxurl + 144 '?action=revisions-data&compare_to=' + self._revisions.at( self._left_diff - 1 ).get( 'ID' ) + 145 '&post_id=' + wpRevisionsSettings.post_id + 146 '&show_autosaves=' + self._autosaves + 147 '&show_split_view=' + self._show_split_view + 148 '&nonce=' + wpRevisionsSettings.nonce + 149 '&left_handle_at=' + (self._left_diff ) ; 150 } 151 163 152 self._right_handle_revisions.fetch({ 164 153 165 154 success : function(){ 166 155 self.stop_right_model_loading(); 167 156 }, 168 157 169 error : function ( ) {170 window.console && console.log( 'Error loading revision data ');158 error : function ( response ) { 159 window.console && console.log( 'Error loading revision data - ' + response.toSource() ); 171 160 self.stop_right_model_loading(); 172 161 } 173 162 }); 163 174 164 }, 175 165 166 reloadleftright : function() { 167 this.reloadleft(); 168 this.reloadright(); 169 }, 170 176 171 /* 177 172 * initialize the revision application 178 173 */ … … 195 190 196 191 revisionDiffSetup : function() { 197 192 var self = this, slider; 198 199 193 this._revisionView = new wp.revisions.views.View({ 200 194 model : this._revisions 201 195 }); … … 206 200 }); 207 201 this._revisionsInteractions.render(); 208 202 203 /* 204 //Options hidden for now, moving to screen options 209 205 this._revisionsOptions = new wp.revisions.views.Options({ 210 206 model : this._revisions 211 207 }); 212 208 this._revisionsOptions.render(); 209 */ 213 210 214 211 } 215 212 }) … … 217 214 218 215 wp.revisions.Collection = Backbone.Collection.extend({ 219 216 model : wp.revisions.Model, 220 url : ajaxurl + '?action=revisions-data&compareto=' + wpRevisionsSettings.post_id + '&showautosaves=false&showsplitview=true&nonce=' + wpRevisionsSettings.nonce 217 url : ajaxurl + '?action=revisions-data&compare_to=' + wpRevisionsSettings.post_id + 218 '&show_autosaves=false&show_split_view=true&nonce=' + wpRevisionsSettings.nonce 221 219 }); 222 220 223 221 _.extend(wp.revisions.views, { … … 260 258 ) ); 261 259 } 262 260 } 263 } else { //end compare two revisions mode, eg only one slider hand el261 } else { //end compare two revisions mode, eg only one slider handle 264 262 this.comparetwochecked = ''; 265 263 if ( this.model.at( REVAPP._right_diff - 1 ) ) { 266 264 addhtml = this.template( _.extend( 267 this.model.at( REVAPP._right_diff -1 ).toJSON(),268 { comparetwochecked : this.comparetwochecked } //keep the checkmark checked265 this.model.at( REVAPP._right_diff - 1 ).toJSON(), 266 { comparetwochecked : this.comparetwochecked } //keep the checkmark unchecked 269 267 ) ); 270 268 } 271 269 } … … 345 343 var self = this; 346 344 347 345 if ( $( 'input#showsplitview' ).is( ':checked' ) ) { 348 REVAPP._show splitview = 'true';346 REVAPP._show_split_view = 'true'; 349 347 $('.revisiondiffcontainer').addClass('diffsplit'); 350 348 } else { 351 REVAPP._show splitview = '';349 REVAPP._show_split_view = ''; 352 350 $('.revisiondiffcontainer').removeClass('diffsplit'); 353 351 } 354 352 … … 364 362 tagName : 'revisionvinteract', 365 363 className : 'revisionvinteract-container', 366 364 template : wp.template('revisionvinteract'), 365 _restoreword : '', 367 366 368 367 initialize : function() { 368 this._restoreword = $( 'input#restore' ).attr( 'value' ); 369 369 }, 370 370 371 reset_restore_button : function() { 372 $( 'input#restore' ).attr( 'value', this._restoreword + ' ' + REVAPP._revisions.at( REVAPP._right_diff - 1 ).get( 'ID' ) ); 373 }, 374 371 375 render : function() { 372 376 var self = this; 373 377 … … 376 380 $( '#diff_max, #diff_maxof' ).html( this.model.length ); 377 381 $( '#diff_count' ).html( REVAPP._right_diff ); 378 382 $( '#diff_left_count_inner' ).html( 0 == REVAPP._left_diff ? '' : 'revision' + REVAPP._left_diff ); 383 self.reset_restore_button(); 379 384 380 385 var modelcount = REVAPP._revisions.length; 381 386 382 slider = $( "#slider");387 slider = $( "#slider" ); 383 388 if ( 1 == REVAPP._compareoneortwo ) { 384 389 //set up the slider with a single handle 385 390 slider.slider({ … … 390 395 391 396 //slide interactions for one handles slider 392 397 slide : function( event, ui ) { 393 if ( REVAPP. right_model_loading ) //left model stoll loading, prevent sliding left handle398 if ( REVAPP._right_model_loading ) //left model stoll loading, prevent sliding left handle 394 399 return false; 395 400 396 401 REVAPP._right_diff =( ui.value+1 ); 397 402 $( '#diff_count' ).html( REVAPP._right_diff ); 398 403 REVAPP._revisionView.render(); 404 self.reset_restore_button(); 399 405 } 400 406 }); 401 407 $( '.revisiondiffcontainer' ).removeClass( 'comparetwo' ); … … 414 420 415 421 switch ( index ) { 416 422 case 1: //left handle drag 417 if ( REVAPP. left_model_loading ) //left model stoll loading, prevent sliding left handle423 if ( REVAPP._left_model_loading ) //left model stoll loading, prevent sliding left handle 418 424 return false; 419 425 420 426 if ( REVAPP._revisionView.model !== REVAPP._left_handle_revisions && … … 422 428 REVAPP._revisionView.model = REVAPP._left_handle_revisions; 423 429 424 430 REVAPP._revisionView.draggingleft = true; 431 REVAPP._left_diff_start = ui.values[ 0 ]; 425 432 break; 426 433 427 434 case 2: //right 428 if ( REVAPP. right_model_loading ) //right model stoll loading, prevent sliding right handle435 if ( REVAPP._right_model_loading ) //right model stoll loading, prevent sliding right handle 429 436 return false; 430 437 431 438 //one extra spot at left end when comparing two … … 434 441 REVAPP._revisionView.model = REVAPP._right_handle_revisions; 435 442 436 443 REVAPP._revisionView.draggingleft = false; 437 REVAPP._right_diff = ui.values[1] - 1;444 REVAPP._right_diff_start = ui.values[ 1 ]; 438 445 break; 439 446 } 440 447 }, 441 448 442 449 //when sliding in two handled mode change appropriate value 443 450 slide : function( event, ui ) { 444 if ( ui.values[ 0] == ui.values[1] ) //prevent compare to self451 if ( ui.values[ 0 ] == ui.values[ 1 ] ) //prevent compare to self 445 452 return false; 446 453 447 454 var index = $( ui.handle ).index(); //0 (left) or 1 (right) 448 455 449 456 switch ( index ) { 450 457 case 1: //left 451 if ( REVAPP. left_model_loading ) //left model stoll loading, prevent sliding left handle458 if ( REVAPP._left_model_loading ) //left model still loading, prevent sliding left handle 452 459 return false; 453 460 454 REVAPP._left_diff = ui.values[ 0] - 1; //one extra spot at left end when comparing two461 REVAPP._left_diff = ui.values[ 0 ] - 1; //one extra spot at left end when comparing two 455 462 break; 456 463 457 464 case 2: //right 458 if ( REVAPP. right_model_loading ) //right model stoll loading, prevent sliding right handle465 if ( REVAPP._right_model_loading ) //right model still loading, prevent sliding right handle 459 466 return false; 460 467 461 REVAPP._right_diff = ui.values[ 1] - 1 ;468 REVAPP._right_diff = ui.values[ 1 ] - 1 ; 462 469 break; 463 470 } 464 471 … … 473 480 } 474 481 475 482 REVAPP._revisionView.render(); //render the diff view 483 self.reset_restore_button(); 476 484 }, 477 485 478 486 //when the user stops sliding in 2 handle mode, recalculate diffs … … 480 488 if ( 2 == REVAPP._compareoneortwo ) { 481 489 //calculate and generate a diff for comparing to the left handle 482 490 //and the right handle, swap out when dragging 483 if ( ! (REVAPP.left_model_loading && REVAPP.right_model.loading ) ) { 484 REVAPP.reloadleftright(); 491 492 var index = $( ui.handle ).index(); //0 (left) or 1 (right) 493 494 switch ( index ) { 495 case 1: //left 496 //left handle dragged & changed, reload right handle model 497 if ( ! ( REVAPP._left_diff_start == ui.values[ 0 ] || REVAPP._left_model_loading ) ) 498 REVAPP.reloadright(); 499 500 break; 501 502 case 2: //right 503 //right handle dragged & changed, reload left handle model if changed 504 if ( ! ( REVAPP._right_diff_start == ui.values[ 1 ] || REVAPP._right_model_loading ) ) 505 REVAPP.reloadleft(); 506 507 break; 485 508 } 486 509 } 487 510 } … … 507 530 508 531 $( '#diff_count' ).html( REVAPP._right_diff ); 509 532 $( '#slider' ).slider( 'value', REVAPP._right_diff - 1 ).trigger( 'slide' ); 533 this.reset_restore_button(); 510 534 }, 511 535 512 536 //go the the previous revision … … 518 542 519 543 $( '#diff_count' ).html( REVAPP._right_diff ); 520 544 $( '#slider' ).slider( 'value', REVAPP._right_diff - 1 ).trigger( 'slide' ); 545 this.reset_restore_button(); 521 546 } 522 547 }) 523 548 }); -
wp-admin/revision.php
10 10 require_once('./admin.php'); 11 11 wp_reset_vars( array( 'revision', 'action' ) ); 12 12 13 $revision_id = absint( $revision);13 $revision_id = absint( $revision ); 14 14 $redirect = 'edit.php'; 15 15 16 16 switch ( $action ) : 17 17 case 'restore' : 18 if ( ! $revision = wp_get_post_revision( $revision_id ) )18 if ( ! $revision = wp_get_post_revision( $revision_id ) ) 19 19 break; 20 if ( ! current_user_can( 'edit_post', $revision->post_parent ) )20 if ( ! current_user_can( 'edit_post', $revision->post_parent ) ) 21 21 break; 22 if ( ! $post = get_post( $revision->post_parent ) )22 if ( ! $post = get_post( $revision->post_parent ) ) 23 23 break; 24 24 25 25 // Revisions disabled and we're not looking at an autosave 26 if ( ( ! WP_POST_REVISIONS || ! post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) {26 if ( ( ! WP_POST_REVISIONS || ! post_type_supports( $post->post_type, 'revisions' ) ) && ! wp_is_post_autosave( $revision ) ) { 27 27 $redirect = 'edit.php?post_type=' . $post->post_type; 28 28 break; 29 29 } 30 30 check_admin_referer( "restore-post_{$post->ID}|{$revision->ID}" ); 31 31 32 //store revision event in post meta 33 $restore_details = array( 34 'restored_revision_id' => $revision->ID, 35 'restored_by_user' => get_current_user_id(), 36 'restored_time' => time() 37 ); 38 wp_update_post_meta( $post->ID, '_post_restored_from', $restore_details ); 39 32 40 wp_restore_post_revision( $revision->ID ); 33 41 $redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) ); 34 42 break; 35 43 case 'view' : 36 44 case 'edit' : 37 45 default : 38 if ( ! $revision = wp_get_post_revision( $revision_id ) )46 if ( ! $revision = wp_get_post_revision( $revision_id ) ) 39 47 break; 40 if ( ! $post = get_post( $revision->post_parent ) )48 if ( ! $post = get_post( $revision->post_parent ) ) 41 49 break; 42 50 43 if ( ! current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) )51 if ( ! current_user_can( 'read_post', $revision->ID ) || ! current_user_can( 'read_post', $post->ID ) ) 44 52 break; 45 53 46 54 // Revisions disabled and we're not looking at an autosave … … 59 67 endswitch; 60 68 61 69 // Empty post_type means either malformed object found, or no valid parent was found. 62 if ( ! $redirect && empty($post->post_type) )70 if ( ! $redirect && empty( $post->post_type ) ) 63 71 $redirect = 'edit.php'; 64 72 65 if ( ! empty($redirect) ) {73 if ( ! empty( $redirect ) ) { 66 74 wp_redirect( $redirect ); 67 75 exit; 68 76 } 69 77 70 78 // This is so that the correct "Edit" menu item is selected. 71 if ( ! empty($post->post_type) && 'post' != $post->post_type )79 if ( ! empty( $post->post_type ) && 'post' != $post->post_type ) 72 80 $parent_file = $submenu_file = 'edit.php?post_type=' . $post->post_type; 73 81 else 74 82 $parent_file = $submenu_file = 'edit.php'; … … 83 91 <script type="text/javascript"> 84 92 var wpRevisionsSettings = <?php echo json_encode( array( 'post_id' => $post->ID, 'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ) ) ); ?>; 85 93 </script> 94 <?php 95 $comparetworevisionslink = get_edit_post_link( $revision->ID ); 96 ?> 86 97 87 98 <div id="backbonerevisionsoptions"></div> 88 89 <br class="clear"/>90 99 <div class="wrap"> 91 100 <div class="icon32 icon32-posts-post" id="icon-edit"><br></div> 92 101 <div class="revisiondiffcontainer diffsplit currentversion rightmodelloading"> … … 94 103 <h2 class="long-header"><?php echo $h2; ?></h2> 95 104 <div id="backbonerevisionsinteract"></div> 96 105 <div id="backbonerevisionsdiff"></div> 97 <hr /> 98 <?php 99 $comparetworevisionslink = get_edit_post_link( $revision->ID ); 100 ?> 106 <hr /> 101 107 </div> 102 108 </div> 103 109 … … 107 113 <div id="difftitlefrom">{{{ data.revision_from_date_author }}} <?php _e( '- compared to -' ); ?></div> 108 114 <div id="difftitle">{{{ data.revision_date_author }}}</div> 109 115 <div id="diffcancel"><input class="button" onClick="document.location='<?php echo get_edit_post_link( $post->ID ); ?>'" type="submit" id="cancel" value="<?php esc_attr_e( 'Cancel' )?>" /></div> 110 <div id="diffrestore"><input class="button button-primary" onClick="document.location='{{{ data.restoreaction }}}'" type="submit" id="restore" value="<?php esc_attr_e( 'Restore ' )?>" /></div>116 <div id="diffrestore"><input class="button button-primary" onClick="document.location='{{{ data.restoreaction }}}'" type="submit" id="restore" value="<?php esc_attr_e( 'Restore revision ID' )?>" /></div> 111 117 <div id="comparetworevisions"><input type="checkbox" id="comparetwo" value="comparetwo" {{{ data.comparetwochecked }}} name="comparetwo"/> <?php esc_attr_e( 'Compare two revisions' )?></div> 112 118 </div> 113 119 <div id="removedandadded"> … … 119 125 120 126 <script id="tmpl-revisionvinteract" type="text/html"> 121 127 <div id="diffheader"> 122 <div id="diffprevious"><input class="button" type="submit" id="previous" value=" Previous" /></div>123 <div id="diffnext"><input class="button" type="submit" id="next" value=" Next" /></div>128 <div id="diffprevious"><input class="button" type="submit" id="previous" value="<?php esc_attr_e( 'Previous' ); ?>" /></div> 129 <div id="diffnext"><input class="button" type="submit" id="next" value="<?php esc_attr_e( 'Next' ); ?>" /></div> 124 130 <div id="diffslider"> 125 131 <div id="revisioncount"> 126 132 <?php _e( 'Comparing' ); ?>