Make WordPress Core

Ticket #30232: 30232.diff

File 30232.diff, 4.8 KB (added by ericlewis, 11 years ago)
  • src/wp-admin/includes/revision.php

    diff --git src/wp-admin/includes/revision.php src/wp-admin/includes/revision.php
    index 9e8b6e3..af9c090 100644
    function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) { 
    111111 *
    112112 * @since 3.6.0
    113113 *
    114  * @param object|int $post                 The post object. Also accepts a post ID.
    115  * @param int        $selected_revision_id The selected revision ID.
    116  * @param int        $from                 Optional. The revision ID to compare from.
     114 * @param array      $args {
     115 *     Options hash for preparing data.
     116 *
     117 *     @type object|int $post      The post object or post ID.
     118 *     @type int        $from      Optional. The revision ID to compare from. Defaults to the
     119 *                                 most recent revision.
     120 *     @type int        $to        The revision ID to compare to.
     121 *     @type array      $revisions Optional. A group of revisions to prepare data for.
     122 *                                 Defaults to all revisions of the post.
     123 * }
    117124 *
    118125 * @return array An associative array of revision data and related settings.
    119126 */
    120 function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) {
    121         $post = get_post( $post );
     127function wp_prepare_revisions_for_js( $args = array() ) {
     128        // Backwards compatibility for when this function was a string of arguments.
     129        if ( ! is_array( $args ) || func_num_args() > 1 ) {
     130                _deprecated_argument( __FUNCTION__, '4.1', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.' ), __FUNCTION__, __FILE__ ) );
     131                $old_args = array( 0 => 'post', 1 => 'to', 2 => 'from' );
     132                $func_args = func_get_args();
     133                foreach( $old_args as $arg_num => $arg_key ) {
     134                        if ( isset( $func_args[$arg_num] ) ) {
     135                                $new_args[$arg_key] = $func_args[$arg_num];
     136                        }
     137                }
     138                $args = $new_args;
     139        }
     140
     141        $defaults = array(
     142                'from' => null,
     143                'revisions' => null
     144        );
     145        $args = wp_parse_args( $args, $defaults );
     146
     147        if ( empty( $args['post'] ) ) {
     148                return new WP_Error( 'revisions_post_required', __( 'Post required.' ) );
     149        }
     150        if ( empty( $args['to'] ) ) {
     151                return new WP_Error( 'revisions_to_required', __( 'To required.' ) );
     152        }
     153        $post = get_post( $args['post'] );
     154        $to = $args['to'];
     155        $from = $args['from'];
     156
    122157        $authors = array();
    123158        $now_gmt = time();
    124159
    125         $revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC', 'check_enabled' => false ) );
     160        $revisions = $args['revisions'];
     161        if ( empty( $revisions ) ) {
     162                $revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC', 'check_enabled' => false ) );
     163        }
     164
    126165        // If revisions are disabled, we only want autosaves and the current post.
    127166        if ( ! wp_revisions_enabled( $post ) ) {
    128167                foreach ( $revisions as $revision_id => $revision ) {
    function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null 
    209248        // Now, grab the initial diff.
    210249        $compare_two_mode = is_numeric( $from );
    211250        if ( ! $compare_two_mode ) {
    212                 $found = array_search( $selected_revision_id, array_keys( $revisions ) );
     251                $found = array_search( $to, array_keys( $revisions ) );
    213252                if ( $found ) {
    214253                        $from = array_keys( array_slice( $revisions, $found - 1, 1, true ) );
    215254                        $from = reset( $from );
    function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null 
    219258        }
    220259
    221260        $from = absint( $from );
    222 
    223261        $diffs = array( array(
    224                 'id' => $from . ':' . $selected_revision_id,
    225                 'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ),
     262                'id' => $from . ':' . $to,
     263                'fields' => wp_get_revision_ui_diff( $post->ID, $from, $to ),
    226264        ));
    227265
    228266        return array(
    229267                'postId'           => $post->ID,
    230268                'nonce'            => wp_create_nonce( 'revisions-ajax-nonce' ),
    231269                'revisionData'     => array_values( $revisions ),
    232                 'to'               => $selected_revision_id,
     270                'to'               => $to,
    233271                'from'             => $from,
    234272                'diffData'         => $diffs,
    235273                'baseUrl'          => parse_url( admin_url( 'revision.php' ), PHP_URL_PATH ),
  • src/wp-admin/revision.php

    diff --git src/wp-admin/revision.php src/wp-admin/revision.php
    index f65ae6a..1709c19 100644
    else 
    9898        $parent_file = $submenu_file = 'edit.php';
    9999
    100100wp_enqueue_script( 'revisions' );
    101 wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $post, $revision_id, $from ) );
     101wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( array(
     102        'post' => $post,
     103        'to' => $revision_id,
     104        'from' => $from ) ) );
    102105
    103106/* Revisions Help Tab */
    104107