Ticket #23497: 23497.14.diff
File 23497.14.diff, 18.3 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
2137 2137 function wp_ajax_revisions_data() { 2138 2138 check_ajax_referer( 'revisions-ajax-nonce', 'nonce' ); 2139 2139 2140 $compare to = isset( $_GET['compareto'] ) ? absint( $_GET['compareto'] ) : 0;2141 $show autosaves = isset( $_GET['showautosaves'] ) ? $_GET['showautosaves'] : '';2142 $show splitview = isset( $_GET['showsplitview'] ) ? $_GET['showsplitview'] : '';2143 $post id = isset( $_GET['post_id'] ) ? absint( $_GET['post_id'] ) : '';2140 $compare_to = isset( $_GET['compare_to'] ) ? absint( $_GET['compare_to'] ) : 0; 2141 $show_autosaves = isset( $_GET['show_autosaves'] ) ? $_GET['show_autosaves'] : ''; 2142 $show_split_view = isset( $_GET['show_split_view'] ) ? $_GET['show_split_view'] : ''; 2143 $post_id = isset( $_GET['post_id'] ) ? absint( $_GET['post_id'] ) : ''; 2144 2144 2145 $compare twomode = ( '' == $postid ) ? false : true;2145 $compare_two_mode = ( '' == $post_id ) ? false : true; 2146 2146 // 2147 //TODO: currently code returns all possible comparisons for the indicated 'compare to' revision2147 //TODO: currently code returns all possible comparisons for the indicated 'compare_to' revision 2148 2148 //however, the front end prevents users from pulling the right handle past the left or the left pass the right, 2149 2149 //so only the possible diffs need be generated 2150 2150 // 2151 2151 $alltherevisions = array(); 2152 if ( '' == $post id )2153 $post id = $compareto;2152 if ( '' == $post_id ) 2153 $post_id = $compare_to; 2154 2154 2155 if ( ! current_user_can( 'read_post', $post id ) )2155 if ( ! current_user_can( 'read_post', $post_id ) ) 2156 2156 continue; 2157 2157 2158 if ( ! $revisions = wp_get_post_revisions( $post id ) )2158 if ( ! $revisions = wp_get_post_revisions( $post_id ) ) 2159 2159 return; 2160 2160 2161 2161 2162 2162 //if we are comparing two revisions, the first 'revision' represented by the leftmost 2163 2163 //slider position is the current revision, prepend a comparison to this revision 2164 if ( $compare twomode )2165 array_unshift( $revisions, get_post( $post id ) );2164 if ( $compare_two_mode ) 2165 array_unshift( $revisions, get_post( $post_id ) ); 2166 2166 2167 2167 $count = 1; 2168 2168 foreach ( $revisions as $revision ) : 2169 if ( 'true' != $showautosaves&& wp_is_post_autosave( $revision ) )2169 if ( ! empty( $show_autosaves ) && wp_is_post_autosave( $revision ) ) 2170 2170 continue; 2171 2171 2172 2172 $revision_from_date_author = ''; 2173 2173 2174 2174 2175 $left_revision = get_post( $compare to );2175 $left_revision = get_post( $compare_to ); 2176 2176 $right_revision = get_post( $revision ); 2177 2177 2178 2178 $author = get_the_author_meta( 'display_name', $revision->post_author ); … … 2191 2191 $date 2192 2192 ); 2193 2193 2194 if ( $compare twomode ) {2195 $compare to_gravatar = get_avatar( $left_revision->post_author, 18 );2196 $compare to_author = get_the_author_meta( 'display_name', $left_revision->post_author );2197 $compare to_date = date_i18n( $datef, strtotime( $left_revision->post_modified ) );2194 if ( $compare_two_mode ) { 2195 $compare_to_gravatar = get_avatar( $left_revision->post_author, 18 ); 2196 $compare_to_author = get_the_author_meta( 'display_name', $left_revision->post_author ); 2197 $compare_to_date = date_i18n( $datef, strtotime( $left_revision->post_modified ) ); 2198 2198 2199 2199 $revision_from_date_author = sprintf( 2200 2200 '%s %s, %s %s (%s)', 2201 $compare to_gravatar,2202 $compare to_author,2201 $compare_to_gravatar, 2202 $compare_to_author, 2203 2203 human_time_diff( strtotime( $left_revision->post_modified ), current_time( 'timestamp' ) ), 2204 2204 __( ' ago ' ), 2205 $compare to_date2205 $compare_to_date 2206 2206 ); 2207 2207 } 2208 2208 … … 2212 2212 'action' => 'restore' ), 2213 2213 '/wp-admin/revision.php' 2214 2214 ), 2215 "restore-post_{$compare to}|{$revision->ID}"2215 "restore-post_{$compare_to}|{$revision->ID}" 2216 2216 ); 2217 2217 2218 2218 // … … 2236 2236 2237 2237 $args = array(); 2238 2238 2239 if ( 'true' == $showsplitview)2240 $args = array( 'show splitview' => 'true');2239 if ( ! empty( $show_split_view ) ) 2240 $args = array( 'show_split_view' => true ); 2241 2241 2242 2242 $content .= wp_text_diff( $left_content, $right_content, $args ); 2243 2243 } … … 2245 2245 //if we are comparing two revisions 2246 2246 //and we are on the matching revision 2247 2247 //add an error revision indicating unable to compare to self 2248 if ( $compare twomode && $compareto == $revision->ID )2248 if ( $compare_two_mode && $compare_to == $revision->ID ) 2249 2249 $alltherevisions[] = array ( 2250 2250 'ID' => $revision->ID, 2251 2251 'revision_date_author' => $revision_date_author, -
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 35 left_model_loading : false, //keep track of model loads 36 36 right_model_loading : false, //disallow slider interaction, also repeat loads, while loading … … 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 … … 111 111 if ( 0 == self._left_diff ) { 112 112 self._right_handle_revisions.url = 113 113 ajaxurl + 114 '?action=revisions-data&compare to=' + wpRevisionsSettings.post_id +114 '?action=revisions-data&compare_to=' + wpRevisionsSettings.post_id + 115 115 '&post_id=' + wpRevisionsSettings.post_id + 116 '&show autosaves=' + self._autosaves +117 '&show splitview=' + self._showsplitview +116 '&show_autosaves=' + self._autosaves + 117 '&show_split_view=' + self._show_split_view + 118 118 '&nonce=' + wpRevisionsSettings.nonce; 119 119 } else { 120 120 self._right_handle_revisions.url = 121 121 ajaxurl + 122 '?action=revisions-data&compare to=' + self._revisions.at( self._left_diff - 1 ).get( 'ID' ) +122 '?action=revisions-data&compare_to=' + self._revisions.at( self._left_diff - 1 ).get( 'ID' ) + 123 123 '&post_id=' + wpRevisionsSettings.post_id + 124 '&show autosaves=' + self._autosaves +125 '&show splitview=' + self._showsplitview +124 '&show_autosaves=' + self._autosaves + 125 '&show_split_view=' + self._show_split_view + 126 126 '&nonce=' + wpRevisionsSettings.nonce; 127 127 } 128 128 129 129 self._left_handle_revisions.url = 130 130 ajaxurl + 131 '?action=revisions-data&compare to=' + self._revisions.at( self._right_diff - 1 ).get( 'ID' ) +131 '?action=revisions-data&compare_to=' + self._revisions.at( self._right_diff - 1 ).get( 'ID' ) + 132 132 '&post_id=' + wpRevisionsSettings.post_id + 133 '&show autosaves=' + self._autosaves +134 '&show splitview=' + self._showsplitview +133 '&show_autosaves=' + self._autosaves + 134 '&show_split_view=' + self._show_split_view + 135 135 '&nonce=' + wpRevisionsSettings.nonce; 136 136 137 137 self._left_handle_revisions.fetch({ 138 138 139 /* 140 //TODO - add a load progress bar for fetch 141 // 139 142 xhr: function() { 140 143 var xhr = $.ajaxSettings.xhr(); 141 144 xhr.onprogress = self.handleProgress; … … 149 152 window.console && console.log( Math.round( percentComplete * 100) + "%" ); 150 153 } 151 154 }, 152 155 */ 153 156 success : function(){ 154 157 self.stop_left_model_loading(); 155 158 }, … … 166 169 self.stop_right_model_loading(); 167 170 }, 168 171 169 error : function ( ) {170 window.console && console.log( 'Error loading revision data ');172 error : function ( response ) { 173 window.console && console.log( 'Error loading revision data - ' + response.toSource() ); 171 174 self.stop_right_model_loading(); 172 175 } 173 176 }); … … 217 220 218 221 wp.revisions.Collection = Backbone.Collection.extend({ 219 222 model : wp.revisions.Model, 220 url : ajaxurl + '?action=revisions-data&compare to=' + wpRevisionsSettings.post_id + '&showautosaves=false&showsplitview=true&nonce=' + wpRevisionsSettings.nonce223 url : ajaxurl + '?action=revisions-data&compare_to=' + wpRevisionsSettings.post_id + '&show_autosaves=false&show_split_view=true&nonce=' + wpRevisionsSettings.nonce 221 224 }); 222 225 223 226 _.extend(wp.revisions.views, { … … 264 267 this.comparetwochecked = ''; 265 268 if ( this.model.at( REVAPP._right_diff - 1 ) ) { 266 269 addhtml = this.template( _.extend( 267 this.model.at( REVAPP._right_diff -1 ).toJSON(),270 this.model.at( REVAPP._right_diff - 1 ).toJSON(), 268 271 { comparetwochecked : this.comparetwochecked } //keep the checkmark checked 269 272 ) ); 270 273 } … … 345 348 var self = this; 346 349 347 350 if ( $( 'input#showsplitview' ).is( ':checked' ) ) { 348 REVAPP._show splitview = 'true';351 REVAPP._show_split_view = 'true'; 349 352 $('.revisiondiffcontainer').addClass('diffsplit'); 350 353 } else { 351 REVAPP._show splitview = '';354 REVAPP._show_split_view = ''; 352 355 $('.revisiondiffcontainer').removeClass('diffsplit'); 353 356 } 354 357 … … 364 367 tagName : 'revisionvinteract', 365 368 className : 'revisionvinteract-container', 366 369 template : wp.template('revisionvinteract'), 370 _restoreword : '', 367 371 368 372 initialize : function() { 373 this._restoreword = $( 'input#restore' ).attr( 'value' ); 369 374 }, 370 375 376 reset_restore_button : function() { 377 $( 'input#restore' ).attr( 'value', this._restoreword + ' ' + REVAPP._revisions.at( REVAPP._right_diff - 1 ).get( 'ID' ) ); 378 }, 379 371 380 render : function() { 372 381 var self = this; 373 382 … … 376 385 $( '#diff_max, #diff_maxof' ).html( this.model.length ); 377 386 $( '#diff_count' ).html( REVAPP._right_diff ); 378 387 $( '#diff_left_count_inner' ).html( 0 == REVAPP._left_diff ? '' : 'revision' + REVAPP._left_diff ); 388 self.reset_restore_button(); 379 389 380 390 var modelcount = REVAPP._revisions.length; 381 391 382 slider = $( "#slider");392 slider = $( "#slider" ); 383 393 if ( 1 == REVAPP._compareoneortwo ) { 384 394 //set up the slider with a single handle 385 395 slider.slider({ … … 396 406 REVAPP._right_diff =( ui.value+1 ); 397 407 $( '#diff_count' ).html( REVAPP._right_diff ); 398 408 REVAPP._revisionView.render(); 409 self.reset_restore_button(); 399 410 } 400 411 }); 401 412 $( '.revisiondiffcontainer' ).removeClass( 'comparetwo' ); … … 473 484 } 474 485 475 486 REVAPP._revisionView.render(); //render the diff view 487 self.reset_restore_button(); 476 488 }, 477 489 478 490 //when the user stops sliding in 2 handle mode, recalculate diffs … … 480 492 if ( 2 == REVAPP._compareoneortwo ) { 481 493 //calculate and generate a diff for comparing to the left handle 482 494 //and the right handle, swap out when dragging 483 if ( ! (REVAPP.left_model_loading && REVAPP.right_model .loading ) ) {495 if ( ! (REVAPP.left_model_loading && REVAPP.right_model_loading ) ) { 484 496 REVAPP.reloadleftright(); 485 497 } 486 498 } … … 507 519 508 520 $( '#diff_count' ).html( REVAPP._right_diff ); 509 521 $( '#slider' ).slider( 'value', REVAPP._right_diff - 1 ).trigger( 'slide' ); 522 this.reset_restore_button(); 510 523 }, 511 524 512 525 //go the the previous revision … … 518 531 519 532 $( '#diff_count' ).html( REVAPP._right_diff ); 520 533 $( '#slider' ).slider( 'value', REVAPP._right_diff - 1 ).trigger( 'slide' ); 534 this.reset_restore_button(); 521 535 } 522 536 }) 523 537 }); -
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'; … … 84 92 <script type="text/javascript"> 85 93 var wpRevisionsSettings = <?php echo json_encode( array( 'post_id' => $post->ID, 'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ) ) ); ?>; 86 94 </script> 95 <?php 96 $comparetworevisionslink = get_edit_post_link( $revision->ID ); 97 ?> 87 98 88 99 <div id="backbonerevisionsoptions"></div> 89 90 <br class="clear"/>91 100 <div class="wrap"> 92 101 <div class="icon32 icon32-posts-post" id="icon-edit"><br></div> 93 102 <div class="revisiondiffcontainer diffsplit currentversion rightmodelloading"> … … 95 104 <h2 class="long-header"><?php echo $h2; ?></h2> 96 105 <div id="backbonerevisionsinteract"></div> 97 106 <div id="backbonerevisionsdiff"></div> 98 <hr /> 99 <?php 100 $comparetworevisionslink = get_edit_post_link( $revision->ID ); 101 ?> 107 <hr /> 102 108 </div> 103 109 </div> 104 110 … … 108 114 <div id="difftitlefrom">{{{ data.revision_from_date_author }}} <?php _e( '- compared to -' ); ?></div> 109 115 <div id="difftitle">{{{ data.revision_date_author }}}</div> 110 116 <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> 111 <div id="diffrestore"><input class="button button-primary" onClick="document.location='{{{ data.restoreaction }}}'" type="submit" id="restore" value="<?php esc_attr_e( 'Restore ' )?>" /></div>117 <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> 112 118 <div id="comparetworevisions"><input type="checkbox" id="comparetwo" value="comparetwo" {{{ data.comparetwochecked }}} name="comparetwo"/> <?php esc_attr_e( 'Compare two revisions' )?></div> 113 119 </div> 114 120 <div id="removedandadded"> … … 120 126 121 127 <script id="tmpl-revisionvinteract" type="text/html"> 122 128 <div id="diffheader"> 123 <div id="diffprevious"><input class="button" type="submit" id="previous" value=" Previous" /></div>124 <div id="diffnext"><input class="button" type="submit" id="next" value=" Next" /></div>129 <div id="diffprevious"><input class="button" type="submit" id="previous" value="<?php esc_attr_e( 'Previous' ); ?>" /></div> 130 <div id="diffnext"><input class="button" type="submit" id="next" value="<?php esc_attr_e( 'Next' ); ?>" /></div> 125 131 <div id="diffslider"> 126 132 <div id="revisioncount"> 127 133 <?php _e( 'Comparing' ); ?>