]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/upload.php
WordPress 4.4.1
[autoinstalls/wordpress.git] / wp-admin / upload.php
1 <?php
2 /**
3  * Media Library administration panel.
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /** WordPress Administration Bootstrap */
10 require_once( dirname( __FILE__ ) . '/admin.php' );
11
12 if ( !current_user_can('upload_files') )
13         wp_die( __( 'You do not have permission to upload files.' ) );
14
15 $mode = get_user_option( 'media_library_mode', get_current_user_id() ) ? get_user_option( 'media_library_mode', get_current_user_id() ) : 'grid';
16 $modes = array( 'grid', 'list' );
17
18 if ( isset( $_GET['mode'] ) && in_array( $_GET['mode'], $modes ) ) {
19         $mode = $_GET['mode'];
20         update_user_option( get_current_user_id(), 'media_library_mode', $mode );
21 }
22
23 if ( 'grid' === $mode ) {
24         wp_enqueue_media();
25         wp_enqueue_script( 'media-grid' );
26         wp_enqueue_script( 'media' );
27
28         remove_action( 'admin_head', 'wp_admin_canonical_url' );
29
30         $q = $_GET;
31         // let JS handle this
32         unset( $q['s'] );
33         $vars = wp_edit_attachments_query_vars( $q );
34         $ignore = array( 'mode', 'post_type', 'post_status', 'posts_per_page' );
35         foreach ( $vars as $key => $value ) {
36                 if ( ! $value || in_array( $key, $ignore ) ) {
37                         unset( $vars[ $key ] );
38                 }
39         }
40
41         wp_localize_script( 'media-grid', '_wpMediaGridSettings', array(
42                 'adminUrl' => parse_url( self_admin_url(), PHP_URL_PATH ),
43                 'queryVars' => (object) $vars
44         ) );
45
46         get_current_screen()->add_help_tab( array(
47                 'id'            => 'overview',
48                 'title'         => __( 'Overview' ),
49                 'content'       =>
50                         '<p>' . __( 'All the files you&#8217;ve uploaded are listed in the Media Library, with the most recent uploads listed first.' ) . '</p>' .
51                         '<p>' . __( 'You can view your media in a simple visual grid or a list with columns. Switch between these views using the icons to the left above the media.' ) . '</p>' .
52                         '<p>' . __( 'To delete media items, click the Bulk Select button at the top of the screen. Select any items you wish to delete, then click the Delete Selected button. Clicking the Cancel Selection button takes you back to viewing your media.' ) . '</p>'
53         ) );
54
55         get_current_screen()->add_help_tab( array(
56                 'id'            => 'attachment-details',
57                 'title'         => __( 'Attachment Details' ),
58                 'content'       =>
59                         '<p>' . __( 'Clicking an item will display an Attachment Details dialog, which allows you to preview media and make quick edits. Any changes you make to the attachment details will be automatically saved.' ) . '</p>' .
60                         '<p>' . __( 'Use the arrow buttons at the top of the dialog, or the left and right arrow keys on your keyboard, to navigate between media items quickly.' ) . '</p>' .
61                         '<p>' . __( 'You can also delete individual items and access the extended edit screen from the details dialog.' ) . '</p>'
62         ) );
63
64         get_current_screen()->set_help_sidebar(
65                 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
66                 '<p>' . __( '<a href="https://codex.wordpress.org/Media_Library_Screen" target="_blank">Documentation on Media Library</a>' ) . '</p>' .
67                 '<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
68         );
69
70         $title = __('Media Library');
71         $parent_file = 'upload.php';
72
73         require_once( ABSPATH . 'wp-admin/admin-header.php' );
74         ?>
75         <div class="wrap" id="wp-media-grid" data-search="<?php _admin_search_query() ?>">
76                 <h1>
77                 <?php
78                 echo esc_html( $title );
79                 if ( current_user_can( 'upload_files' ) ) { ?>
80                         <a href="media-new.php" class="page-title-action"><?php echo esc_html_x( 'Add New', 'file' ); ?></a><?php
81                 }
82                 ?>
83                 </h1>
84                 <div class="error hide-if-js">
85                         <p><?php _e( 'The grid view for the Media Library requires JavaScript. <a href="upload.php?mode=list">Switch to the list view</a>.' ); ?></p>
86                 </div>
87         </div>
88         <?php
89         include( ABSPATH . 'wp-admin/admin-footer.php' );
90         exit;
91 }
92
93 $wp_list_table = _get_list_table('WP_Media_List_Table');
94 $pagenum = $wp_list_table->get_pagenum();
95
96 // Handle bulk actions
97 $doaction = $wp_list_table->current_action();
98
99 if ( $doaction ) {
100         check_admin_referer('bulk-media');
101
102         if ( 'delete_all' == $doaction ) {
103                 $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" );
104                 $doaction = 'delete';
105         } elseif ( isset( $_REQUEST['media'] ) ) {
106                 $post_ids = $_REQUEST['media'];
107         } elseif ( isset( $_REQUEST['ids'] ) ) {
108                 $post_ids = explode( ',', $_REQUEST['ids'] );
109         }
110
111         $location = 'upload.php';
112         if ( $referer = wp_get_referer() ) {
113                 if ( false !== strpos( $referer, 'upload.php' ) )
114                         $location = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'message', 'ids', 'posted' ), $referer );
115         }
116
117         switch ( $doaction ) {
118                 case 'detach':
119                         wp_media_attach_action( $_REQUEST['parent_post_id'], 'detach' );
120                         break;
121
122                 case 'attach':
123                         wp_media_attach_action( $_REQUEST['found_post_id'] );
124                         break;
125
126                 case 'trash':
127                         if ( !isset( $post_ids ) )
128                                 break;
129                         foreach ( (array) $post_ids as $post_id ) {
130                                 if ( !current_user_can( 'delete_post', $post_id ) )
131                                         wp_die( __( 'You are not allowed to move this item to the Trash.' ) );
132
133                                 if ( !wp_trash_post( $post_id ) )
134                                         wp_die( __( 'Error in moving to Trash.' ) );
135                         }
136                         $location = add_query_arg( array( 'trashed' => count( $post_ids ), 'ids' => join( ',', $post_ids ) ), $location );
137                         break;
138                 case 'untrash':
139                         if ( !isset( $post_ids ) )
140                                 break;
141                         foreach ( (array) $post_ids as $post_id ) {
142                                 if ( !current_user_can( 'delete_post', $post_id ) )
143                                         wp_die( __( 'You are not allowed to move this item out of the Trash.' ) );
144
145                                 if ( !wp_untrash_post( $post_id ) )
146                                         wp_die( __( 'Error in restoring from Trash.' ) );
147                         }
148                         $location = add_query_arg( 'untrashed', count( $post_ids ), $location );
149                         break;
150                 case 'delete':
151                         if ( !isset( $post_ids ) )
152                                 break;
153                         foreach ( (array) $post_ids as $post_id_del ) {
154                                 if ( !current_user_can( 'delete_post', $post_id_del ) )
155                                         wp_die( __( 'You are not allowed to delete this item.' ) );
156
157                                 if ( !wp_delete_attachment( $post_id_del ) )
158                                         wp_die( __( 'Error in deleting.' ) );
159                         }
160                         $location = add_query_arg( 'deleted', count( $post_ids ), $location );
161                         break;
162         }
163
164         wp_redirect( $location );
165         exit;
166 } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
167          wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
168          exit;
169 }
170
171 $wp_list_table->prepare_items();
172
173 $title = __('Media Library');
174 $parent_file = 'upload.php';
175
176 wp_enqueue_script( 'media' );
177
178 add_screen_option( 'per_page' );
179
180 get_current_screen()->add_help_tab( array(
181 'id'            => 'overview',
182 'title'         => __('Overview'),
183 'content'       =>
184         '<p>' . __( 'All the files you&#8217;ve uploaded are listed in the Media Library, with the most recent uploads listed first. You can use the Screen Options tab to customize the display of this screen.' ) . '</p>' .
185         '<p>' . __( 'You can narrow the list by file type/status using the text link filters at the top of the screen. You also can refine the list by date using the dropdown menu above the media table.' ) . '</p>' .
186         '<p>' . __( 'You can view your media in a simple visual grid or a list with columns. Switch between these views using the icons to the left above the media.' ) . '</p>'
187 ) );
188 get_current_screen()->add_help_tab( array(
189 'id'            => 'actions-links',
190 'title'         => __('Available Actions'),
191 'content'       =>
192         '<p>' . __( 'Hovering over a row reveals action links: Edit, Delete Permanently, and View. Clicking Edit or on the media file&#8217;s name displays a simple screen to edit that individual file&#8217;s metadata. Clicking Delete Permanently will delete the file from the media library (as well as from any posts to which it is currently attached). View will take you to the display page for that file.' ) . '</p>'
193 ) );
194 get_current_screen()->add_help_tab( array(
195 'id'            => 'attaching-files',
196 'title'         => __('Attaching Files'),
197 'content'       =>
198         '<p>' . __( 'If a media file has not been attached to any post, you will see that in the Attached To column, and can click on Attach File to launch a small popup that will allow you to search for a post and attach the file.' ) . '</p>'
199 ) );
200
201 get_current_screen()->set_help_sidebar(
202         '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
203         '<p>' . __( '<a href="https://codex.wordpress.org/Media_Library_Screen" target="_blank">Documentation on Media Library</a>' ) . '</p>' .
204         '<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
205 );
206
207 get_current_screen()->set_screen_reader_content( array(
208         'heading_views'      => __( 'Filter media items list' ),
209         'heading_pagination' => __( 'Media items list navigation' ),
210         'heading_list'       => __( 'Media items list' ),
211 ) );
212
213 require_once( ABSPATH . 'wp-admin/admin-header.php' );
214 ?>
215
216 <div class="wrap">
217 <h1>
218 <?php
219 echo esc_html( $title );
220 if ( current_user_can( 'upload_files' ) ) { ?>
221         <a href="media-new.php" class="page-title-action"><?php echo esc_html_x('Add New', 'file'); ?></a><?php
222 }
223 if ( ! empty( $_REQUEST['s'] ) )
224         printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', get_search_query() ); ?>
225 </h1>
226
227 <?php
228 $message = '';
229 if ( ! empty( $_GET['posted'] ) ) {
230         $message = __( 'Media attachment updated.' );
231         $_SERVER['REQUEST_URI'] = remove_query_arg(array('posted'), $_SERVER['REQUEST_URI']);
232 }
233
234 if ( ! empty( $_GET['attached'] ) && $attached = absint( $_GET['attached'] ) ) {
235         $message = sprintf( _n( 'Reattached %d attachment.', 'Reattached %d attachments.', $attached ), $attached );
236         $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] );
237 }
238
239 if ( ! empty( $_GET['detach'] ) && $detached = absint( $_GET['detach'] ) ) {
240         $message = sprintf( _n( 'Detached %d attachment.', 'Detached %d attachments.', $detached ), $detached );
241         $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] );
242 }
243
244 if ( ! empty( $_GET['deleted'] ) && $deleted = absint( $_GET['deleted'] ) ) {
245         if ( 1 == $deleted ) {
246                 $message = __( 'Media attachment permanently deleted.' );
247         } else {
248                 $message = _n( '%d media attachment permanently deleted.', '%d media attachments permanently deleted.', $deleted );
249         }
250         $message = sprintf( $message, number_format_i18n( $deleted ) );
251         $_SERVER['REQUEST_URI'] = remove_query_arg(array('deleted'), $_SERVER['REQUEST_URI']);
252 }
253
254 if ( ! empty( $_GET['trashed'] ) && $trashed = absint( $_GET['trashed'] ) ) {
255         if ( 1 == $trashed ) {
256                 $message = __( 'Media attachment moved to the trash.' );
257         } else {
258                 $message = _n( '%d media attachment moved to the trash.', '%d media attachments moved to the trash.', $trashed );
259         }
260         $message = sprintf( $message, number_format_i18n( $trashed ) );
261         $message .= ' <a href="' . esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids='.(isset($_GET['ids']) ? $_GET['ids'] : ''), "bulk-media" ) ) . '">' . __('Undo') . '</a>';
262         $_SERVER['REQUEST_URI'] = remove_query_arg(array('trashed'), $_SERVER['REQUEST_URI']);
263 }
264
265 if ( ! empty( $_GET['untrashed'] ) && $untrashed = absint( $_GET['untrashed'] ) ) {
266         if ( 1 == $untrashed ) {
267                 $message = __( 'Media attachment restored from the trash.' );
268         } else {
269                 $message = _n( '%d media attachment restored from the trash.', '%d media attachments restored from the trash.', $untrashed );
270         }
271         $message = sprintf( $message, number_format_i18n( $untrashed ) );
272         $_SERVER['REQUEST_URI'] = remove_query_arg(array('untrashed'), $_SERVER['REQUEST_URI']);
273 }
274
275 $messages[1] = __( 'Media attachment updated.' );
276 $messages[2] = __( 'Media attachment permanently deleted.' );
277 $messages[3] = __( 'Error saving media attachment.' );
278 $messages[4] = __( 'Media attachment moved to the trash.' ) . ' <a href="' . esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids='.(isset($_GET['ids']) ? $_GET['ids'] : ''), "bulk-media" ) ) . '">' . __( 'Undo' ) . '</a>';
279 $messages[5] = __( 'Media attachment restored from the trash.' );
280
281 if ( ! empty( $_GET['message'] ) && isset( $messages[ $_GET['message'] ] ) ) {
282         $message = $messages[ $_GET['message'] ];
283         $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
284 }
285
286 if ( !empty($message) ) { ?>
287 <div id="message" class="updated notice is-dismissible"><p><?php echo $message; ?></p></div>
288 <?php } ?>
289
290 <form id="posts-filter" method="get">
291
292 <?php $wp_list_table->views(); ?>
293
294 <?php $wp_list_table->display(); ?>
295
296 <div id="ajax-response"></div>
297 <?php find_posts_div(); ?>
298 </form>
299 </div>
300
301 <?php
302 include( ABSPATH . 'wp-admin/admin-footer.php' );