]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/upload.php
WordPress 4.7.2-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( __( 'Sorry, you are not allowed 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">Documentation on Media Library</a>' ) . '</p>' .
67                 '<p>' . __( '<a href="https://wordpress.org/support/">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( __( 'Sorry, 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( __( 'Sorry, you are not allowed to restore this item from 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( __( 'Sorry, 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                 default:
167                         /** This action is documented in wp-admin/edit-comments.php */
168                         $location = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $location, $doaction, $post_ids );
169         }
170
171         wp_redirect( $location );
172         exit;
173 } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
174          wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
175          exit;
176 }
177
178 $wp_list_table->prepare_items();
179
180 $title = __('Media Library');
181 $parent_file = 'upload.php';
182
183 wp_enqueue_script( 'media' );
184
185 add_screen_option( 'per_page' );
186
187 get_current_screen()->add_help_tab( array(
188 'id'            => 'overview',
189 'title'         => __('Overview'),
190 'content'       =>
191         '<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>' .
192         '<p>' . __( 'You can narrow the list by file type/status or by date using the dropdown menus above the media table.' ) . '</p>' .
193         '<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>'
194 ) );
195 get_current_screen()->add_help_tab( array(
196 'id'            => 'actions-links',
197 'title'         => __('Available Actions'),
198 'content'       =>
199         '<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>'
200 ) );
201 get_current_screen()->add_help_tab( array(
202 'id'            => 'attaching-files',
203 'title'         => __('Attaching Files'),
204 'content'       =>
205         '<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>'
206 ) );
207
208 get_current_screen()->set_help_sidebar(
209         '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
210         '<p>' . __( '<a href="https://codex.wordpress.org/Media_Library_Screen">Documentation on Media Library</a>' ) . '</p>' .
211         '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>'
212 );
213
214 get_current_screen()->set_screen_reader_content( array(
215         'heading_views'      => __( 'Filter media items list' ),
216         'heading_pagination' => __( 'Media items list navigation' ),
217         'heading_list'       => __( 'Media items list' ),
218 ) );
219
220 require_once( ABSPATH . 'wp-admin/admin-header.php' );
221 ?>
222
223 <div class="wrap">
224 <h1>
225 <?php
226 echo esc_html( $title );
227 if ( current_user_can( 'upload_files' ) ) { ?>
228         <a href="<?php echo admin_url( 'media-new.php' ); ?>" class="page-title-action"><?php echo esc_html_x('Add New', 'file'); ?></a><?php
229 }
230 if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
231         /* translators: %s: search keywords */
232         printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', get_search_query() );
233 }
234 ?>
235 </h1>
236
237 <?php
238 $message = '';
239 if ( ! empty( $_GET['posted'] ) ) {
240         $message = __( 'Media file updated.' );
241         $_SERVER['REQUEST_URI'] = remove_query_arg(array('posted'), $_SERVER['REQUEST_URI']);
242 }
243
244 if ( ! empty( $_GET['attached'] ) && $attached = absint( $_GET['attached'] ) ) {
245         if ( 1 == $attached ) {
246                 $message = __( 'Media file attached.' );
247         } else {
248                 /* translators: %s: number of media files */
249                 $message = _n( '%s media file attached.', '%s media files attached.', $attached );
250         }
251         $message = sprintf( $message, number_format_i18n( $attached ) );
252         $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] );
253 }
254
255 if ( ! empty( $_GET['detach'] ) && $detached = absint( $_GET['detach'] ) ) {
256         if ( 1 == $detached ) {
257                 $message = __( 'Media file detached.' );
258         } else {
259                 /* translators: %s: number of media files */
260                 $message = _n( '%s media file detached.', '%s media files detached.', $detached );
261         }
262         $message = sprintf( $message, number_format_i18n( $detached ) );
263         $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] );
264 }
265
266 if ( ! empty( $_GET['deleted'] ) && $deleted = absint( $_GET['deleted'] ) ) {
267         if ( 1 == $deleted ) {
268                 $message = __( 'Media file permanently deleted.' );
269         } else {
270                 /* translators: %s: number of media files */
271                 $message = _n( '%s media file permanently deleted.', '%s media files permanently deleted.', $deleted );
272         }
273         $message = sprintf( $message, number_format_i18n( $deleted ) );
274         $_SERVER['REQUEST_URI'] = remove_query_arg(array('deleted'), $_SERVER['REQUEST_URI']);
275 }
276
277 if ( ! empty( $_GET['trashed'] ) && $trashed = absint( $_GET['trashed'] ) ) {
278         if ( 1 == $trashed ) {
279                 $message = __( 'Media file moved to the trash.' );
280         } else {
281                 /* translators: %s: number of media files */
282                 $message = _n( '%s media file moved to the trash.', '%s media files moved to the trash.', $trashed );
283         }
284         $message = sprintf( $message, number_format_i18n( $trashed ) );
285         $message .= ' <a href="' . esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids='.(isset($_GET['ids']) ? $_GET['ids'] : ''), "bulk-media" ) ) . '">' . __('Undo') . '</a>';
286         $_SERVER['REQUEST_URI'] = remove_query_arg(array('trashed'), $_SERVER['REQUEST_URI']);
287 }
288
289 if ( ! empty( $_GET['untrashed'] ) && $untrashed = absint( $_GET['untrashed'] ) ) {
290         if ( 1 == $untrashed ) {
291                 $message = __( 'Media file restored from the trash.' );
292         } else {
293                 /* translators: %s: number of media files */
294                 $message = _n( '%s media file restored from the trash.', '%s media files restored from the trash.', $untrashed );
295         }
296         $message = sprintf( $message, number_format_i18n( $untrashed ) );
297         $_SERVER['REQUEST_URI'] = remove_query_arg(array('untrashed'), $_SERVER['REQUEST_URI']);
298 }
299
300 $messages[1] = __( 'Media file updated.' );
301 $messages[2] = __( 'Media file permanently deleted.' );
302 $messages[3] = __( 'Error saving media file.' );
303 $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>';
304 $messages[5] = __( 'Media file restored from the trash.' );
305
306 if ( ! empty( $_GET['message'] ) && isset( $messages[ $_GET['message'] ] ) ) {
307         $message = $messages[ $_GET['message'] ];
308         $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
309 }
310
311 if ( !empty($message) ) { ?>
312 <div id="message" class="updated notice is-dismissible"><p><?php echo $message; ?></p></div>
313 <?php } ?>
314
315 <form id="posts-filter" method="get">
316
317 <?php $wp_list_table->views(); ?>
318
319 <?php $wp_list_table->display(); ?>
320
321 <div id="ajax-response"></div>
322 <?php find_posts_div(); ?>
323 </form>
324 </div>
325
326 <?php
327 include( ABSPATH . 'wp-admin/admin-footer.php' );