]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/upload.php
WordPress 4.5-scripts
[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="<?php echo admin_url( '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 printf(
86                                 /* translators: %s: list view URL */
87                                 __( 'The grid view for the Media Library requires JavaScript. <a href="%s">Switch to the list view</a>.' ),
88                                 'upload.php?mode=list'
89                         ); ?></p>
90                 </div>
91         </div>
92         <?php
93         include( ABSPATH . 'wp-admin/admin-footer.php' );
94         exit;
95 }
96
97 $wp_list_table = _get_list_table('WP_Media_List_Table');
98 $pagenum = $wp_list_table->get_pagenum();
99
100 // Handle bulk actions
101 $doaction = $wp_list_table->current_action();
102
103 if ( $doaction ) {
104         check_admin_referer('bulk-media');
105
106         if ( 'delete_all' == $doaction ) {
107                 $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" );
108                 $doaction = 'delete';
109         } elseif ( isset( $_REQUEST['media'] ) ) {
110                 $post_ids = $_REQUEST['media'];
111         } elseif ( isset( $_REQUEST['ids'] ) ) {
112                 $post_ids = explode( ',', $_REQUEST['ids'] );
113         }
114
115         $location = 'upload.php';
116         if ( $referer = wp_get_referer() ) {
117                 if ( false !== strpos( $referer, 'upload.php' ) )
118                         $location = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'message', 'ids', 'posted' ), $referer );
119         }
120
121         switch ( $doaction ) {
122                 case 'detach':
123                         wp_media_attach_action( $_REQUEST['parent_post_id'], 'detach' );
124                         break;
125
126                 case 'attach':
127                         wp_media_attach_action( $_REQUEST['found_post_id'] );
128                         break;
129
130                 case 'trash':
131                         if ( !isset( $post_ids ) )
132                                 break;
133                         foreach ( (array) $post_ids as $post_id ) {
134                                 if ( !current_user_can( 'delete_post', $post_id ) )
135                                         wp_die( __( 'You are not allowed to move this item to the Trash.' ) );
136
137                                 if ( !wp_trash_post( $post_id ) )
138                                         wp_die( __( 'Error in moving to Trash.' ) );
139                         }
140                         $location = add_query_arg( array( 'trashed' => count( $post_ids ), 'ids' => join( ',', $post_ids ) ), $location );
141                         break;
142                 case 'untrash':
143                         if ( !isset( $post_ids ) )
144                                 break;
145                         foreach ( (array) $post_ids as $post_id ) {
146                                 if ( !current_user_can( 'delete_post', $post_id ) )
147                                         wp_die( __( 'You are not allowed to move this item out of the Trash.' ) );
148
149                                 if ( !wp_untrash_post( $post_id ) )
150                                         wp_die( __( 'Error in restoring from Trash.' ) );
151                         }
152                         $location = add_query_arg( 'untrashed', count( $post_ids ), $location );
153                         break;
154                 case 'delete':
155                         if ( !isset( $post_ids ) )
156                                 break;
157                         foreach ( (array) $post_ids as $post_id_del ) {
158                                 if ( !current_user_can( 'delete_post', $post_id_del ) )
159                                         wp_die( __( 'You are not allowed to delete this item.' ) );
160
161                                 if ( !wp_delete_attachment( $post_id_del ) )
162                                         wp_die( __( 'Error in deleting.' ) );
163                         }
164                         $location = add_query_arg( 'deleted', count( $post_ids ), $location );
165                         break;
166         }
167
168         wp_redirect( $location );
169         exit;
170 } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
171          wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
172          exit;
173 }
174
175 $wp_list_table->prepare_items();
176
177 $title = __('Media Library');
178 $parent_file = 'upload.php';
179
180 wp_enqueue_script( 'media' );
181
182 add_screen_option( 'per_page' );
183
184 get_current_screen()->add_help_tab( array(
185 'id'            => 'overview',
186 'title'         => __('Overview'),
187 'content'       =>
188         '<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>' .
189         '<p>' . __( 'You can narrow the list by file type/status or by date using the dropdown menus above the media table.' ) . '</p>' .
190         '<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>'
191 ) );
192 get_current_screen()->add_help_tab( array(
193 'id'            => 'actions-links',
194 'title'         => __('Available Actions'),
195 'content'       =>
196         '<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>'
197 ) );
198 get_current_screen()->add_help_tab( array(
199 'id'            => 'attaching-files',
200 'title'         => __('Attaching Files'),
201 'content'       =>
202         '<p>' . __( 'If a media file has not been attached to any content, you will see that in the Uploaded To column, and can click on Attach to launch a small popup that will allow you to search for existing content and attach the file.' ) . '</p>'
203 ) );
204
205 get_current_screen()->set_help_sidebar(
206         '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
207         '<p>' . __( '<a href="https://codex.wordpress.org/Media_Library_Screen" target="_blank">Documentation on Media Library</a>' ) . '</p>' .
208         '<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
209 );
210
211 get_current_screen()->set_screen_reader_content( array(
212         'heading_views'      => __( 'Filter media items list' ),
213         'heading_pagination' => __( 'Media items list navigation' ),
214         'heading_list'       => __( 'Media items list' ),
215 ) );
216
217 require_once( ABSPATH . 'wp-admin/admin-header.php' );
218 ?>
219
220 <div class="wrap">
221 <h1>
222 <?php
223 echo esc_html( $title );
224 if ( current_user_can( 'upload_files' ) ) { ?>
225         <a href="<?php echo admin_url( 'media-new.php' ); ?>" class="page-title-action"><?php echo esc_html_x('Add New', 'file'); ?></a><?php
226 }
227 if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
228         /* translators: %s: search keywords */
229         printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', get_search_query() );
230 }
231 ?>
232 </h1>
233
234 <?php
235 $message = '';
236 if ( ! empty( $_GET['posted'] ) ) {
237         $message = __( 'Media file updated.' );
238         $_SERVER['REQUEST_URI'] = remove_query_arg(array('posted'), $_SERVER['REQUEST_URI']);
239 }
240
241 if ( ! empty( $_GET['attached'] ) && $attached = absint( $_GET['attached'] ) ) {
242         if ( 1 == $attached ) {
243                 $message = __( 'Media file attached.' );
244         } else {
245                 /* translators: %s: number of media files */
246                 $message = _n( '%s media file attached.', '%s media files attached.', $attached );
247         }
248         $message = sprintf( $message, number_format_i18n( $attached ) );
249         $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] );
250 }
251
252 if ( ! empty( $_GET['detach'] ) && $detached = absint( $_GET['detach'] ) ) {
253         if ( 1 == $detached ) {
254                 $message = __( 'Media file detached.' );
255         } else {
256                 /* translators: %s: number of media files */
257                 $message = _n( '%s media file detached.', '%s media files detached.', $detached );
258         }
259         $message = sprintf( $message, number_format_i18n( $detached ) );
260         $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] );
261 }
262
263 if ( ! empty( $_GET['deleted'] ) && $deleted = absint( $_GET['deleted'] ) ) {
264         if ( 1 == $deleted ) {
265                 $message = __( 'Media file permanently deleted.' );
266         } else {
267                 /* translators: %s: number of media files */
268                 $message = _n( '%s media file permanently deleted.', '%s media files permanently deleted.', $deleted );
269         }
270         $message = sprintf( $message, number_format_i18n( $deleted ) );
271         $_SERVER['REQUEST_URI'] = remove_query_arg(array('deleted'), $_SERVER['REQUEST_URI']);
272 }
273
274 if ( ! empty( $_GET['trashed'] ) && $trashed = absint( $_GET['trashed'] ) ) {
275         if ( 1 == $trashed ) {
276                 $message = __( 'Media file moved to the trash.' );
277         } else {
278                 /* translators: %s: number of media files */
279                 $message = _n( '%s media file moved to the trash.', '%s media files moved to the trash.', $trashed );
280         }
281         $message = sprintf( $message, number_format_i18n( $trashed ) );
282         $message .= ' <a href="' . esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids='.(isset($_GET['ids']) ? $_GET['ids'] : ''), "bulk-media" ) ) . '">' . __('Undo') . '</a>';
283         $_SERVER['REQUEST_URI'] = remove_query_arg(array('trashed'), $_SERVER['REQUEST_URI']);
284 }
285
286 if ( ! empty( $_GET['untrashed'] ) && $untrashed = absint( $_GET['untrashed'] ) ) {
287         if ( 1 == $untrashed ) {
288                 $message = __( 'Media file restored from the trash.' );
289         } else {
290                 /* translators: %s: number of media files */
291                 $message = _n( '%s media file restored from the trash.', '%s media files restored from the trash.', $untrashed );
292         }
293         $message = sprintf( $message, number_format_i18n( $untrashed ) );
294         $_SERVER['REQUEST_URI'] = remove_query_arg(array('untrashed'), $_SERVER['REQUEST_URI']);
295 }
296
297 $messages[1] = __( 'Media file updated.' );
298 $messages[2] = __( 'Media file permanently deleted.' );
299 $messages[3] = __( 'Error saving media file.' );
300 $messages[4] = __( 'Media file 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>';
301 $messages[5] = __( 'Media file restored from the trash.' );
302
303 if ( ! empty( $_GET['message'] ) && isset( $messages[ $_GET['message'] ] ) ) {
304         $message = $messages[ $_GET['message'] ];
305         $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
306 }
307
308 if ( !empty($message) ) { ?>
309 <div id="message" class="updated notice is-dismissible"><p><?php echo $message; ?></p></div>
310 <?php } ?>
311
312 <form id="posts-filter" method="get">
313
314 <?php $wp_list_table->views(); ?>
315
316 <?php $wp_list_table->display(); ?>
317
318 <div id="ajax-response"></div>
319 <?php find_posts_div(); ?>
320 </form>
321 </div>
322
323 <?php
324 include( ABSPATH . 'wp-admin/admin-footer.php' );