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