mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Move autosave to post revisions. Props mdawaffe. see #6775
git-svn-id: https://develop.svn.wordpress.org/trunk@7907 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -168,8 +168,6 @@ var autosave = function() {
|
||||
autosave_disable_buttons();
|
||||
|
||||
var origStatus = jQuery('#original_post_status').val();
|
||||
if ( 'draft' != origStatus ) // autosave currently only turned on for drafts
|
||||
doAutoSave = false;
|
||||
|
||||
autosaveLast = jQuery("#title").val()+jQuery("#content").val();
|
||||
goodcats = ([]);
|
||||
|
||||
@@ -1392,7 +1392,7 @@ if ( !function_exists( 'wp_text_diff' ) ) :
|
||||
* @return string human readable HTML of string differences. Empty string if strings are equivalent
|
||||
*/
|
||||
function wp_text_diff( $left_string, $right_string, $args = null ) {
|
||||
$defaults = array( 'title' => '' );
|
||||
$defaults = array( 'title' => '', 'title_left' => '', 'title_right' => '' );
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
|
||||
// PEAR Text_Diff is lame; it includes things from include_path rather than it's own path.
|
||||
@@ -1425,8 +1425,18 @@ function wp_text_diff( $left_string, $right_string, $args = null ) {
|
||||
$r = "<table class='diff'>\n";
|
||||
$r .= "<col class='ltype' /><col class='content' /><col class='ltype' /><col class='content' />";
|
||||
|
||||
if ( $args['title'] || $args['title_left'] || $args['title_right'] )
|
||||
$r .= "<thead>";
|
||||
if ( $args['title'] )
|
||||
$r .= "<thead><tr><th colspan='4'>$args[title]</th></tr></thead>\n";
|
||||
$r .= "<tr class='diff-title'><th colspan='4'>$args[title]</th></tr>\n";
|
||||
if ( $args['title_left'] || $args['title_right'] ) {
|
||||
$r .= "<tr class='diff-sub-title'>\n";
|
||||
$r .= "\t<td></td><th>$args[title_left]</th>\n";
|
||||
$r .= "\t<td></td><th>$args[title_right]</th>\n";
|
||||
$r .= "</tr>\n";
|
||||
}
|
||||
if ( $args['title'] || $args['title_left'] || $args['title_right'] )
|
||||
$r .= "</thead>\n";
|
||||
|
||||
$r .= "<tbody>\n$diff\n</tbody>\n";
|
||||
$r .= "</table>";
|
||||
|
||||
@@ -566,27 +566,39 @@ function is_page_template($template = '') {
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_post_revision_time() - returns formatted datetimestamp of a revision
|
||||
* wp_post_revision_title() - returns formatted datetimestamp of a revision (linked to that revisions's page)
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Post Revisions
|
||||
* @since 2.6
|
||||
*
|
||||
* @uses wp_get_revision()
|
||||
* @uses date_i18n()
|
||||
*
|
||||
* @param int|object $revision revision ID or revision object
|
||||
* @param bool $link optional Link to revisions's page?
|
||||
* @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' );
|
||||
function wp_post_revision_title( $revision, $link = true ) {
|
||||
if ( !$revision = get_post( $revision ) )
|
||||
return $revision;
|
||||
}
|
||||
|
||||
$datef = _c( 'j F, Y @ G:i|revision date format');
|
||||
return date_i18n( $datef, strtotime( $revision->post_date_gmt . ' +0000' ) );
|
||||
if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) )
|
||||
return false;
|
||||
|
||||
$datef = _c( 'j F, Y @ G:i|revision date format');
|
||||
$autosavef = __( '%s [Autosave]' );
|
||||
$currentf = __( '%s [Current Revision]' );
|
||||
|
||||
$date = date_i18n( $datef, strtotime( $revision->post_modified_gmt . ' +0000' ) );
|
||||
if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
|
||||
$date = "<a href='$link'>$date</a>";
|
||||
|
||||
if ( 'revision' != $revision->post_type )
|
||||
$date = sprintf( $currentf, $date );
|
||||
elseif ( "{$revision->post_parent}-autosave" == $revision->post_name )
|
||||
$date = sprintf( $autosavef, $date );
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -605,7 +617,7 @@ function wp_post_revision_time( $revision ) {
|
||||
* @since 2.6
|
||||
*
|
||||
* @uses wp_get_post_revisions()
|
||||
* @uses wp_post_revision_time()
|
||||
* @uses wp_post_revision_title()
|
||||
* @uses get_edit_post_link()
|
||||
* @uses get_author_name()
|
||||
*
|
||||
@@ -630,33 +642,32 @@ function wp_list_post_revisions( $post_id = 0, $args = null ) { // TODO? split i
|
||||
$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>";
|
||||
$date = wp_post_revision_title( $revision );
|
||||
$name = get_author_name( $revision->post_author );
|
||||
|
||||
if ( 'form-table' == $format ) {
|
||||
if ( $left )
|
||||
$old_checked = $left == $revision->ID ? ' checked="checked"' : '';
|
||||
$left_checked = $left == $revision->ID ? ' checked="checked"' : '';
|
||||
else
|
||||
$old_checked = $new_checked ? ' checked="checked"' : '';
|
||||
$new_checked = $right == $revision->ID ? ' checked="checked"' : '';
|
||||
$left_checked = $right_checked ? ' checked="checked"' : ''; // [sic] (the next one)
|
||||
$right_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>';
|
||||
$actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'diff' => false, 'action' => '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<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='$revision->ID'$left_checked /><input type='radio' name='right' value='$revision->ID'$right_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";
|
||||
$title = sprintf( $titlef, $date, $name );
|
||||
$rows .= "\t<li>$title</li>\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -667,6 +678,7 @@ function wp_list_post_revisions( $post_id = 0, $args = null ) { // TODO? split i
|
||||
<div class="tablenav">
|
||||
<div class="alignleft">
|
||||
<input type="submit" class="button-secondary" value="<?php _e( 'Compare Revisions' ); ?>" />
|
||||
<input type="hidden" name="action" value="diff" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
+71
-19
@@ -88,7 +88,6 @@ function &get_children($args = '', $output = OBJECT) {
|
||||
$r = wp_parse_args( $args, $defaults );
|
||||
|
||||
$children = get_posts( $r );
|
||||
|
||||
if ( !$children )
|
||||
return false;
|
||||
|
||||
@@ -2957,18 +2956,19 @@ function _get_post_ancestors(&$_post) {
|
||||
/**
|
||||
* _wp_revision_fields() - determines which fields of posts are to be saved in revisions
|
||||
*
|
||||
* Does two things. If passed a postn *array*, it will return a post array ready to be
|
||||
* Does two things. If passed a post *array*, it will return a post array ready to be
|
||||
* insterted into the posts table as a post revision.
|
||||
* Otherwise, returns an array whose keys are the post fields to be saved post revisions.
|
||||
* Otherwise, returns an array whose keys are the post fields to be saved for post revisions.
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Post Revisions
|
||||
* @since 2.6
|
||||
*
|
||||
* @param array $post optional a post array to be processed for insertion as a post revision
|
||||
* @param bool $autosave optional Is the revision an autosave?
|
||||
* @return array post array ready to be inserted as a post revision or array of fields that can be versioned
|
||||
*/
|
||||
function _wp_revision_fields( $post = null ) {
|
||||
function _wp_revision_fields( $post = null, $autosave = false ) {
|
||||
static $fields = false;
|
||||
|
||||
if ( !$fields ) {
|
||||
@@ -2980,6 +2980,9 @@ function _wp_revision_fields( $post = null ) {
|
||||
'post_excerpt' => __( 'Excerpt' ),
|
||||
);
|
||||
|
||||
// Runs only once
|
||||
$fields = apply_filters( '_wp_revision_fields', $fields );
|
||||
|
||||
// WP uses these internally either in versioning or elsewhere - they cannot be versioned
|
||||
foreach ( array( 'ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count' ) as $protect )
|
||||
unset( $fields[$protect] );
|
||||
@@ -2995,7 +2998,7 @@ function _wp_revision_fields( $post = null ) {
|
||||
$return['post_parent'] = $post['ID'];
|
||||
$return['post_status'] = 'inherit';
|
||||
$return['post_type'] = 'revision';
|
||||
$return['post_name'] = "$post[ID]-revision";
|
||||
$return['post_name'] = $autosave ? "$post[ID]-autosave" : "$post[ID]-revision";
|
||||
$return['post_date'] = $post['post_modified'];
|
||||
$return['post_date_gmt'] = $post['post_modified_gmt'];
|
||||
|
||||
@@ -3015,20 +3018,61 @@ function _wp_revision_fields( $post = null ) {
|
||||
* @return mixed null or 0 if error, new revision ID if success
|
||||
*/
|
||||
function wp_save_revision( $post_id ) {
|
||||
// TODO: rework autosave to use special type of post revision
|
||||
// We do autosaves manually with wp_create_autosave()
|
||||
if ( @constant( 'DOING_AUTOSAVE' ) )
|
||||
return;
|
||||
|
||||
if ( !$post = get_post( $post_id, ARRAY_A ) )
|
||||
return;
|
||||
|
||||
// TODO: open this up for pages also
|
||||
if ( 'post' != $post->post_type )
|
||||
if ( !in_array( $post['post_type'], array( 'post', 'page' ) ) )
|
||||
return;
|
||||
|
||||
return _wp_put_revision( $post );
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_get_autosave() - returns the autosaved data of the specified post.
|
||||
*
|
||||
* Returns a post object containing the information that was autosaved for the specified post.
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Post Revisions
|
||||
* @since 2.6
|
||||
*
|
||||
* @param int $post_id The post ID
|
||||
* @return object|bool the autosaved data or false on failure or when no autosave exists
|
||||
*/
|
||||
function wp_get_autosave( $post_id ) {
|
||||
global $wpdb;
|
||||
if ( !$post = get_post( $post_id ) )
|
||||
return false;
|
||||
|
||||
$q = array(
|
||||
'name' => "{$post->ID}-autosave",
|
||||
'post_parent' => $post->ID,
|
||||
'post_type' => 'revision',
|
||||
'post_status' => 'inherit'
|
||||
);
|
||||
|
||||
// Use WP_Query so that the result gets cached
|
||||
$autosave_query = new WP_Query;
|
||||
|
||||
add_action( 'parse_query', '_wp_get_autosave_hack' );
|
||||
$autosave = $autosave_query->query( $q );
|
||||
remove_action( 'parse_query', '_wp_get_autosave_hack' );
|
||||
|
||||
if ( $autosave && is_array($autosave) && is_object($autosave[0]) )
|
||||
return $autosave[0];
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Internally used to hack WP_Query into submission
|
||||
function _wp_get_autosave_hack( $query ) {
|
||||
$query->is_single = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* _wp_put_revision() - Inserts post data into the posts table as a post revision
|
||||
*
|
||||
@@ -3039,25 +3083,28 @@ function wp_save_revision( $post_id ) {
|
||||
* @uses wp_insert_post()
|
||||
*
|
||||
* @param int|object|array $post post ID, post object OR post array
|
||||
* @param bool $autosave optional Is the revision an autosave?
|
||||
* @return mixed null or 0 if error, new revision ID if success
|
||||
*/
|
||||
function _wp_put_revision( $post = null ) {
|
||||
function _wp_put_revision( $post = null, $autosave = false ) {
|
||||
if ( is_object($post) )
|
||||
$post = get_object_vars( $post );
|
||||
elseif ( !is_array($post) )
|
||||
$post = get_post($post, ARRAY_A);
|
||||
|
||||
if ( !$post || empty($post['ID']) )
|
||||
return;
|
||||
|
||||
if ( isset($post['post_type']) && 'revision' == $post_post['type'] )
|
||||
return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) );
|
||||
|
||||
$post = _wp_revision_fields( $post );
|
||||
$post = _wp_revision_fields( $post, $autosave );
|
||||
|
||||
if ( $revision_id = wp_insert_post( $post ) )
|
||||
$revision_id = wp_insert_post( $post );
|
||||
if ( is_wp_error($revision_id) )
|
||||
return $revision_id;
|
||||
|
||||
if ( $revision_id )
|
||||
do_action( '_wp_put_revision', $revision_id );
|
||||
|
||||
return $revision_id;
|
||||
}
|
||||
|
||||
@@ -3127,7 +3174,11 @@ function wp_restore_revision( $revision_id, $fields = null ) {
|
||||
|
||||
$update['ID'] = $revision['post_parent'];
|
||||
|
||||
if ( $post_id = wp_update_post( $update ) )
|
||||
$post_id = wp_update_post( $update );
|
||||
if ( is_wp_error( $post_id ) )
|
||||
return $post_id;
|
||||
|
||||
if ( $post_id )
|
||||
do_action( 'wp_restore_revision', $post_id, $revision['ID'] );
|
||||
|
||||
return $post_id;
|
||||
@@ -3153,7 +3204,11 @@ function wp_delete_revision( $revision_id ) {
|
||||
if ( !$revision = wp_get_revision( $revision_id ) )
|
||||
return $revision;
|
||||
|
||||
if ( $delete = wp_delete_post( $revision->ID ) )
|
||||
$delete = wp_delete_post( $revision->ID );
|
||||
if ( is_wp_error( $delete ) )
|
||||
return $delete;
|
||||
|
||||
if ( $delete )
|
||||
do_action( 'wp_delete_revision', $revision->ID, $revision );
|
||||
|
||||
return $delete;
|
||||
@@ -3174,10 +3229,7 @@ function wp_delete_revision( $revision_id ) {
|
||||
function wp_get_post_revisions( $post_id = 0 ) {
|
||||
if ( ( !$post = get_post( $post_id ) ) || empty( $post->ID ) )
|
||||
return array();
|
||||
|
||||
if ( !$revisions = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'revision' ) ) )
|
||||
if ( !$revisions = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) ) )
|
||||
return array();
|
||||
return $revisions;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -47,7 +47,7 @@ class WP_Scripts {
|
||||
'broken' => __('An unidentified error has occurred.')
|
||||
) );
|
||||
|
||||
$this->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '20080424' );
|
||||
$this->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '20080507' );
|
||||
|
||||
$this->add( 'wp-ajax', '/wp-includes/js/wp-ajax.js', array('prototype'), '20070306');
|
||||
$this->localize( 'wp-ajax', 'WPAjaxL10n', array(
|
||||
|
||||
Reference in New Issue
Block a user