Make WordPress Core


Ignore:
Timestamp:
04/18/2008 11:38:21 PM (17 years ago)
Author:
ryan
Message:

Post revisions from mdawaffe. see #6775

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post-template.php

    r7492 r7747  
    565565}
    566566
    567 ?>
     567/**
     568 * wp_post_revision_time() - returns formatted datetimestamp of a revision
     569 *
     570 * @package WordPress
     571 * @subpackage Post Revisions
     572 * @since 2.6
     573 *
     574 * @uses wp_get_revision()
     575 * @uses date_i18n()
     576 *
     577 * @param int|object $revision revision ID or revision object
     578 * @return string i18n formatted datetimestamp or localized 'Corrent Revision'
     579 */
     580function wp_post_revision_time( $revision ) {
     581    if ( !$revision = wp_get_revision( $revision ) ) {
     582        if ( $revision = get_post( $revision ) )
     583            return __( 'Current Revision' );
     584        return $revision;
     585    }
     586
     587    $datef  = _c( 'j F, Y @ G:i|revision date format');
     588    return date_i18n( $datef, strtotime( $revision->post_date_gmt . ' +0000' ) );
     589}
     590
     591/**
     592 * wp_list_post_revisions() - echoes list of a post's revisions
     593 *
     594 * Can output either a UL with edit links or a TABLE with diff interface, and restore action links
     595 *
     596 * Second argument controls parameters:
     597 *   (bool)   parent : include the parent (the "Current Revision") in the list
     598 *   (string) format : 'list' or 'form-table'.  'list' outputs UL, 'form-table' outputs TABLE with UI
     599 *   (int)    right  : what revision is currently being viewed - used in form-table format
     600 *   (int)    left   : what revision is currently being diffed against right - used in form-table format
     601 *
     602 * @package WordPress
     603 * @subpackage Post Revisions
     604 * @since 2.6
     605 *
     606 * @uses wp_get_post_revisions()
     607 * @uses wp_post_revision_time()
     608 * @uses get_edit_post_link()
     609 * @uses get_author_name()
     610 *
     611 * @param int|object $post_id post ID or post object
     612 * @param string|array $args see description @see wp_parse_args()
     613 */
     614function wp_list_post_revisions( $post_id = 0, $args = null ) { // TODO? split into two functions (list, form-table) ?
     615    if ( !$post = get_post( $post_id ) )
     616        return;
     617
     618    if ( !$revisions = wp_get_post_revisions( $post->ID ) )
     619        return;
     620
     621    $defaults = array( 'parent' => false, 'right' => false, 'left' => false, 'format' => 'list' );
     622    extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );
     623
     624    $titlef = _c( '%1$s by %2$s|post revision 1:datetime, 2:name' );
     625
     626    if ( $parent )
     627        array_unshift( $revisions, $post );
     628
     629    $rows = '';
     630    $class = false;
     631    foreach ( $revisions as $revision ) {
     632        $date = wp_post_revision_time( $revision );
     633        if ( $link = get_edit_post_link( $revision->ID ) )
     634            $date = "<a href='$link'>$date</a>";
     635        $name = get_author_name( $revision->post_author );
     636
     637        if ( 'form-table' == $format ) {
     638            if ( $left )
     639                $old_checked = $left == $revision->ID ? ' checked="checked"' : '';
     640            else
     641                $old_checked = $new_checked ? ' checked="checked"' : '';
     642            $new_checked = $right == $revision->ID ? ' checked="checked"' : '';
     643
     644            $class = $class ? '' : " class='alternate'";
     645
     646            if ( $post->ID != $revision->ID && current_user_can( 'edit_post', $post->ID ) )
     647                $actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'diff' => false, 'restore' => 'restore' ) ), "restore-post_$post->ID|$revision->ID" ) . '">' . __( 'Restore' ) . '</a>';
     648            else
     649                $actions = '';
     650
     651            $rows .= "<tr$class>\n";
     652            $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='diff' value='$revision->ID'$old_checked /><input type='radio' name='revision' value='$revision->ID'$new_checked />\n";
     653            $rows .= "\t<td>$date</td>\n";
     654            $rows .= "\t<td>$name</td>\n";
     655            $rows .= "\t<td class='action-links'>$actions</td>\n";
     656            $rows .= "</tr>\n";
     657        } else {
     658            $rows .= "\t<li>" . sprintf( $titlef, $date, $name ). "</li>\n";
     659        }
     660    }
     661
     662    if ( 'form-table' == $format ) : ?>
     663
     664<form action="revision.php" method="get">
     665
     666<div class="tablenav">
     667    <div class="alignleft">
     668        <input type="submit" class="button-secondary" value="<?php _e( 'Compare Revisions' ); ?>" />
     669    </div>
     670</div>
     671
     672<br class="clear" />
     673
     674<table class="widefat post-revisions">
     675    <col />
     676    <col style="width: 33%" />
     677    <col style="width: 33%" />
     678    <col style="width: 33%" />
     679<thead>
     680    <th scope="col"></th>
     681    <th scope="col"><?php _e( 'Date Created' ); ?></th>
     682    <th scope="col"><?php _e( 'Author' ); ?></th>
     683    <th scope="col" class="action-links"><?php _e( 'Actions' ); ?></th>
     684</thead>
     685<tbody>
     686
     687<?php echo $rows; ?>
     688
     689</tbody>
     690</table>
     691
     692<?php
     693    else :
     694        echo "<ul class='post-revisions'>\n";
     695        echo $rows;
     696        echo "</ul>";
     697    endif;
     698
     699}
Note: See TracChangeset for help on using the changeset viewer.