~canonical-sysadmins/wordpress/3.9.x

« back to all changes in this revision

Viewing changes to wp-admin/edit-pages.php

  • Committer: Chris Jones
  • Date: 2010-01-19 13:17:33 UTC
  • Revision ID: cmsj@tenshu.net-20100119131733-rf31jv9k1v0xzo2h
[CJ] Import wordpress 2.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
        wp_die(__('Cheatin’ uh?'));
14
14
 
15
15
// Handle bulk actions
16
 
if ( isset($_GET['action']) && ( -1 != $_GET['action'] || -1 != $_GET['action2'] ) ) {
17
 
        $doaction = ( -1 != $_GET['action'] ) ? $_GET['action'] : $_GET['action2'];
 
16
if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) || isset($_GET['bulk_edit']) ) {
 
17
        check_admin_referer('bulk-pages');
 
18
        $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() );
 
19
 
 
20
        if ( strpos($sendback, 'page.php') !== false )
 
21
                $sendback = admin_url('page-new.php');
 
22
 
 
23
        if ( isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) {
 
24
                $post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_GET['post_status']);
 
25
                $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = %s", $post_status ) );
 
26
                $doaction = 'delete';
 
27
        } elseif ( ( $_GET['action'] != -1 || $_GET['action2'] != -1 ) && ( isset($_GET['post']) || isset($_GET['ids']) ) ) {
 
28
                $post_ids = isset($_GET['post']) ? array_map( 'intval', (array) $_GET['post'] ) : explode(',', $_GET['ids']);
 
29
                $doaction = ($_GET['action'] != -1) ? $_GET['action'] : $_GET['action2'];
 
30
        } else {
 
31
                wp_redirect( admin_url('edit-pages.php') );
 
32
        }
18
33
 
19
34
        switch ( $doaction ) {
 
35
                case 'trash':
 
36
                        $trashed = 0;
 
37
                        foreach( (array) $post_ids as $post_id ) {
 
38
                                if ( !current_user_can('delete_page', $post_id) )
 
39
                                        wp_die( __('You are not allowed to move this page to the trash.') );
 
40
 
 
41
                                if ( !wp_trash_post($post_id) )
 
42
                                        wp_die( __('Error in moving to trash...') );
 
43
 
 
44
                                $trashed++;
 
45
                        }
 
46
                        $sendback = add_query_arg( array('trashed' => $trashed, 'ids' => join(',', $post_ids)), $sendback );
 
47
                        break;
 
48
                case 'untrash':
 
49
                        $untrashed = 0;
 
50
                        foreach( (array) $post_ids as $post_id ) {
 
51
                                if ( !current_user_can('delete_page', $post_id) )
 
52
                                        wp_die( __('You are not allowed to restore this page from the trash.') );
 
53
 
 
54
                                if ( !wp_untrash_post($post_id) )
 
55
                                        wp_die( __('Error in restoring from trash...') );
 
56
 
 
57
                                $untrashed++;
 
58
                        }
 
59
                        $sendback = add_query_arg('untrashed', $untrashed, $sendback);
 
60
                        break;
20
61
                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++;
 
62
                        $deleted = 0;
 
63
                        foreach( (array) $post_ids as $post_id ) {
 
64
                                $post_del = & get_post($post_id);
 
65
 
 
66
                                if ( !current_user_can('delete_page', $post_id) )
 
67
                                        wp_die( __('You are not allowed to delete this page.') );
 
68
 
 
69
                                if ( $post_del->post_type == 'attachment' ) {
 
70
                                        if ( ! wp_delete_attachment($post_id) )
 
71
                                                wp_die( __('Error in deleting...') );
 
72
                                } else {
 
73
                                        if ( !wp_delete_post($post_id) )
 
74
                                                wp_die( __('Error in deleting...') );
38
75
                                }
 
76
                                $deleted++;
39
77
                        }
 
78
                        $sendback = add_query_arg('deleted', $deleted, $sendback);
40
79
                        break;
41
80
                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);
 
81
                        $_GET['post_type'] = 'page';
 
82
                        $done = bulk_edit_posts($_GET);
 
83
 
 
84
                        if ( is_array($done) ) {
 
85
                                $done['updated'] = count( $done['updated'] );
 
86
                                $done['skipped'] = count( $done['skipped'] );
 
87
                                $done['locked'] = count( $done['locked'] );
 
88
                                $sendback = add_query_arg( $done, $sendback );
53
89
                        }
54
90
                        break;
55
91
        }
56
92
 
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);
 
93
        if ( isset($_GET['action']) )
 
94
                $sendback = remove_query_arg( array('action', 'action2', 'post_parent', 'page_template', 'post_author', 'comment_status', 'ping_status', '_status',  'post', 'bulk_edit', 'post_view', 'post_type'), $sendback );
 
95
 
68
96
        wp_redirect($sendback);
69
97
        exit();
70
98
} elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
82
110
                'future' => array(_x('Scheduled', 'page'), __('Scheduled pages'), _nx_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>', 'page')),
83
111
                '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
112
                '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'))
 
113
                'private' => array(_x('Private', 'page'), __('Private pages'), _nx_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>', 'page')),
 
114
                'trash' => array(_x('Trash', 'page'), __('Trash pages'), _nx_noop('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>', 'page'))
86
115
        );
87
116
 
 
117
if ( !EMPTY_TRASH_DAYS )
 
118
        unset($post_stati['trash']);
 
119
 
88
120
$post_stati = apply_filters('page_stati', $post_stati);
89
121
 
90
122
$query = array('post_type' => 'page', 'orderby' => 'menu_order title',
109
141
 
110
142
<div class="wrap">
111
143
<?php screen_icon(); ?>
112
 
<h2><?php echo esc_html( $title );
 
144
<h2><?php echo esc_html( $title ); ?> <a href="page-new.php" class="button add-new-h2"><?php echo esc_html_x('Add New', 'page'); ?></a> <?php
113
145
if ( isset($_GET['s']) && $_GET['s'] )
114
146
        printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( get_search_query() ) ); ?>
115
147
</h2>
116
148
 
117
 
<?php if ( isset($_GET['locked']) || isset($_GET['skipped']) || isset($_GET['updated']) || isset($_GET['deleted']) ) { ?>
 
149
<?php if ( isset($_GET['locked']) || isset($_GET['skipped']) || isset($_GET['updated']) || isset($_GET['deleted']) || isset($_GET['trashed']) || isset($_GET['untrashed']) ) { ?>
118
150
<div id="message" class="updated fade"><p>
119
151
<?php if ( isset($_GET['updated']) && (int) $_GET['updated'] ) {
120
152
        printf( _n( '%s page updated.', '%s pages updated.', $_GET['updated'] ), number_format_i18n( $_GET['updated'] ) );
121
153
        unset($_GET['updated']);
122
154
}
123
 
 
124
155
if ( isset($_GET['skipped']) && (int) $_GET['skipped'] ) {
125
156
        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
157
        unset($_GET['skipped']);
127
158
}
128
 
 
129
159
if ( isset($_GET['locked']) && (int) $_GET['locked'] ) {
130
160
        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
161
        unset($_GET['locked']);
132
162
}
133
 
 
134
163
if ( isset($_GET['deleted']) && (int) $_GET['deleted'] ) {
135
 
        printf( _n( 'Page deleted.', '%s pages deleted.', $_GET['deleted'] ), number_format_i18n( $_GET['deleted'] ) );
 
164
        printf( _n( 'Page permanently deleted.', '%s pages permanently deleted.', $_GET['deleted'] ), number_format_i18n( $_GET['deleted'] ) );
136
165
        unset($_GET['deleted']);
137
166
}
138
 
$_SERVER['REQUEST_URI'] = remove_query_arg( array('locked', 'skipped', 'updated', 'deleted'), $_SERVER['REQUEST_URI'] );
 
167
if ( isset($_GET['trashed']) && (int) $_GET['trashed'] ) {
 
168
        printf( _n( 'Page moved to the trash.', '%s pages moved to the trash.', $_GET['trashed'] ), number_format_i18n( $_GET['trashed'] ) );
 
169
        $ids = isset($_GET['ids']) ? $_GET['ids'] : 0;
 
170
        echo ' <a href="' . esc_url( wp_nonce_url( "edit-pages.php?doaction=undo&action=untrash&ids=$ids", "bulk-pages" ) ) . '">' . __('Undo') . '</a><br />';
 
171
        unset($_GET['trashed']);
 
172
}
 
173
if ( isset($_GET['untrashed']) && (int) $_GET['untrashed'] ) {
 
174
        printf( _n( 'Page restored from the trash.', '%s pages restored from the trash.', $_GET['untrashed'] ), number_format_i18n( $_GET['untrashed'] ) );
 
175
        unset($_GET['untrashed']);
 
176
}
 
177
$_SERVER['REQUEST_URI'] = remove_query_arg( array('locked', 'skipped', 'updated', 'deleted', 'trashed', 'untrashed'), $_SERVER['REQUEST_URI'] );
139
178
?>
140
179
</p></div>
141
180
<?php } ?>
145
184
<?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('posted'), $_SERVER['REQUEST_URI']);
146
185
endif; ?>
147
186
 
148
 
<form id="posts-filter" action="" method="get">
 
187
<form id="posts-filter" action="<?php echo admin_url('edit-pages.php'); ?>" method="get">
149
188
<ul class="subsubsub">
150
189
<?php
151
190
 
153
192
if ( empty($locked_post_status) ) :
154
193
$status_links = array();
155
194
$num_posts = wp_count_posts('page', 'readable');
156
 
$total_posts = array_sum( (array) $num_posts );
 
195
$total_posts = array_sum( (array) $num_posts ) - $num_posts->trash;
157
196
$class = empty($_GET['post_status']) ? ' class="current"' : '';
158
197
$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
198
foreach ( $post_stati as $status => $label ) {
160
199
        $class = '';
161
200
 
162
 
        if ( !in_array($status, $avail_post_stati) )
 
201
        if ( !in_array($status, $avail_post_stati) || $num_posts->$status <= 0 )
163
202
                continue;
164
203
 
165
204
        if ( isset( $_GET['post_status'] ) && $status == $_GET['post_status'] )
179
218
        <input type="submit" value="<?php esc_attr_e( 'Search Pages' ); ?>" class="button" />
180
219
</p>
181
220
 
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; ?>
 
221
<input type="hidden" name="post_status" class="post_status_page" value="<?php echo !empty($_GET['post_status']) ? esc_attr($_GET['post_status']) : 'all'; ?>" />
185
222
 
186
223
<?php if ($posts) { ?>
187
224
 
191
228
$pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 0;
192
229
if ( empty($pagenum) )
193
230
        $pagenum = 1;
194
 
$per_page = get_user_option('edit_pages_per_page');
195
 
if ( empty( $per_page ) || $per_page < 0 )
 
231
$per_page = (int) get_user_option( 'edit_pages_per_page', 0, false );
 
232
if ( empty( $per_page ) || $per_page < 1 )
196
233
        $per_page = 20;
 
234
$per_page = apply_filters( 'edit_pages_per_page', $per_page );
197
235
 
198
236
$num_pages = ceil($wp_query->post_count / $per_page);
199
237
$page_links = paginate_links( array(
205
243
        'current' => $pagenum
206
244
));
207
245
 
 
246
$is_trash = isset($_GET['post_status']) && $_GET['post_status'] == 'trash';
 
247
 
208
248
if ( $page_links ) : ?>
209
249
<div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
210
250
        number_format_i18n( ( $pagenum - 1 ) * $per_page + 1 ),
217
257
<div class="alignleft actions">
218
258
<select name="action">
219
259
<option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
 
260
<?php if ( $is_trash ) { ?>
 
261
<option value="untrash"><?php _e('Restore'); ?></option>
 
262
<?php } else { ?>
220
263
<option value="edit"><?php _e('Edit'); ?></option>
221
 
<option value="delete"><?php _e('Delete'); ?></option>
 
264
<?php } if ( $is_trash || !EMPTY_TRASH_DAYS ) { ?>
 
265
<option value="delete"><?php _e('Delete Permanently'); ?></option>
 
266
<?php } else { ?>
 
267
<option value="trash"><?php _e('Move to Trash'); ?></option>
 
268
<?php } ?>
222
269
</select>
223
270
<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
224
271
<?php wp_nonce_field('bulk-pages'); ?>
 
272
<?php if ( $is_trash ) { ?>
 
273
<input type="submit" name="delete_all" id="delete_all" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
 
274
<?php } ?>
225
275
</div>
226
276
 
227
277
<br class="clear" />
256
306
<div class="alignleft actions">
257
307
<select name="action2">
258
308
<option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
 
309
<?php if ( $is_trash ) { ?>
 
310
<option value="untrash"><?php _e('Restore'); ?></option>
 
311
<?php } else { ?>
259
312
<option value="edit"><?php _e('Edit'); ?></option>
260
 
<option value="delete"><?php _e('Delete'); ?></option>
 
313
<?php } if ( $is_trash || !EMPTY_TRASH_DAYS ) { ?>
 
314
<option value="delete"><?php _e('Delete Permanently'); ?></option>
 
315
<?php } else { ?>
 
316
<option value="trash"><?php _e('Move to Trash'); ?></option>
 
317
<?php } ?>
261
318
</select>
262
319
<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
 
320
<?php if ( $is_trash ) { ?>
 
321
<input type="submit" name="delete_all2" id="delete_all2" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
 
322
<?php } ?>
263
323
</div>
264
324
 
265
325
<br class="clear" />