WordPress 3.0 beta 1 documentation kindly provided to you by Hay Kranen
| [ Index ] |
PHP Cross Reference of WordPress 3.0 beta 1 |
|
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Revisions administration panel. 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9 /** WordPress Administration Bootstrap */ 10 require_once ('admin.php'); 11 12 wp_enqueue_script('list-revisions'); 13 14 wp_reset_vars(array('revision', 'left', 'right', 'diff', 'action')); 15 16 $revision_id = absint($revision); 17 $diff = absint($diff); 18 $left = absint($left); 19 $right = absint($right); 20 21 $redirect = 'edit.php'; 22 23 switch ( $action ) : 24 case 'restore' : 25 if ( !$revision = wp_get_post_revision( $revision_id ) ) 26 break; 27 if ( !current_user_can( 'edit_post', $revision->post_parent ) ) 28 break; 29 if ( !$post = get_post( $revision->post_parent ) ) 30 break; 31 32 if ( ! WP_POST_REVISIONS && !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave 33 break; 34 35 check_admin_referer( "restore-post_$post->ID|$revision->ID" ); 36 37 wp_restore_post_revision( $revision->ID ); 38 $redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) ); 39 break; 40 case 'diff' : 41 if ( !$left_revision = get_post( $left ) ) 42 break; 43 if ( !$right_revision = get_post( $right ) ) 44 break; 45 46 if ( !current_user_can( 'read_post', $left_revision->ID ) || !current_user_can( 'read_post', $right_revision->ID ) ) 47 break; 48 49 // If we're comparing a revision to itself, redirect to the 'view' page for that revision or the edit page for that post 50 if ( $left_revision->ID == $right_revision->ID ) { 51 $redirect = get_edit_post_link( $left_revision->ID ); 52 include ( 'js/revisions-js.php' ); 53 break; 54 } 55 56 // Don't allow reverse diffs? 57 if ( strtotime($right_revision->post_modified_gmt) < strtotime($left_revision->post_modified_gmt) ) { 58 $redirect = add_query_arg( array( 'left' => $right, 'right' => $left ) ); 59 break; 60 } 61 62 if ( $left_revision->ID == $right_revision->post_parent ) // right is a revision of left 63 $post =& $left_revision; 64 elseif ( $left_revision->post_parent == $right_revision->ID ) // left is a revision of right 65 $post =& $right_revision; 66 elseif ( $left_revision->post_parent == $right_revision->post_parent ) // both are revisions of common parent 67 $post = get_post( $left_revision->post_parent ); 68 else 69 break; // Don't diff two unrelated revisions 70 71 if ( ! WP_POST_REVISIONS ) { // Revisions disabled 72 if ( 73 // we're not looking at an autosave 74 ( !wp_is_post_autosave( $left_revision ) && !wp_is_post_autosave( $right_revision ) ) 75 || 76 // we're not comparing an autosave to the current post 77 ( $post->ID !== $left_revision->ID && $post->ID !== $right_revision->ID ) 78 ) 79 break; 80 } 81 82 if ( 83 // They're the same 84 $left_revision->ID == $right_revision->ID 85 || 86 // Neither is a revision 87 ( !wp_get_post_revision( $left_revision->ID ) && !wp_get_post_revision( $right_revision->ID ) ) 88 ) 89 break; 90 91 $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>'; 92 $h2 = sprintf( __( 'Compare Revisions of “%1$s”' ), $post_title ); 93 94 $left = $left_revision->ID; 95 $right = $right_revision->ID; 96 97 $redirect = false; 98 break; 99 case 'view' : 100 default : 101 if ( !$revision = wp_get_post_revision( $revision_id ) ) 102 break; 103 if ( !$post = get_post( $revision->post_parent ) ) 104 break; 105 106 if ( !current_user_can( 'read_post', $revision->ID ) || !current_user_can( 'read_post', $post->ID ) ) 107 break; 108 109 if ( ! WP_POST_REVISIONS && !wp_is_post_autosave( $revision ) ) // Revisions disabled and we're not looking at an autosave 110 break; 111 112 $post_type_object = get_post_type_object($post->post_type); 113 114 $post_title = '<a href="' . get_edit_post_link() . '">' . get_the_title() . '</a>'; 115 $revision_title = wp_post_revision_title( $revision, false ); 116 $h2 = sprintf( __( 'Revision for “%1$s” created on %2$s' ), $post_title, $revision_title ); 117 $title = __( 'Revisions' ); 118 119 // Sets up the diff radio buttons 120 $left = $revision->ID; 121 $right = $post->ID; 122 123 $redirect = false; 124 break; 125 endswitch; 126 127 if ( !$redirect ) { 128 if ( empty($post->post_type) ) // Empty post_type means either malformed object found, or no valid parent was found. 129 $redirect = 'edit.php'; 130 elseif ( !post_type_supports($post->post_type, 'revisions') ) 131 $redirect = 'edit.php?post_type=' . $post->post_type; 132 } 133 134 if ( !empty($redirect) ) { 135 wp_redirect( $redirect ); 136 exit; 137 } 138 139 // This is so that the correct "Edit" menu item is selected. 140 if ( !empty($post->post_type) && 'post' != $post->post_type ) 141 $parent_file = $submenu_file = 'edit.php?post_type=' . $post->post_type; 142 else 143 $parent_file = $submenu_file = 'edit.php'; 144 145 require_once ( 'admin-header.php' ); 146 147 ?> 148 149 <div class="wrap"> 150 151 <h2 class="long-header"><?php echo $h2; ?></h2> 152 153 <table class="form-table ie-fixed"> 154 <col class="th" /> 155 <?php if ( 'diff' == $action ) : ?> 156 <tr id="revision"> 157 <th scope="row"></th> 158 <th scope="col" class="th-full"> 159 <span class="alignleft"><?php printf( __('Older: %s'), wp_post_revision_title( $left_revision ) ); ?></span> 160 <span class="alignright"><?php printf( __('Newer: %s'), wp_post_revision_title( $right_revision ) ); ?></span> 161 </th> 162 </tr> 163 <?php endif; 164 165 // use get_post_to_edit filters? 166 $identical = true; 167 foreach ( _wp_post_revision_fields() as $field => $field_title ) : 168 if ( 'diff' == $action ) { 169 $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field ); 170 $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field ); 171 if ( !$content = wp_text_diff( $left_content, $right_content ) ) 172 continue; // There is no difference between left and right 173 $identical = false; 174 } else { 175 add_filter( "_wp_post_revision_field_$field", 'htmlspecialchars' ); 176 $content = apply_filters( "_wp_post_revision_field_$field", $revision->$field, $field ); 177 } 178 ?> 179 180 <tr id="revision-field-<?php echo $field; ?>"> 181 <th scope="row"><?php echo esc_html( $field_title ); ?></th> 182 <td><div class="pre"><?php echo $content; ?></div></td> 183 </tr> 184 185 <?php 186 187 endforeach; 188 189 if ( 'diff' == $action && $identical ) : 190 191 ?> 192 193 <tr><td colspan="2"><div class="updated"><p><?php _e( 'These revisions are identical.' ); ?></p></div></td></tr> 194 195 <?php 196 197 endif; 198 199 ?> 200 201 </table> 202 203 <br class="clear" /> 204 205 <h2><?php echo $title; ?></h2> 206 207 <?php 208 209 $args = array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left ); 210 if ( ! WP_POST_REVISIONS ) 211 $args['type'] = 'autosave'; 212 213 wp_list_post_revisions( $post, $args ); 214 215 ?> 216 217 </div> 218 219 <?php 220 221 require_once ( 'admin-footer.php' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Apr 5 14:26:09 2010 | Cross-referenced by PHPXref 0.7 |