]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/upload.php
WordPress 4.2.4-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         $q = $_GET;
29         // let JS handle this
30         unset( $q['s'] );
31         $vars = wp_edit_attachments_query_vars( $q );
32         $ignore = array( 'mode', 'post_type', 'post_status', 'posts_per_page' );
33         foreach ( $vars as $key => $value ) {
34                 if ( ! $value || in_array( $key, $ignore ) ) {
35                         unset( $vars[ $key ] );
36                 }
37         }
38
39         wp_localize_script( 'media-grid', '_wpMediaGridSettings', array(
40                 'adminUrl' => parse_url( self_admin_url(), PHP_URL_PATH ),
41                 'queryVars' => (object) $vars
42         ) );
43
44         get_current_screen()->add_help_tab( array(
45                 'id'            => 'overview',
46                 'title'         => __( 'Overview' ),
47                 'content'       =>
48                         '<p>' . __( 'All the files you&#8217;ve uploaded are listed in the Media Library, with the most recent uploads listed first.' ) . '</p>' .
49                         '<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>' .
50                         '<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>'
51         ) );
52
53         get_current_screen()->add_help_tab( array(
54                 'id'            => 'attachment-details',
55                 'title'         => __( 'Attachment Details' ),
56                 'content'       =>
57                         '<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>' .
58                         '<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>' .
59                         '<p>' . __( 'You can also delete individual items and access the extended edit screen from the details dialog.' ) . '</p>'
60         ) );
61
62         get_current_screen()->set_help_sidebar(
63                 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
64                 '<p>' . __( '<a href="https://codex.wordpress.org/Media_Library_Screen" target="_blank">Documentation on Media Library</a>' ) . '</p>' .
65                 '<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
66         );
67
68         $title = __('Media Library');
69         $parent_file = 'upload.php';
70
71         require_once( ABSPATH . 'wp-admin/admin-header.php' );
72         ?>
73         <div class="wrap" id="wp-media-grid" data-search="<?php _admin_search_query() ?>">
74                 <h2>
75                 <?php
76                 echo esc_html( $title );
77                 if ( current_user_can( 'upload_files' ) ) { ?>
78                         <a href="media-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'file' ); ?></a><?php
79                 }
80                 ?>
81                 </h2>
82                 <div class="error hide-if-js">
83                         <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>
84                 </div>
85         </div>
86         <?php
87         include( ABSPATH . 'wp-admin/admin-footer.php' );
88         exit;
89 }
90
91 $wp_list_table = _get_list_table('WP_Media_List_Table');
92 $pagenum = $wp_list_table->get_pagenum();
93
94 // Handle bulk actions
95 $doaction = $wp_list_table->current_action();
96
97 if ( $doaction ) {
98         check_admin_referer('bulk-media');
99
100         if ( 'delete_all' == $doaction ) {
101                 $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" );
102                 $doaction = 'delete';
103         } elseif ( isset( $_REQUEST['media'] ) ) {
104                 $post_ids = $_REQUEST['media'];
105         } elseif ( isset( $_REQUEST['ids'] ) ) {
106                 $post_ids = explode( ',', $_REQUEST['ids'] );
107         }
108
109         $location = 'upload.php';
110         if ( $referer = wp_get_referer() ) {
111                 if ( false !== strpos( $referer, 'upload.php' ) )
112                         $location = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'message', 'ids', 'posted' ), $referer );
113         }
114
115         switch ( $doaction ) {
116                 case 'detach':
117                         wp_media_attach_action( $_REQUEST['parent_post_id'], 'detach' );
118                         break;
119
120                 case 'attach':
121                         wp_media_attach_action( $_REQUEST['found_post_id'] );
122                         break;
123
124                 case 'trash':
125                         if ( !isset( $post_ids ) )
126                                 break;
127                         foreach ( (array) $post_ids as $post_id ) {
128                                 if ( !current_user_can( 'delete_post', $post_id ) )
129                                         wp_die( __( 'You are not allowed to move this post to the trash.' ) );
130
131                                 if ( !wp_trash_post( $post_id ) )
132                                         wp_die( __( 'Error in moving to trash.' ) );
133                         }
134                         $location = add_query_arg( array( 'trashed' => count( $post_ids ), 'ids' => join( ',', $post_ids ) ), $location );
135                         break;
136                 case 'untrash':
137                         if ( !isset( $post_ids ) )
138                                 break;
139                         foreach ( (array) $post_ids as $post_id ) {
140                                 if ( !current_user_can( 'delete_post', $post_id ) )
141                                         wp_die( __( 'You are not allowed to move this post out of the trash.' ) );
142
143                                 if ( !wp_untrash_post( $post_id ) )
144                                         wp_die( __( 'Error in restoring from trash.' ) );
145                         }
146                         $location = add_query_arg( 'untrashed', count( $post_ids ), $location );
147                         break;
148                 case 'delete':
149                         if ( !isset( $post_ids ) )
150                                 break;
151                         foreach ( (array) $post_ids as $post_id_del ) {
152                                 if ( !current_user_can( 'delete_post', $post_id_del ) )
153                                         wp_die( __( 'You are not allowed to delete this post.' ) );
154
155                                 if ( !wp_delete_attachment( $post_id_del ) )
156                                         wp_die( __( 'Error in deleting.' ) );
157                         }
158                         $location = add_query_arg( 'deleted', count( $post_ids ), $location );
159                         break;
160         }
161
162         wp_redirect( $location );
163         exit;
164 } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
165          wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
166          exit;
167 }
168
169 $wp_list_table->prepare_items();
170
171 $title = __('Media Library');
172 $parent_file = 'upload.php';
173
174 wp_enqueue_script( 'media' );
175
176 add_screen_option( 'per_page' );
177
178 get_current_screen()->add_help_tab( array(
179 'id'            => 'overview',
180 'title'         => __('Overview'),
181 'content'       =>
182         '<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>' .
183         '<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>' .
184         '<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>'
185 ) );
186 get_current_screen()->add_help_tab( array(
187 'id'            => 'actions-links',
188 'title'         => __('Available Actions'),
189 'content'       =>
190         '<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>'
191 ) );
192 get_current_screen()->add_help_tab( array(
193 'id'            => 'attaching-files',
194 'title'         => __('Attaching Files'),
195 'content'       =>
196         '<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>'
197 ) );
198
199 get_current_screen()->set_help_sidebar(
200         '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
201         '<p>' . __( '<a href="https://codex.wordpress.org/Media_Library_Screen" target="_blank">Documentation on Media Library</a>' ) . '</p>' .
202         '<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
203 );
204
205 require_once( ABSPATH . 'wp-admin/admin-header.php' );
206 ?>
207
208 <div class="wrap">
209 <h2>
210 <?php
211 echo esc_html( $title );
212 if ( current_user_can( 'upload_files' ) ) { ?>
213         <a href="media-new.php" class="add-new-h2"><?php echo esc_html_x('Add New', 'file'); ?></a><?php
214 }
215 if ( ! empty( $_REQUEST['s'] ) )
216         printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', get_search_query() ); ?>
217 </h2>
218
219 <?php
220 $message = '';
221 if ( ! empty( $_GET['posted'] ) ) {
222         $message = __( 'Media attachment updated.' );
223         $_SERVER['REQUEST_URI'] = remove_query_arg(array('posted'), $_SERVER['REQUEST_URI']);
224 }
225
226 if ( ! empty( $_GET['attached'] ) && $attached = absint( $_GET['attached'] ) ) {
227         $message = sprintf( _n( 'Reattached %d attachment.', 'Reattached %d attachments.', $attached ), $attached );
228         $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] );
229 }
230
231 if ( ! empty( $_GET['detach'] ) && $detached = absint( $_GET['detach'] ) ) {
232         $message = sprintf( _n( 'Detached %d attachment.', 'Detached %d attachments.', $detached ), $detached );
233         $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detach', 'attached' ), $_SERVER['REQUEST_URI'] );
234 }
235
236 if ( ! empty( $_GET['deleted'] ) && $deleted = absint( $_GET['deleted'] ) ) {
237         if ( 1 == $deleted ) {
238                 $message = __( 'Media attachment permanently deleted.' );
239         } else {
240                 $message = _n( '%d media attachment permanently deleted.', '%d media attachments permanently deleted.', $deleted );
241         }
242         $message = sprintf( $message, number_format_i18n( $deleted ) );
243         $_SERVER['REQUEST_URI'] = remove_query_arg(array('deleted'), $_SERVER['REQUEST_URI']);
244 }
245
246 if ( ! empty( $_GET['trashed'] ) && $trashed = absint( $_GET['trashed'] ) ) {
247         if ( 1 == $trashed ) {
248                 $message = __( 'Media attachment moved to the trash.' );
249         } else {
250                 $message = _n( '%d media attachment moved to the trash.', '%d media attachments moved to the trash.', $trashed );
251         }
252         $message = sprintf( $message, number_format_i18n( $trashed ) );
253         $message .= ' <a href="' . esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids='.(isset($_GET['ids']) ? $_GET['ids'] : ''), "bulk-media" ) ) . '">' . __('Undo') . '</a>';
254         $_SERVER['REQUEST_URI'] = remove_query_arg(array('trashed'), $_SERVER['REQUEST_URI']);
255 }
256
257 if ( ! empty( $_GET['untrashed'] ) && $untrashed = absint( $_GET['untrashed'] ) ) {
258         if ( 1 == $untrashed ) {
259                 $message = __( 'Media attachment restored from the trash.' );
260         } else {
261                 $message = _n( '%d media attachment restored from the trash.', '%d media attachments restored from the trash.', $untrashed );
262         }
263         $message = sprintf( $message, number_format_i18n( $untrashed ) );
264         $_SERVER['REQUEST_URI'] = remove_query_arg(array('untrashed'), $_SERVER['REQUEST_URI']);
265 }
266
267 $messages[1] = __('Media attachment updated.');
268 $messages[2] = __('Media permanently deleted.');
269 $messages[3] = __('Error saving media attachment.');
270 $messages[4] = __('Media 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>';
271 $messages[5] = __('Media restored from the trash.');
272
273 if ( ! empty( $_GET['message'] ) && isset( $messages[ $_GET['message'] ] ) ) {
274         $message = $messages[ $_GET['message'] ];
275         $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
276 }
277
278 if ( !empty($message) ) { ?>
279 <div id="message" class="updated notice is-dismissible"><p><?php echo $message; ?></p></div>
280 <?php } ?>
281
282 <form id="posts-filter" method="get">
283
284 <?php $wp_list_table->views(); ?>
285
286 <?php $wp_list_table->display(); ?>
287
288 <div id="ajax-response"></div>
289 <?php find_posts_div(); ?>
290 </form>
291 </div>
292
293 <?php
294 include( ABSPATH . 'wp-admin/admin-footer.php' );