mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 21:00:21 +00:00
Post revisions from mdawaffe. see #6775
git-svn-id: https://develop.svn.wordpress.org/trunk@7747 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -564,4 +564,136 @@ function is_page_template($template = '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
?>
|
||||
/**
|
||||
* wp_post_revision_time() - returns formatted datetimestamp of a revision
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Post Revisions
|
||||
* @since 2.6
|
||||
*
|
||||
* @uses wp_get_revision()
|
||||
* @uses date_i18n()
|
||||
*
|
||||
* @param int|object $revision revision ID or revision object
|
||||
* @return string i18n formatted datetimestamp or localized 'Corrent Revision'
|
||||
*/
|
||||
function wp_post_revision_time( $revision ) {
|
||||
if ( !$revision = wp_get_revision( $revision ) ) {
|
||||
if ( $revision = get_post( $revision ) )
|
||||
return __( 'Current Revision' );
|
||||
return $revision;
|
||||
}
|
||||
|
||||
$datef = _c( 'j F, Y @ G:i|revision date format');
|
||||
return date_i18n( $datef, strtotime( $revision->post_date_gmt . ' +0000' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_list_post_revisions() - echoes list of a post's revisions
|
||||
*
|
||||
* Can output either a UL with edit links or a TABLE with diff interface, and restore action links
|
||||
*
|
||||
* Second argument controls parameters:
|
||||
* (bool) parent : include the parent (the "Current Revision") in the list
|
||||
* (string) format : 'list' or 'form-table'. 'list' outputs UL, 'form-table' outputs TABLE with UI
|
||||
* (int) right : what revision is currently being viewed - used in form-table format
|
||||
* (int) left : what revision is currently being diffed against right - used in form-table format
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Post Revisions
|
||||
* @since 2.6
|
||||
*
|
||||
* @uses wp_get_post_revisions()
|
||||
* @uses wp_post_revision_time()
|
||||
* @uses get_edit_post_link()
|
||||
* @uses get_author_name()
|
||||
*
|
||||
* @param int|object $post_id post ID or post object
|
||||
* @param string|array $args see description @see wp_parse_args()
|
||||
*/
|
||||
function wp_list_post_revisions( $post_id = 0, $args = null ) { // TODO? split into two functions (list, form-table) ?
|
||||
if ( !$post = get_post( $post_id ) )
|
||||
return;
|
||||
|
||||
if ( !$revisions = wp_get_post_revisions( $post->ID ) )
|
||||
return;
|
||||
|
||||
$defaults = array( 'parent' => false, 'right' => false, 'left' => false, 'format' => 'list' );
|
||||
extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );
|
||||
|
||||
$titlef = _c( '%1$s by %2$s|post revision 1:datetime, 2:name' );
|
||||
|
||||
if ( $parent )
|
||||
array_unshift( $revisions, $post );
|
||||
|
||||
$rows = '';
|
||||
$class = false;
|
||||
foreach ( $revisions as $revision ) {
|
||||
$date = wp_post_revision_time( $revision );
|
||||
if ( $link = get_edit_post_link( $revision->ID ) )
|
||||
$date = "<a href='$link'>$date</a>";
|
||||
$name = get_author_name( $revision->post_author );
|
||||
|
||||
if ( 'form-table' == $format ) {
|
||||
if ( $left )
|
||||
$old_checked = $left == $revision->ID ? ' checked="checked"' : '';
|
||||
else
|
||||
$old_checked = $new_checked ? ' checked="checked"' : '';
|
||||
$new_checked = $right == $revision->ID ? ' checked="checked"' : '';
|
||||
|
||||
$class = $class ? '' : " class='alternate'";
|
||||
|
||||
if ( $post->ID != $revision->ID && current_user_can( 'edit_post', $post->ID ) )
|
||||
$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>';
|
||||
else
|
||||
$actions = '';
|
||||
|
||||
$rows .= "<tr$class>\n";
|
||||
$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";
|
||||
$rows .= "\t<td>$date</td>\n";
|
||||
$rows .= "\t<td>$name</td>\n";
|
||||
$rows .= "\t<td class='action-links'>$actions</td>\n";
|
||||
$rows .= "</tr>\n";
|
||||
} else {
|
||||
$rows .= "\t<li>" . sprintf( $titlef, $date, $name ). "</li>\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'form-table' == $format ) : ?>
|
||||
|
||||
<form action="revision.php" method="get">
|
||||
|
||||
<div class="tablenav">
|
||||
<div class="alignleft">
|
||||
<input type="submit" class="button-secondary" value="<?php _e( 'Compare Revisions' ); ?>" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<br class="clear" />
|
||||
|
||||
<table class="widefat post-revisions">
|
||||
<col />
|
||||
<col style="width: 33%" />
|
||||
<col style="width: 33%" />
|
||||
<col style="width: 33%" />
|
||||
<thead>
|
||||
<th scope="col"></th>
|
||||
<th scope="col"><?php _e( 'Date Created' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Author' ); ?></th>
|
||||
<th scope="col" class="action-links"><?php _e( 'Actions' ); ?></th>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<?php echo $rows; ?>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
else :
|
||||
echo "<ul class='post-revisions'>\n";
|
||||
echo $rows;
|
||||
echo "</ul>";
|
||||
endif;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user