<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[24664] trunk: Revisions: real URLs and preloading of the requested diff.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/24664">24664</a></dd>
<dt>Author</dt> <dd>markjaquith</dd>
<dt>Date</dt> <dd>2013-07-11 22:56:48 +0000 (Thu, 11 Jul 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>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 <a href="http://core.trac.wordpress.org/ticket/24425">#24425</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesrevisionphp">trunk/wp-admin/includes/revision.php</a></li>
<li><a href="#trunkwpadminjsrevisionsjs">trunk/wp-admin/js/revisions.js</a></li>
<li><a href="#trunkwpadminrevisionphp">trunk/wp-admin/revision.php</a></li>
<li><a href="#trunkwpincludeslinktemplatephp">trunk/wp-includes/link-template.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesrevisionphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/revision.php (24663 => 24664)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/revision.php     2013-07-11 20:57:47 UTC (rev 24663)
+++ trunk/wp-admin/includes/revision.php        2013-07-11 22:56:48 UTC (rev 24664)
</span><span class="lines">@@ -61,7 +61,7 @@
</span><span class="cx">  return $return;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-function wp_prepare_revisions_for_js( $post, $selected_revision_id ) {
</del><ins>+function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) {
</ins><span class="cx">   $post = get_post( $post );
</span><span class="cx">  $revisions = array();
</span><span class="cx">  $now_gmt = time();
</span><span class="lines">@@ -98,10 +98,27 @@
</span><span class="cx">          );
</span><span class="cx">  }
</span><span class="cx"> 
</span><ins>+       // Now, grab the initial diff
+       if ( ! $from ) { // Single mode
+               $initial_revisions = array_reverse( array_keys( array_slice( $revisions, array_search( $selected_revision_id, array_keys( $revisions ) ), 2, true ) ) );
+               $compare_two_mode = false;
+       } else { // Compare two
+               $compare_two_mode = true;
+               $initial_revisions = array( $from, $selected_revision_id );
+       }
+       $diffs = array( array(
+               'id' => $initial_revisions[0] . ':' . $initial_revisions[1],
+               'fields' => wp_get_revision_ui_diff( $post->ID, $initial_revisions[0], $initial_revisions[1] ),
+       ));
+
</ins><span class="cx">   return array(
</span><span class="cx">          'postId'           => $post->ID,
</span><span class="cx">          'nonce'            => wp_create_nonce( 'revisions-ajax-nonce' ),
</span><span class="cx">          'revisionData'     => array_values( $revisions ),
</span><del>-               'selectedRevision' => $selected_revision_id,
</del><ins>+                'to'               => $selected_revision_id,
+               'from'             => $from,
+               'diffData'         => $diffs,
+               'baseUrl'          => parse_url( admin_url( 'revision.php' ), PHP_URL_PATH ),
+               'compareTwoMode'   => absint( $compare_two_mode ), // Apparently booleans are not allowed
</ins><span class="cx">   );
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkwpadminjsrevisionsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/revisions.js (24663 => 24664)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/revisions.js   2013-07-11 20:57:47 UTC (rev 24663)
+++ trunk/wp-admin/js/revisions.js      2013-07-11 22:56:48 UTC (rev 24664)
</span><span class="lines">@@ -17,9 +17,14 @@
</span><span class="cx">  };
</span><span class="cx"> 
</span><span class="cx">  // wp_localize_script transforms top-level numbers into strings. Undo that.
</span><del>-       if ( revisions.settings.selectedRevision )
-               revisions.settings.selectedRevision = parseInt( revisions.settings.selectedRevision, 10 );
</del><ins>+        if ( revisions.settings.to )
+               revisions.settings.to = parseInt( revisions.settings.to, 10 );
+       if ( revisions.settings.from )
+               revisions.settings.from = parseInt( revisions.settings.from, 10 );
</ins><span class="cx"> 
</span><ins>+       // wp_localize_script does not allow for top-level booleans. Fix that.
+       if ( revisions.settings.compareTwoMode )
+               revisions.settings.compareTwoMode = revisions.settings.compareTwoMode === '1';
</ins><span class="cx"> 
</span><span class="cx">  /**
</span><span class="cx">   * ========================================================================
</span><span class="lines">@@ -40,7 +45,7 @@
</span><span class="cx">                  this.revisions = options.revisions;
</span><span class="cx">                  this.set({
</span><span class="cx">                          max:   this.revisions.length - 1,
</span><del>-                               value: this.revisions.indexOf( this.revisions.get( revisions.settings.selectedRevision ) ),
</del><ins>+                                value: this.revisions.indexOf( this.revisions.get( revisions.settings.to ) ),
</ins><span class="cx">                           compareTwoMode: this.frame.get('compareTwoMode')
</span><span class="cx">                  });
</span><span class="cx"> 
</span><span class="lines">@@ -314,6 +319,10 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">  revisions.model.FrameState = Backbone.Model.extend({
</span><ins>+               defaults: {
+                       compareTwoMode: false
+               },
+
</ins><span class="cx">           initialize: function( attributes, options ) {
</span><span class="cx">                  var properties = {};
</span><span class="cx"> 
</span><span class="lines">@@ -322,17 +331,22 @@
</span><span class="cx">                  this.revisions = options.revisions;
</span><span class="cx">                  this.diffs = new revisions.model.Diffs( [], { revisions: this.revisions });
</span><span class="cx"> 
</span><del>-                       // Set the initial revision provided through the settings.
-                       properties.to = this.revisions.get( revisions.settings.selectedRevision );
-                       properties.from = this.revisions.prev( properties.to );
-                       properties.compareTwoMode = false;
</del><ins>+                        // Set the initial diffs collection provided through the settings
+                       this.diffs.set( revisions.settings.diffData );
+
+                       // Set the initial revisions, baseUrl, and mode as provided through settings
+                       properties.to = this.revisions.get( revisions.settings.to );
+                       properties.from = this.revisions.get( revisions.settings.from ) || this.revisions.prev( properties.to );
+                       properties.compareTwoMode = revisions.settings.compareTwoMode;
+                       properties.baseUrl = revisions.settings.baseUrl;
</ins><span class="cx">                   this.set( properties );
</span><span class="cx"> 
</span><span class="cx">                  // Start the router. This will trigger a navigate event and ensure that
</span><span class="cx">                  // the `from` and `to` revisions accurately reflect the hash.
</span><span class="cx">                  this.router = new revisions.Router({ model: this });
</span><del>-                       Backbone.history.start();
</del><ins>+                        Backbone.history.start({ pushState: true });
</ins><span class="cx"> 
</span><ins>+                       // Set up internal listeners
</ins><span class="cx">                   this.listenTo( this, 'change:from', this.changeRevisionHandler );
</span><span class="cx">                  this.listenTo( this, 'change:to', this.changeRevisionHandler );
</span><span class="cx">                  this.listenTo( this, 'update:revisions', this.loadSurrounding );
</span><span class="lines">@@ -937,23 +951,30 @@
</span><span class="cx">  revisions.Router = Backbone.Router.extend({
</span><span class="cx">          initialize: function( options ) {
</span><span class="cx">                  this.model = options.model;
</span><ins>+                       this.routes = this.getRoutes();
</ins><span class="cx"> 
</span><span class="cx">                  // Maintain state history when dragging
</span><span class="cx">                  this.listenTo( this.model, 'update:diff', _.debounce( this.updateUrl, 250 ) );
</span><span class="cx">          },
</span><span class="cx"> 
</span><del>-               routes: {
-                       'from/:from/to/:to': 'handleRoute',
-                       'at/:to': 'handleRoute'
</del><ins>+                getRoutes: function() {
+                       var routes = {};
+                       routes[this.baseUrl( '?from=:from&to=:to' )] = 'handleRoute';
+                       routes[this.baseUrl( '?revision=:to' )] = 'handleRoute';
+                       return routes;
</ins><span class="cx">           },
</span><span class="cx"> 
</span><ins>+               baseUrl: function( url ) {
+                       return this.model.get('baseUrl') + url;
+               },
+
</ins><span class="cx">           updateUrl: function() {
</span><span class="cx">                  var from = this.model.has('from') ? this.model.get('from').id : 0;
</span><span class="cx">                  var to = this.model.get('to').id;
</span><span class="cx">                  if ( this.model.get('compareTwoMode' ) )
</span><del>-                               this.navigate( 'from/' + from + '/to/' + to );
</del><ins>+                                this.navigate( this.baseUrl( '?from=' + from + '&to=' + to ) );
</ins><span class="cx">                   else
</span><del>-                               this.navigate( 'at/' + to );
</del><ins>+                                this.navigate( this.baseUrl( '?revision=' + to ) );
</ins><span class="cx">           },
</span><span class="cx"> 
</span><span class="cx">          handleRoute: function( a, b ) {
</span><span class="lines">@@ -964,7 +985,7 @@
</span><span class="cx">                          b = this.model.revisions.get( a );
</span><span class="cx">                          a = this.model.revisions.prev( b );
</span><span class="cx">                          b = b ? b.id : 0;
</span><del>-                               a = a ? a.id : 0
</del><ins>+                                a = a ? a.id : 0;
</ins><span class="cx">                           compareTwo = false;
</span><span class="cx">                  } else {
</span><span class="cx">                          compareTwo = true;
</span><span class="lines">@@ -984,7 +1005,7 @@
</span><span class="cx">                                  from: selectedFromRevision
</span><span class="cx">                          });
</span><span class="cx">                  }
</span><del>-                       revisions.settings.selectedRevision = to;
</del><ins>+                        revisions.settings.to = to;
</ins><span class="cx">           }
</span><span class="cx">  });
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminrevisionphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/revision.php (24663 => 24664)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/revision.php      2013-07-11 20:57:47 UTC (rev 24663)
+++ trunk/wp-admin/revision.php 2013-07-11 22:56:48 UTC (rev 24664)
</span><span class="lines">@@ -11,9 +11,12 @@
</span><span class="cx"> 
</span><span class="cx"> require ABSPATH . 'wp-admin/includes/revision.php';
</span><span class="cx"> 
</span><del>-wp_reset_vars( array( 'revision', 'action' ) );
</del><ins>+wp_reset_vars( array( 'revision', 'action', 'from', 'to' ) );
</ins><span class="cx"> 
</span><span class="cx"> $revision_id = absint( $revision );
</span><ins>+$from = absint( $from );
+if ( ! $revision_id )
+       $revision_id = absint( $to );
</ins><span class="cx"> $redirect = 'edit.php';
</span><span class="cx"> 
</span><span class="cx"> switch ( $action ) :
</span><span class="lines">@@ -79,7 +82,7 @@
</span><span class="cx">  $parent_file = $submenu_file = 'edit.php';
</span><span class="cx"> 
</span><span class="cx"> wp_enqueue_script( 'revisions' );
</span><del>-wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $post, $revision_id ) );
</del><ins>+wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $post, $revision_id, $from ) );
</ins><span class="cx"> 
</span><span class="cx"> /* Revisions Help Tab */
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpincludeslinktemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/link-template.php (24663 => 24664)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/link-template.php      2013-07-11 20:57:47 UTC (rev 24663)
+++ trunk/wp-includes/link-template.php 2013-07-11 22:56:48 UTC (rev 24664)
</span><span class="lines">@@ -897,7 +897,9 @@
</span><span class="cx">  if ( ! $post = get_post( $id ) )
</span><span class="cx">          return;
</span><span class="cx"> 
</span><del>-       if ( 'display' == $context )
</del><ins>+        if ( 'revision' === $post->post_type )
+               $action = '';
+       elseif ( 'display' == $context )
</ins><span class="cx">           $action = '&amp;action=edit';
</span><span class="cx">  else
</span><span class="cx">          $action = '&action=edit';
</span></span></pre>
</div>
</div>

</body>
</html>