Make WordPress Core

Changeset 24664


Ignore:
Timestamp:
07/11/2013 10:56:48 PM (13 years ago)
Author:
markjaquith
Message:

Revisions: real URLs and preloading of the requested diff.

  • Real URLs are being used now, using pushState. ?revision={id} or ?from={from}&to={to}.
  • Drop the redundant action=edit from the URLs (this is the default).
  • The initial comparison is preloaded, whether a single revision or a compare-two situation.

See #24425.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/revision.php

    r24663 r24664  
    6262}
    6363
    64 function wp_prepare_revisions_for_js( $post, $selected_revision_id ) {
     64function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) {
    6565        $post = get_post( $post );
    6666        $revisions = array();
     
    9999        }
    100100
     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
    101114        return array(
    102115                'postId'           => $post->ID,
    103116                'nonce'            => wp_create_nonce( 'revisions-ajax-nonce' ),
    104117                '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
    106123        );
    107124}
  • trunk/wp-admin/js/revisions.js

    r24661 r24664  
    1818
    1919        // 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';
    2328
    2429        /**
     
    4146                        this.set({
    4247                                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 ) ),
    4449                                compareTwoMode: this.frame.get('compareTwoMode')
    4550                        });
     
    315320
    316321        revisions.model.FrameState = Backbone.Model.extend({
     322                defaults: {
     323                        compareTwoMode: false
     324                },
     325
    317326                initialize: function( attributes, options ) {
    318327                        var properties = {};
     
    323332                        this.diffs = new revisions.model.Diffs( [], { revisions: this.revisions });
    324333
    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;
    329342                        this.set( properties );
    330343
     
    332345                        // the `from` and `to` revisions accurately reflect the hash.
    333346                        this.router = new revisions.Router({ model: this });
    334                         Backbone.history.start();
    335 
     347                        Backbone.history.start({ pushState: true });
     348
     349                        // Set up internal listeners
    336350                        this.listenTo( this, 'change:from', this.changeRevisionHandler );
    337351                        this.listenTo( this, 'change:to', this.changeRevisionHandler );
     
    938952                initialize: function( options ) {
    939953                        this.model = options.model;
     954                        this.routes = this.getRoutes();
    940955
    941956                        // Maintain state history when dragging
     
    943958                },
    944959
    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;
    948969                },
    949970
     
    952973                        var to = this.model.get('to').id;
    953974                        if ( this.model.get('compareTwoMode' ) )
    954                                 this.navigate( 'from/' + from + '/to/' + to );
     975                                this.navigate( this.baseUrl( '?from=' + from + '&to=' + to ) );
    955976                        else
    956                                 this.navigate( 'at/' + to );
     977                                this.navigate( this.baseUrl( '?revision=' + to ) );
    957978                },
    958979
     
    965986                                a = this.model.revisions.prev( b );
    966987                                b = b ? b.id : 0;
    967                                 a = a ? a.id : 0
     988                                a = a ? a.id : 0;
    968989                                compareTwo = false;
    969990                        } else {
     
    9851006                                });
    9861007                        }
    987                         revisions.settings.selectedRevision = to;
     1008                        revisions.settings.to = to;
    9881009                }
    9891010        });
  • trunk/wp-admin/revision.php

    r24643 r24664  
    1212require ABSPATH . 'wp-admin/includes/revision.php';
    1313
    14 wp_reset_vars( array( 'revision', 'action' ) );
     14wp_reset_vars( array( 'revision', 'action', 'from', 'to' ) );
    1515
    1616$revision_id = absint( $revision );
     17$from = absint( $from );
     18if ( ! $revision_id )
     19        $revision_id = absint( $to );
    1720$redirect = 'edit.php';
    1821
     
    8083
    8184wp_enqueue_script( 'revisions' );
    82 wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $post, $revision_id ) );
     85wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $post, $revision_id, $from ) );
    8386
    8487/* Revisions Help Tab */
  • trunk/wp-includes/link-template.php

    r24593 r24664  
    898898                return;
    899899
    900         if ( 'display' == $context )
     900        if ( 'revision' === $post->post_type )
     901                $action = '';
     902        elseif ( 'display' == $context )
    901903                $action = '&action=edit';
    902904        else
Note: See TracChangeset for help on using the changeset viewer.