root/trunk/wp-admin/edit-pages.php

Revision 1525, 10.5 kB (checked in by donncha, 2 days ago)

WP merge with revision 9756

  • Property svn:eol-style set to native
Line 
1 <?php
2 /**
3  * Edit Pages Administration Panel.
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /** WordPress Administration Bootstrap */
10 require_once('admin.php');
11
12 // Handle bulk actions
13 if ( isset($_GET['action']) && ( -1 != $_GET['action'] || -1 != $_GET['action2'] ) ) {
14     $doaction = ( -1 != $_GET['action'] ) ? $_GET['action'] : $_GET['action2'];
15
16     switch ( $doaction ) {
17         case 'delete':
18             if ( isset($_GET['post']) && ! isset($_GET['bulk_edit']) && (isset($_GET['doaction']) || isset($_GET['doaction2'])) ) {
19                 check_admin_referer('bulk-pages');
20                 foreach( (array) $_GET['post'] as $post_id_del ) {
21                     $post_del = & get_post($post_id_del);
22
23                     if ( !current_user_can('delete_page', $post_id_del) )
24                         wp_die( __('You are not allowed to delete this page.') );
25
26                     if ( $post_del->post_type == 'attachment' ) {
27                         if ( ! wp_delete_attachment($post_id_del) )
28                             wp_die( __('Error in deleting...') );
29                     } else {
30                         if ( !wp_delete_post($post_id_del) )
31                             wp_die( __('Error in deleting...') );
32                     }
33                 }
34             }
35             break;
36         case 'edit':
37             if ( isset($_GET['post']) && isset($_GET['bulk_edit']) ) {
38                 check_admin_referer('bulk-pages');
39
40                 if ( -1 == $_GET['_status'] ) {
41                     $_GET['post_status'] = null;
42                     unset($_GET['_status'], $_GET['post_status']);
43                 } else {
44                     $_GET['post_status'] = $_GET['_status'];
45                 }
46
47                 $done = bulk_edit_posts($_GET);
48             }
49             break;
50     }
51
52     $sendback = wp_get_referer();
53     if (strpos($sendback, 'page.php') !== false) $sendback = admin_url('page-new.php');
54     elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
55     $sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback);
56     if ( isset($done) ) {
57         $done['updated'] = count( $done['updated'] );
58         $done['skipped'] = count( $done['skipped'] );
59         $done['locked'] = count( $done['locked'] );
60         $sendback = add_query_arg( $done, $sendback );
61     }
62     wp_redirect($sendback);
63     exit();
64 } elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
65      wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
66      exit;
67 }
68
69 if ( empty($title) )
70     $title = __('Edit Pages');
71 $parent_file = 'edit.php';
72 wp_enqueue_script('inline-edit-post');
73
74 $post_stati  = array(    //    array( adj, noun )
75         'publish' => array(__('Published'), __('Published pages'), __ngettext_noop('Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>')),
76         'future' => array(__('Scheduled'), __('Scheduled pages'), __ngettext_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>')),
77         'pending' => array(__('Pending Review'), __('Pending pages'), __ngettext_noop('Pending Review <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>')),
78         'draft' => array(__('Draft'), _c('Drafts|manage posts header'), __ngettext_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>')),
79         'private' => array(__('Private'), __('Private pages'), __ngettext_noop('<a %s>Private</a> <span class="count">(%s)</span>', '<a %s>Private</a> <span class="count">(%s)</span>'))
80     );
81
82 $query = array('post_type' => 'page', 'orderby' => 'menu_order title', 'what_to_show' => 'posts',
83     'posts_per_page' => -1, 'posts_per_archive_page' => -1, 'order' => 'asc');
84
85 $post_status_label = __('Pages');
86 if ( isset($_GET['post_status']) && in_array( $_GET['post_status'], array_keys($post_stati) ) ) {
87     $post_status_label = $post_stati[$_GET['post_status']][1];
88     $query['post_status'] = $_GET['post_status'];
89     $query['perm'] = 'readable';
90 }
91
92 $query = apply_filters('manage_pages_query', $query);
93 wp($query);
94
95 if ( is_singular() ) {
96     wp_enqueue_script( 'admin-comments' );
97     enqueue_comment_hotkeys_js();
98 }
99
100 require_once('admin-header.php'); ?>
101
102 <div class="wrap">
103 <h2><?php echo wp_specialchars( $title ); ?></h2>
104
105 <?php if ( isset($_GET['locked']) || isset($_GET['skipped']) || isset($_GET['updated']) ) { ?>
106 <div id="message" class="updated fade"><p>
107 <?php if ( (int) $_GET['updated'] ) {
108     printf( __ngettext( '%s page updated.', '%s pages updated.', $_GET['updated'] ), number_format_i18n( $_GET['updated'] ) );
109     unset($_GET['updated']);
110 }
111
112 if ( (int) $_GET['skipped'] ) {
113     printf( __ngettext( '%s page not updated, invalid parent page specified.', '%s pages not updated, invalid parent page specified.', $_GET['skipped'] ), number_format_i18n( $_GET['skipped'] ) );
114     unset($_GET['skipped']);
115 }
116
117 if ( (int) $_GET['locked'] ) {
118     printf( __ngettext( '%s page not updated, somebody is editing it.', '%s pages not updated, somebody is editing them.', $_GET['locked'] ), number_format_i18n( $_GET['skipped'] ) );
119     unset($_GET['locked']);
120 }
121 $_SERVER['REQUEST_URI'] = remove_query_arg( array('locked', 'skipped', 'updated'), $_SERVER['REQUEST_URI'] );
122 ?>
123 </p></div>
124 <?php } ?>
125
126 <?php if ( isset($_GET['posted']) && $_GET['posted'] ) : $_GET['posted'] = (int) $_GET['posted']; ?>
127 <div id="message" class="updated fade"><p><strong><?php _e('Your page has been saved.'); ?></strong> <a href="<?php echo get_permalink( $_GET['posted'] ); ?>"><?php _e('View page'); ?></a> | <a href="<?php echo get_edit_post_link( $_GET['posted'] ); ?>"><?php _e('Edit page'); ?></a></p></div>
128 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('posted'), $_SERVER['REQUEST_URI']);
129 endif; ?>
130
131 <form id="posts-filter" action="" method="get">
132 <ul class="subsubsub">
133 <?php
134
135 $avail_post_stati = get_available_post_statuses('page');
136 if ( empty($locked_post_status) ) :
137 $status_links = array();
138 $num_posts = wp_count_posts('page', 'readable');
139 $total_posts = array_sum( (array) $num_posts );
140 $class = empty($_GET['post_status']) ? ' class="current"' : '';
141 $status_links[] = "<li><a href='edit-pages.php'$class>" . sprintf( __ngettext( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts ), number_format_i18n( $total_posts ) ) . '</a>';
142 foreach ( $post_stati as $status => $label ) {
143     $class = '';
144
145     if ( !in_array($status, $avail_post_stati) )
146         continue;
147
148     if ( isset( $_GET['post_status'] ) && $status == $_GET['post_status'] )
149         $class = ' class="current"';
150
151     $status_links[] = "<li><a href='edit-pages.php?post_status=$status'$class>" . sprintf( __ngettext( $label[2][0], $label[2][1], $num_posts->$status ), number_format_i18n( $num_posts->$status ) ) . '</a>';
152 }
153 echo implode( " |</li>\n", $status_links ) . '</li>';
154 unset($status_links);
155 endif;
156 ?>
157 </ul>
158
159 <p class="search-box">
160     <label class="hidden" for="page-search-input"><?php _e( 'Search Pages' ); ?>:</label>
161     <input type="text" class="search-input" id="page-search-input" name="s" value="<?php _admin_search_query(); ?>" />
162     <input type="submit" value="<?php _e( 'Search Pages' ); ?>" class="button" />
163 </p>
164
165 <?php if ( isset($_GET['post_status'] ) ) : ?>
166 <input type="hidden" name="post_status" value="<?php echo attribute_escape($_GET['post_status']) ?>" />
167 <?php endif; ?>
168
169 <div class="tablenav">
170
171 <?php
172 $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 0;
173 if ( empty($pagenum) )
174     $pagenum = 1;
175 if( ! isset( $per_page ) || $per_page < 0 )
176     $per_page = 20;
177
178 $num_pages = ceil($wp_query->post_count / $per_page);
179 $page_links = paginate_links( array(
180     'base' => add_query_arg( 'pagenum', '%#%' ),
181     'format' => '',
182     'prev_text' => __('&larr;'),
183     'next_text' => __('&rarr;'),
184     'total' => $num_pages,
185     'current' => $pagenum
186 ));
187
188 if ( $page_links ) : ?>
189 <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
190     number_format_i18n( ( $pagenum - 1 ) * $per_page + 1 ),
191     number_format_i18n( min( $pagenum * $per_page, $wp_query->post_count ) ),
192     number_format_i18n( $wp_query->post_count ),
193     $page_links
194 ); echo $page_links_text; ?></div>
195 <?php endif; ?>
196
197 <div class="alignleft actions">
198 <select name="action">
199 <option value="-1" selected="selected"><?php _e('Actions'); ?></option>
200 <option value="edit"><?php _e('Edit'); ?></option>
201 <option value="delete"><?php _e('Delete'); ?></option>
202 </select>
203 <input type="submit" value="<?php _e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
204 <?php wp_nonce_field('bulk-pages'); ?>
205 </div>
206
207 <br class="clear" />
208 </div>
209
210 <div class="clear"></div>
211
212 <?php
213
214 if ($posts) {
215 ?>
216 <table class="widefat page fixed" cellspacing="0">
217   <thead>
218   <tr>
219 <?php print_column_headers('edit-pages'); ?>
220   </tr>
221   </thead>
222
223   <tfoot>
224   <tr>
225 <?php print_column_headers('edit-pages', false); ?>
226   </tr>
227   </tfoot>
228
229   <tbody>
230   <?php page_rows($posts, $pagenum, $per_page); ?>
231   </tbody>
232 </table>
233
234 <div class="tablenav">
235 <?php
236 if ( $page_links )
237     echo "<div class='tablenav-pages'>$page_links_text</div>";
238 ?>
239
240 <div class="alignleft actions">
241 <select name="action2">
242 <option value="-1" selected="selected"><?php _e('Actions'); ?></option>
243 <option value="edit"><?php _e('Edit'); ?></option>
244 <option value="delete"><?php _e('Delete'); ?></option>
245 </select>
246 <input type="submit" value="<?php _e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
247 </div>
248
249 <br class="clear" />
250 </div>
251
252 </form>
253
254 <?php inline_edit_row( 'page' ) ?>
255
256 <div id="ajax-response"></div>
257
258 <?php
259 } else {
260 ?>
261 </form>
262 <p><?php _e('No pages found.') ?></p>
263 <?php
264 } // end if ($posts)
265 ?>
266
267
268 <?php
269
270 if ( 1 == count($posts) && is_singular() ) :
271
272     $comments = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved != 'spam' ORDER BY comment_date", $id) );
273     if ( $comments ) :
274         // Make sure comments, post, and post_author are cached
275         update_comment_cache($comments);
276         $post = get_post($id);
277         $authordata = get_userdata($post->post_author);
278     ?>
279
280 <br class="clear" />
281
282 <table class="widefat" cellspacing="0">
283 <thead>
284   <tr>
285     <th scope="col" class="column-comment"><?php _e('Comment') ?></th>
286     <th scope="col" class="column-author"><?php _e('Author') ?></th>
287     <th scope="col" class="column-date"><?php _e('Submitted') ?></th>
288   </tr>
289 </thead>
290 <tbody id="the-comment-list" class="list:comment">
291 <?php
292     foreach ($comments as $comment)
293         _wp_comment_row( $comment->comment_ID, 'single', false, false );
294 ?>
295 </tbody>
296 </table>
297
298 <?php
299 wp_comment_reply();
300 endif; // comments
301 endif; // posts;
302
303 ?>
304
305 </div>
306
307 <script type="text/javascript">
308 /* <![CDATA[ */
309 (function($){
310     $(document).ready(function(){
311         $('#doaction, #doaction2').click(function(){
312             if ( $('select[name^="action"]').val() == 'delete' ) {
313                 var m = '<?php echo js_escape(__("You are about to delete the selected pages.\n  'Cancel' to stop, 'OK' to delete.")); ?>';
314                 return showNotice.warn(m);
315             }
316         });
317     });
318 })(jQuery);
319 columns.init('edit-pages');
320 /* ]]> */
321 </script>
322
323 <?php include('admin-footer.php'); ?>
324
Note: See TracBrowser for help on using the browser.