Ticket #24056: 24056-combined.patch
File 24056-combined.patch, 16.8 KB (added by , 11 years ago) |
---|
-
wp-admin/css/wp-admin.css
3641 3641 display: block; 3642 3642 } 3643 3643 3644 #diff-paginate { 3645 text-align: center; 3646 margin: 10px 0 0 0; 3647 } 3648 3649 #diff-paginate input { 3650 margin: 0 2px; 3651 } 3652 3644 3653 #diff-title-to strong { 3645 3654 display: none; 3646 3655 } … … 3693 3702 3694 3703 .comparing-two-revisions #diff-previous-revision, 3695 3704 .comparing-two-revisions #diff-next-revision, 3705 .comparing-two-revisions .button.paginate, 3696 3706 #diff-header-from { 3697 3707 display: none; 3698 3708 } -
wp-admin/includes/ajax-actions.php
2112 2112 $right_handle_at = ! empty( $_GET['right_handle_at'] ) ? (int) $_GET['right_handle_at'] : 0; 2113 2113 $left_handle_at = ! empty( $_GET['left_handle_at'] ) ? (int) $_GET['left_handle_at'] : 0; 2114 2114 $single_revision_id = ! empty( $_GET['single_revision_id'] ) ? absint( $_GET['single_revision_id'] ) : 0; 2115 $page_size = ! empty( $_GET['page_size'] ) ? absint( $_GET['page_size'] ) : -1; 2116 $pages = ! empty( $_GET['pages'] ) ? absint( $_GET['pages'] ) : 1; 2117 $page = ! empty( $_GET['page'] ) ? absint( $_GET['page'] ) : 1; 2115 2118 $compare_two_mode = (bool) $post_id; 2116 2119 2117 2120 $all_the_revisions = array(); 2118 if ( ! $post_id )2119 $post_id = $compare_to;2120 2121 2121 2122 if ( ! current_user_can( 'read_post', $post_id ) ) 2122 2123 continue; 2123 2124 2124 if ( ! $revisions = wp_get_post_revisions( $post_id ) )2125 if ( ! $revisions = wp_get_post_revisions( $post_id, array( 'posts_per_page' => $page_size, 'paged' => $page ) ) ) 2125 2126 return; 2126 2127 2127 2128 $left_revision = get_post( $compare_to ); … … 2186 2187 // reverse the list to start with oldest revision 2187 2188 $revisions = array_reverse( $revisions ); 2188 2189 2189 $previous_revision_id = 0; 2190 if ( $page < $pages ) { // not on last page 2191 $previous = array_pop( wp_get_post_revisions( $post_id, array( 'posts_per_page' => $page_size, 'paged' => $page, 'order' => 'ASC', 'numberposts' => 1 ) ) ); 2192 $previous_revision_id = $previous->ID; 2193 } else { 2194 $previous_revision_id = 0; 2195 } 2190 2196 2191 2197 /* translators: revision date format, see http://php.net/date */ 2192 2198 $datef = _x( 'j F, Y @ G:i:s', 'revision date format'); … … 2209 2215 ( 0 != $right_handle_at && $count > ( $right_handle_at - 2 ) ) ) ) { 2210 2216 $all_the_revisions[] = array ( 2211 2217 'ID' => $revision->ID, 2218 'timestamp' => strtotime($revision->post_modified), 2212 2219 ); 2213 2220 continue; 2214 2221 } … … 2217 2224 ( 0 != $left_handle_at && $count < $right_handle_at ) ) ) { 2218 2225 $all_the_revisions[] = array ( 2219 2226 'ID' => $revision->ID, 2227 'timestamp' => strtotime($revision->post_modified), 2220 2228 ); 2221 2229 continue; 2222 2230 } … … 2305 2313 'restoreLink' => urldecode( $restore_link ), 2306 2314 'previousID' => $previous_revision_id, 2307 2315 'isCurrent' => $is_current_revision, 2316 'timestamp' => strtotime($revision->post_modified), 2308 2317 ); 2309 2318 } 2310 2319 $previous_revision_id = $revision->ID; -
wp-admin/js/revisions.js
41 41 42 42 constructor: function() { 43 43 var self = this; 44 this.page = parseInt( revisions.model.settings.page ); 44 45 this.slider = new revisions.view.Slider(); 45 46 46 47 if ( null === this.revisions ) { … … 62 63 delay = 0, 63 64 totalChanges; 64 65 65 // match slider to passed revision_id 66 _.each( revisionsToLoad, function( revision ) { 67 if ( revision.get( 'ID' ) == revisions.model.settings.revision_id ) 68 self.rightDiff = self.revisions.indexOf( revision ) + 1; 66 // match slider to passed revision_id when on initial page 67 if ( self.revisionsInteractions == null ) { 68 _.each( revisionsToLoad, function( revision ) { 69 if ( revision.get( 'ID' ) == revisions.model.settings.revision_id ) 70 self.rightDiff = self.revisions.indexOf( revision ) + 1; 71 }); 72 } 73 74 // order revisions in their chronological closeness to the handle(s) 75 var left = self.singleRevision ? 0 : self.revisions.at( self.leftDiff - 1 ).get( 'timestamp' ), 76 right = self.revisions.at( self.rightDiff - 1 ).get( 'timestamp' ); 77 revisionsToLoad = _.sortBy( revisionsToLoad, function( model ) { 78 var t = model.get( 'timestamp' ), 79 y = Math.abs( t - right ), 80 x = Math.abs( t - left ); 81 return _.min( [x, y] ); 69 82 }); 70 83 71 84 _.each( revisionsToLoad, function( revision ) { … … 142 155 }, 143 156 144 157 // load the models for the single handle mode 145 reloadModelSingle: function( ) {158 reloadModelSingle: function( pageChange ) { 146 159 var self = this; 147 160 148 161 self.startRightModelLoading(); 162 self.revisionsInteractions.buttonsDisable(); 163 self.slider.disable(); 149 164 150 165 self.revisions.reload({ 151 166 options: { 152 'showAutosaves': self.autosaves,153 'showSplitView': self.showSplitView167 'showAutosaves': self.autosaves, 168 'showSplitView': self.showSplitView 154 169 }, 155 170 156 171 success: function() { 157 var revisionCount = self.revisions.length; 172 var revisionCount = self.revisions.length, 173 pos = self.rightDiff; 174 175 if ( pageChange !== 'undefined' ) 176 pos = ( pageChange == 'left' ) ? revisionCount : 1; 177 self.rightDiff = pos; 178 179 self.slider.refresh({ 180 'max': revisionCount - 1, // slider starts at 0 in single handle mode 181 'value': pos - 1 // slider starts at 0 in single handle mode 182 }, true); 158 183 self.revisionView.model = self.revisions; 159 184 self.revisionView.render(); 160 185 self.loadDiffs( self.revisions ); 161 186 self.tickmarkView.model = self.revisions; 162 187 self.tickmarkView.render(); 163 self.slider.refresh({ 164 'max': revisionCount - 1, // slider starts at 0 in single handle mode 165 'value': self.rightDiff - 1 // slider starts at 0 in single handle mode 166 }, true); 188 189 self.revisionsInteractions.buttonsEnable(); 190 self.slider.enable(); 167 191 }, 168 192 169 193 error: function() { 170 194 self.stopRightModelLoading(); 195 self.revisionsInteractions.buttonsEnable(); 196 self.slider.enable(); 171 197 } 172 198 }); 173 199 }, … … 234 260 * reloadLeftRight reload models for both the left and right handles 235 261 */ 236 262 reloadLeftRight: function() { 237 this.startRightModelLoading();238 this.startLeftModelLoading();239 263 this.reloadLeft(); 240 264 this.reloadRight(); 241 265 }, … … 245 269 next = ! isRtl ? $( '#next' ) : $( '#previous' ), 246 270 prev = ! isRtl ? $( '#previous' ) : $( '#next' ); 247 271 248 // Disable "Next" button if you're on the last node 249 if ( maxVal === val )272 // Disable "Next" button if you're on the last node and first page 273 if ( maxVal === val && Diff.page == 1 ) 250 274 next.prop( 'disabled', true ); 251 275 else 252 276 next.prop( 'disabled', false ); 253 277 254 // Disable "Previous" button if you're on the 0 node 255 if ( 0 === val )278 // Disable "Previous" button if you're on the 0 node and last page 279 if ( 0 === val && Diff.page == revisions.model.settings.pages ) 256 280 prev.prop( 'disabled', true ); 257 281 else 258 282 prev.prop( 'disabled', false ); … … 430 454 return $( '#diff-slider' ).slider( 'option', key ); 431 455 }, 432 456 457 disable: function() { 458 $( '#diff-slider' ).slider( "disable" ); 459 }, 460 461 enable: function() { 462 $( '#diff-slider' ).slider( "enable" ); 463 }, 464 433 465 render: function() { 434 466 var self = this; 435 467 // this.$el doesn't work, why? … … 453 485 el: $('#diff-slider-ticks'), 454 486 template: wp.template('revision-ticks'), 455 487 model: Revision, 488 initWidth: null, 456 489 490 initialize: function() { 491 $(window).on('resize', this, this.resize); 492 }, 493 457 494 resetTicks: function() { 495 if ( this.initWidth == null ) 496 this.initWidth = Diff.slider.width(); 497 458 498 var sliderMax, sliderWidth, adjustMax, tickWidth, tickCount = 0, aTickWidth, tickMargin, self = this, firstTick, lastTick; 459 499 sliderMax = Diff.slider.option( 'max' ); 460 sliderWidth = Diff.slider.width();500 sliderWidth = this.initWidth; 461 501 adjustMax = Diff.singleRevision ? 0 : 1; 462 502 tickWidth = Math.floor( sliderWidth / ( sliderMax - adjustMax ) ); 463 503 tickWidth = ( tickWidth > 50 ) ? 50 : tickWidth; // set minimum and maximum widths for tick marks … … 490 530 /** 491 531 * go through all ticks, add hover and click interactions 492 532 */ 533 493 534 $( '.revision-tick' ).each( function() { 494 535 Diff.slider.addTooltip ( $( this ), Diff.revisions.at( tickCount++ ).get( 'titleTooltip' ) ); 495 536 $( this ).hover( … … 539 580 } ); 540 581 }, 541 582 583 /** 584 * Readjusts the slider width depending on the containers width. 585 */ 586 resize: function( e ) { 587 e.data.initWidth = $('#revision-diff-container').width() - 200; 588 e.data.render(); 589 }, 590 542 591 // render the tick mark view 543 592 render: function() { 544 593 var self = this, addHtml; … … 553 602 } 554 603 self.resetTicks(); 555 604 return self; 556 } 557 } ); 605 }, 558 606 607 /** 608 * Overwrite backbone's default behavior to also remove the window resize event 609 */ 610 remove: function() { 611 $(window).off('resize', this.resize); 612 this.$el.remove(); 613 this.stopListening(); 614 return this; 615 } 616 }); 617 559 618 /** 560 619 * wp.revisions.view.Interact 561 620 * 562 * Next/Prev buttons and the slider621 * Next/Prev/pagination buttons and the slider 563 622 */ 564 623 revisions.view.Interact = Backbone.View.extend({ 565 624 el: $( '#revision-interact' ), … … 568 627 // next and previous buttons, only available in compare one mode 569 628 events: { 570 629 'click #next': ! isRtl ? 'nextRevision' : 'previousRevision', 571 'click #previous': ! isRtl ? 'previousRevision' : 'nextRevision' 630 'click #previous': ! isRtl ? 'previousRevision' : 'nextRevision', 631 'click .paginate': 'changePage' 572 632 }, 573 633 574 634 render: function() { … … 608 668 return this; 609 669 }, 610 670 671 buttonsEnable: function() { 672 $( "#previous, #next, .paginate:not(.disabled)" ).prop('disabled', false); 673 }, 674 675 buttonsDisable: function() { 676 $( "#previous, #next, .paginate" ).prop('disabled', true); 677 }, 678 611 679 // go to the next revision 612 680 nextRevision: function() { 613 if ( Diff.rightDiff < this.model.length ) // unless at right boundry614 Diff.rightDiff = Diff.rightDiff + 1 681 if ( Diff.rightDiff < this.model.length ) { // unless at right boundary 682 Diff.rightDiff = Diff.rightDiff + 1; 615 683 616 Diff.revisionView.render();684 Diff.revisionView.render(); 617 685 618 Diff.slider.refresh({ 619 value: Diff.rightDiff - 1 620 }, true ); 686 Diff.slider.refresh({ 687 value: Diff.rightDiff - 1 688 }, true ); 689 } else if ( Diff.page > 1 ) { // move to previous page 690 this.changePage( +Diff.page - 1 ); 691 } 621 692 }, 622 693 623 694 // go to the previous revision 624 695 previousRevision: function() { 625 if ( Diff.rightDiff > 1 ) // unless at left boundry626 Diff.rightDiff = Diff.rightDiff - 1 696 if ( Diff.rightDiff > 1 ) { // unless at left boundary 697 Diff.rightDiff = Diff.rightDiff - 1; 627 698 628 Diff.revisionView.render();699 Diff.revisionView.render(); 629 700 630 Diff.slider.refresh({ 631 value: Diff.rightDiff - 1 632 }, true ); 633 } 701 Diff.slider.refresh({ 702 value: Diff.rightDiff - 1 703 }, true ); 704 } else if ( Diff.page < revisions.model.settings.pages ) { // move to next page 705 this.changePage( +Diff.page + 1 ); 706 } 707 }, 708 709 changePage: function(arg) { 710 if ( ! Diff.slider.singleRevision ) // only in single handle mode 711 return; 712 713 var self = this; 714 715 // get page button depending on how function is called (direct or onclick) 716 var newPage = $.isNumeric(arg) ? arg : $( arg.currentTarget ).data( 'id' ), 717 oldPage = Diff.page; 718 719 Diff.page = newPage; 720 721 $( ".paginate[data-id=" + newPage + "]" ).addClass( 'disabled' ); 722 $( ".paginate[data-id=" + oldPage + "]" ).removeClass('disabled' ); 723 724 var direction = newPage > oldPage ? 'left' : 'right'; 725 Diff.reloadModelSingle( direction ); 726 } 634 727 }); 635 728 636 729 /** … … 699 792 if ( $( '#compare-two-revisions' ).is( ':checked' ) ) { // compare 2 mode 700 793 Diff.singleRevision = false ; 701 794 702 // in RTL mode handles are swapped, so boundary checks are different; 703 if ( isRtl ){ 704 Diff.leftDiff = Diff.revisions.length; // put the left handle at the rightmost position, representing current revision 795 // ensure that we are on page one 796 Diff.page = 1; 705 797 706 if ( Diff.revisions.length === Diff.rightDiff ) // make sure 'left' handle not in rightmost slot 707 Diff.rightDiff = Diff.rightDiff - 1; 708 } else { 709 if ( 1 === Diff.rightDiff ) // make sure right handle not in leftmost slot 710 Diff.rightDiff = 2; 711 } 798 // fix tickmarks 799 Diff.tickmarkView.resetTicks(); 800 Diff.revisions.reload({ 801 success: function() { 802 // in RTL mode handles are swapped, so boundary checks are different; 803 if ( isRtl ){ 804 Diff.leftDiff = Diff.revisions.length; // put the left handle at the rightmost position, representing current revision 712 805 713 Diff.revisionView.draggingLeft = false; 806 if ( Diff.revisions.length === Diff.rightDiff ) // make sure 'left' handle not in rightmost slot 807 Diff.rightDiff = Diff.rightDiff - 1; 808 } else { 809 if ( 1 === Diff.rightDiff ) // make sure right handle not in leftmost slot 810 Diff.rightDiff = 2; 811 } 714 812 715 revisions.model.settings.revision_id = ''; // reset passed revision id so switching back to one handle mode doesn't re-select revision 716 Diff.reloadLeftRight(); // load diffs for left and right handles 717 Diff.revisionView.model = Diff.rightHandleRevisions; 813 Diff.revisionView.draggingLeft = false; 718 814 815 revisions.model.settings.revision_id = ''; // reset passed revision id so switching back to one handle mode doesn't re-select revision 816 Diff.reloadLeftRight(); // load diffs for left and right handles 817 Diff.revisionView.model = Diff.rightHandleRevisions; 818 } 819 }); 820 821 719 822 } else { // compare one mode 720 823 Diff.singleRevision = true; 721 824 Diff.revisionView.draggingLeft = false; 722 Diff.reloadModelSingle(); 825 Diff.page = null; 826 Diff.revisionsInteractions.changePage( 1 ); 723 827 } 724 828 Diff.revisionsInteractions.render(); 725 829 Diff.tickmarkView.render(); … … 781 885 Revisions = revisions.Revisions = Backbone.Collection.extend({ 782 886 model: Revision, 783 887 888 // sorts the revisions ASC by 'last modified' timestamp 889 comparator: function(item) { 890 return item.get('timestamp'); 891 }, 892 784 893 initialize: function( models, options ) { 785 894 this.options = _.defaults( options || {}, { 786 895 'compareTo': revisions.model.settings.post_id, … … 789 898 'showSplitView': true, 790 899 'rightHandleAt': 0, 791 900 'leftHandleAt': 0, 901 'page_size' : revisions.model.settings.page_size, 902 'pages' : revisions.model.settings.pages, 792 903 'nonce': revisions.model.settings.nonce 793 904 }); 794 905 }, 795 906 796 907 url: function() { 908 if( _.isUndefined( Diff.page ) ) 909 Diff.page = revisions.model.settings.page; 910 797 911 return ajaxurl + 798 912 '?action=revisions-data' + 799 913 '&compare_to=' + this.options.compareTo + // revision are we comparing to … … 802 916 '&show_split_view=' + this.options.showSplitView + // show in split view or single column view 803 917 '&right_handle_at=' + this.options.rightHandleAt + // mark point for comparison list 804 918 '&left_handle_at=' + this.options.leftHandleAt + // mark point for comparison list 919 '&page_size=' + this.options.page_size + 920 '&pages=' + this.options.pages + 921 '&page=' + Diff.page + 805 922 '&nonce=' + this.options.nonce; 806 923 }, 807 924 -
wp-admin/revision.php
78 78 79 79 wp_enqueue_script( 'revisions' ); 80 80 81 $page_size = 50; 82 $revisions_idx = array_flip( array_keys( wp_get_post_revisions( $post->ID ) ) ); 81 83 82 84 $settings = array( 83 85 'post_id' => $post->ID, 84 86 'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ), 85 'revision_id' => $revision_id 87 'revision_id' => $revision_id, 88 'page' => floor( ( ( $revisions_idx[$revision_id] ) / $page_size) ) + 1, 89 'pages' => floor( count( $revisions_idx ) / $page_size ) + 1, 90 'page_size' => $page_size, 86 91 ); 87 92 88 93 wp_localize_script( 'revisions', 'wpRevisionsSettings', $settings ); … … 172 177 </div> 173 178 174 179 <div id="diff-slider" class="wp-slider"></div> 180 181 <?php if ( $settings['pages'] > 1 ) : ?> 182 <div id="diff-paginate"> 183 <?php 184 // display pages from high to low 185 for( $i = $settings['pages']; $i >= 1; $i-- ) { 186 $value = ( ( $i == $settings['pages'] ) ? count( $revisions_idx ) : $i * $page_size ); 187 $value .= '-' . (($i-1) * $page_size + 1); 188 echo "<input class='button paginate' value='$value' data-id='$i' type='button'".disabled( $i, $settings['page'], false)." />\n"; 189 } 190 ?> 191 </div> 192 <?php endif; ?> 175 193 </script> 176 194 177 195 <script id="tmpl-revision-ticks" type="text/html">