Make WordPress Core

Ticket #30232: 30232.2.diff

File 30232.2.diff, 4.0 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..aa6481f 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                $old_args = array( 0 => 'post', 1 => 'to', 2 => 'from' );
     131                $func_args = func_get_args();
     132                foreach( $old_args as $arg_num => $arg_key ) {
     133                        if ( isset( $func_args[$arg_num] ) ) {
     134                                $new_args[$arg_key] = $func_args[$arg_num];
     135                        }
     136                }
     137                $args = $new_args;
     138        }
     139
     140        $defaults = array(
     141                'from' => null,
     142                'revisions' => null
     143        );
     144        $args = wp_parse_args( $args, $defaults );
     145
     146        if ( empty( $args['post'] ) ) {
     147                return new WP_Error( 'revisions_post_required', __( 'Post required.' ) );
     148        }
     149        if ( empty( $args['to'] ) ) {
     150                return new WP_Error( 'revisions_to_required', __( 'To required.' ) );
     151        }
     152        $post = get_post( $args['post'] );
     153        $to = $args['to'];
     154        $from = $args['from'];
     155
    122156        $authors = array();
    123157        $now_gmt = time();
    124158
    125         $revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC', 'check_enabled' => false ) );
     159        $revisions = $args['revisions'];
     160        if ( empty( $revisions ) ) {
     161                $revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC', 'check_enabled' => false ) );
     162        }
     163
    126164        // If revisions are disabled, we only want autosaves and the current post.
    127165        if ( ! wp_revisions_enabled( $post ) ) {
    128166                foreach ( $revisions as $revision_id => $revision ) {
    function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null 
    209247        // Now, grab the initial diff.
    210248        $compare_two_mode = is_numeric( $from );
    211249        if ( ! $compare_two_mode ) {
    212                 $found = array_search( $selected_revision_id, array_keys( $revisions ) );
     250                $found = array_search( $to, array_keys( $revisions ) );
    213251                if ( $found ) {
    214252                        $from = array_keys( array_slice( $revisions, $found - 1, 1, true ) );
    215253                        $from = reset( $from );
    function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null 
    219257        }
    220258
    221259        $from = absint( $from );
    222 
    223260        $diffs = array( array(
    224                 'id' => $from . ':' . $selected_revision_id,
    225                 'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ),
     261                'id' => $from . ':' . $to,
     262                'fields' => wp_get_revision_ui_diff( $post->ID, $from, $to ),
    226263        ));
    227264
    228265        return array(
    229266                'postId'           => $post->ID,
    230267                'nonce'            => wp_create_nonce( 'revisions-ajax-nonce' ),
    231268                'revisionData'     => array_values( $revisions ),
    232                 'to'               => $selected_revision_id,
     269                'to'               => $to,
    233270                'from'             => $from,
    234271                'diffData'         => $diffs,
    235272                'baseUrl'          => parse_url( admin_url( 'revision.php' ), PHP_URL_PATH ),