Open View/Preview post in a new window from the link in the Saved/Updated message, cleanup messages code, add Draft updated for Pages.

git-svn-id: http://svn.automattic.com/wordpress/trunk@12020 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-10-11 00:37:26 +00:00
parent 831178162c
commit bc9fb32835
4 changed files with 87 additions and 42 deletions

View File

@ -18,25 +18,48 @@ if ( !defined('ABSPATH') )
$post_ID = isset($post_ID) ? (int) $post_ID : 0; $post_ID = isset($post_ID) ? (int) $post_ID : 0;
$action = isset($action) ? $action : ''; $action = isset($action) ? $action : '';
if ( isset($_GET['message']) )
$_GET['message'] = absint( $_GET['message'] );
$messages[1] = sprintf(__('Post updated. <a href="%s">View post</a>'), get_permalink($post_ID));
$messages[2] = __('Custom field updated.');
$messages[3] = __('Custom field deleted.');
$messages[4] = __('Post updated.');
$messages[6] = sprintf(__('Post published. <a href="%s">View post</a>'), get_permalink($post_ID));
$messages[7] = __('Post saved.');
$messages[8] = sprintf(__('Post submitted. <a href="%s">Preview post</a>'), add_query_arg( 'preview', 'true', get_permalink($post_ID) ) );
// translators: Publish box date formt, see http://php.net/date - Same as in meta-boxes.php
$messages[9] = sprintf(__('Post scheduled for: <b>%1$s</b>. <a href="%2$s">Preview post</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), get_permalink($post_ID));
$messages[10] = sprintf(__('Draft updated. <a href="%s">Preview</a>'), get_permalink($post_ID));
if ( isset($_GET['revision']) ) $message = false;
$messages[5] = sprintf( __('Post restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ); if ( isset($_GET['message']) ) {
$_GET['message'] = absint( $_GET['message'] );
switch ( $_GET['message'] ) {
case 1:
$message = sprintf( __('Post updated. <a target="_blank" href="%s">View post</a>'), get_permalink($post_ID) );
break;
case 2:
$message = __('Custom field updated.');
break;
case 3:
$message = __('Custom field deleted.');
break;
case 4:
$message = __('Post updated.');
break;
case 5:
if ( isset($_GET['revision']) )
$message = sprintf( __('Post restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) );
break;
case 6:
$message = sprintf( __('Post published. <a target="_blank" href="%s">View post</a>'), get_permalink($post_ID) );
break;
case 7:
$message = __('Post saved.');
break;
case 8:
$message = sprintf( __('Post submitted. <a target="_blank" href="%s">Preview post</a>'), add_query_arg( 'preview', 'true', get_permalink($post_ID) ) );
break;
case 9:
// translators: Publish box date formt, see http://php.net/date - Same as in meta-boxes.php
$message = sprintf( __('Post scheduled for: <b>%1$s</b>. <a target="_blank" href="%2$s">Preview post</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), get_permalink($post_ID) );
break;
case 10:
$message = sprintf( __('Post draft updated. <a target="_blank" href="%s">Preview post</a>'), add_query_arg( 'preview', 'true', get_permalink($post_ID) ) );
break;
}
}
$notice = false; $notice = false;
$notices[1] = __( 'There is an autosave of this post that is more recent than the version below. <a href="%s">View the autosave</a>.' );
if ( 0 == $post_ID ) { if ( 0 == $post_ID ) {
$form_action = 'post'; $form_action = 'post';
$temp_ID = -1 * time(); // don't change this formula without looking at wp_write_post() $temp_ID = -1 * time(); // don't change this formula without looking at wp_write_post()
@ -51,7 +74,7 @@ if ( 0 == $post_ID ) {
if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt, false ) > mysql2date( 'U', $post->post_modified_gmt, false ) ) { if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt, false ) > mysql2date( 'U', $post->post_modified_gmt, false ) ) {
foreach ( _wp_post_revision_fields() as $autosave_field => $_autosave_field ) { foreach ( _wp_post_revision_fields() as $autosave_field => $_autosave_field ) {
if ( normalize_whitespace( $autosave->$autosave_field ) != normalize_whitespace( $post->$autosave_field ) ) { if ( normalize_whitespace( $autosave->$autosave_field ) != normalize_whitespace( $post->$autosave_field ) ) {
$notice = sprintf( $notices[1], get_edit_post_link( $autosave->ID ) ); $notice = sprintf( __( 'There is an autosave of this post that is more recent than the version below. <a href="%s">View the autosave</a>.' ), get_edit_post_link( $autosave->ID ) );
break; break;
} }
} }
@ -116,8 +139,8 @@ require_once('admin-header.php');
<?php if ( $notice ) : ?> <?php if ( $notice ) : ?>
<div id="notice" class="error"><p><?php echo $notice ?></p></div> <div id="notice" class="error"><p><?php echo $notice ?></p></div>
<?php endif; ?> <?php endif; ?>
<?php if (isset($_GET['message'])) : ?> <?php if ( $message ) : ?>
<div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div> <div id="message" class="updated fade"><p><?php echo $message; ?></p></div>
<?php endif; ?> <?php endif; ?>
<form name="post" action="post.php" method="post" id="post"> <form name="post" action="post.php" method="post" id="post">
<?php <?php

View File

@ -20,22 +20,41 @@ if ( ! isset( $post_ID ) )
if ( ! isset( $temp_ID ) ) if ( ! isset( $temp_ID ) )
$temp_ID = 0; $temp_ID = 0;
if ( isset($_GET['message']) ) $message = false;
if ( isset($_GET['message']) ) {
$_GET['message'] = absint( $_GET['message'] ); $_GET['message'] = absint( $_GET['message'] );
$messages[1] = sprintf(__('Page updated. <a href="%s">View page</a>'), get_permalink($post_ID));
$messages[2] = __('Custom field updated.');
$messages[3] = __('Custom field deleted.');
$messages[5] = sprintf(__('Page published. <a href="%s">View page</a>'), get_permalink($post_ID));
$messages[6] = sprintf(__('Page submitted. <a href="%s">Preview page</a>'), add_query_arg( 'preview', 'true', get_permalink($post_ID) ) );
// translators: Publish box date formt, see http://php.net/date - Same as in meta-boxes.php
$messages[7] = sprintf(__('Page scheduled for: <b>%1$s</b>. <a href="%2$s">Preview post</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), get_permalink($post_ID));
if ( isset($_GET['revision']) ) switch ( $_GET['message'] ) {
$messages[5] = sprintf( __('Page restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ); case 1:
$message = sprintf( __('Page updated. <a target="_blank" href="%s">View page</a>'), get_permalink($post_ID) );
break;
case 2:
$message = __('Custom field updated.');
break;
case 3:
$message = __('Custom field deleted.');
break;
case 4:
$message = sprintf( __('Page published. <a target="_blank" href="%s">View page</a>'), get_permalink($post_ID) );
break;
case 5:
if ( isset($_GET['revision']) )
$message = sprintf( __('Page restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) );
break;
case 6:
$message = sprintf( __('Page submitted. <a target="_blank" href="%s">Preview page</a>'), add_query_arg( 'preview', 'true', get_permalink($post_ID) ) );
break;
case 7:
// translators: Publish box date formt, see http://php.net/date - Same as in meta-boxes.php
$message = sprintf( __('Page scheduled for: <b>%1$s</b>. <a target="_blank" href="%2$s">Preview page</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), get_permalink($post_ID) );
break;
case 8:
$message = sprintf( __('Page draft updated. <a target="_blank" href="%s">Preview page</a>'), add_query_arg( 'preview', 'true', get_permalink($post_ID) ) );
break;
}
}
$notice = false; $notice = false;
$notices[1] = __( 'There is an autosave of this page that is more recent than the version below. <a href="%s">View the autosave</a>.' );
if ( 0 == $post_ID) { if ( 0 == $post_ID) {
$form_action = 'post'; $form_action = 'post';
$nonce_action = 'add-page'; $nonce_action = 'add-page';
@ -48,7 +67,7 @@ if ( 0 == $post_ID) {
$form_extra = "<input type='hidden' id='post_ID' name='post_ID' value='$post_ID' />"; $form_extra = "<input type='hidden' id='post_ID' name='post_ID' value='$post_ID' />";
$autosave = wp_get_post_autosave( $post_ID ); $autosave = wp_get_post_autosave( $post_ID );
if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt, false ) > mysql2date( 'U', $post->post_modified_gmt, false ) ) if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt, false ) > mysql2date( 'U', $post->post_modified_gmt, false ) )
$notice = sprintf( $notices[1], get_edit_post_link( $autosave->ID ) ); $notice = sprintf( __( 'There is an autosave of this page that is more recent than the version below. <a href="%s">View the autosave</a>.' ), get_edit_post_link( $autosave->ID ) );
} }
$temp_ID = (int) $temp_ID; $temp_ID = (int) $temp_ID;
@ -87,8 +106,8 @@ require_once('admin-header.php');
<?php if ( $notice ) : ?> <?php if ( $notice ) : ?>
<div id="notice" class="error"><p><?php echo $notice ?></p></div> <div id="notice" class="error"><p><?php echo $notice ?></p></div>
<?php endif; ?> <?php endif; ?>
<?php if (isset($_GET['message'])) : ?> <?php if ( $message ) : ?>
<div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div> <div id="message" class="updated fade"><p><?php echo $message; ?></p></div>
<?php endif; ?> <?php endif; ?>
<?php <?php

View File

@ -35,21 +35,25 @@ function redirect_page($page_ID) {
$location = $_POST['referredby']; $location = $_POST['referredby'];
} elseif ( 'post' == $_POST['originalaction'] && !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) { } elseif ( 'post' == $_POST['originalaction'] && !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) {
$location = 'sidebar.php?a=b'; $location = 'sidebar.php?a=b';
} elseif ( ( isset($_POST['save']) || isset($_POST['publish']) ) ) { } elseif ( isset($_POST['save']) || isset($_POST['publish']) ) {
$status = get_post_status( $page_ID );
if ( isset( $_POST['publish'] ) ) { if ( isset( $_POST['publish'] ) ) {
switch ( get_post_status( $page_ID ) ) { switch ( $status ) {
case 'pending': case 'pending':
$location = add_query_arg( 'message', 6, get_edit_post_link( $page_ID, 'url' ) ); $message = 6;
break; break;
case 'future': case 'future':
$location = add_query_arg( 'message', 7, get_edit_post_link( $page_ID, 'url' ) ); $message = 7;
break; break;
default: default:
$location = add_query_arg( 'message', 5, get_edit_post_link( $page_ID, 'url' ) ); $message = 4;
} }
} else { } else {
$location = add_query_arg( 'message', 1, get_edit_post_link( $page_ID, 'url' ) ); $message = 'draft' == $status ? 8 : 1;
} }
$location = add_query_arg( 'message', $message, get_edit_post_link( $page_ID, 'url' ) );
} elseif ( isset($_POST['addmeta']) ) { } elseif ( isset($_POST['addmeta']) ) {
$location = add_query_arg( 'message', 2, wp_get_referer() ); $location = add_query_arg( 'message', 2, wp_get_referer() );
$location = explode('#', $location); $location = explode('#', $location);

View File

@ -40,7 +40,6 @@ function redirect_post($post_ID = '') {
$location = 'sidebar.php?a=b'; $location = 'sidebar.php?a=b';
} elseif ( isset($_POST['save']) || isset($_POST['publish']) ) { } elseif ( isset($_POST['save']) || isset($_POST['publish']) ) {
$status = get_post_status( $post_ID ); $status = get_post_status( $post_ID );
$link = get_edit_post_link( $post_ID, 'url' );
if ( isset( $_POST['publish'] ) ) { if ( isset( $_POST['publish'] ) ) {
switch ( $status ) { switch ( $status ) {
@ -57,7 +56,7 @@ function redirect_post($post_ID = '') {
$message = 'draft' == $status ? 10 : 1; $message = 'draft' == $status ? 10 : 1;
} }
$location = add_query_arg( 'message', $message, $link ); $location = add_query_arg( 'message', $message, get_edit_post_link( $post_ID, 'url' ) );
} elseif ( isset($_POST['addmeta']) && $_POST['addmeta'] ) { } elseif ( isset($_POST['addmeta']) && $_POST['addmeta'] ) {
$location = add_query_arg( 'message', 2, wp_get_referer() ); $location = add_query_arg( 'message', 2, wp_get_referer() );
$location = explode('#', $location); $location = explode('#', $location);