WordPress.org

Make WordPress Core

Ticket #18206: jacobwg-gsoc2011-patch02.diff

File jacobwg-gsoc2011-patch02.diff, 16.8 KB (added by jacobwg, 3 years ago)

New patch - should fix the issues with the previous patch

  • wp-admin/includes/file.php

     
    323323 
    324324        $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback ); 
    325325 
     326        $tmp_file = wp_tempnam($filename); 
     327 
    326328        // Move the file to the uploads dir 
    327         $new_file = $uploads['path'] . "/$filename"; 
    328         if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) 
     329        if ( false === @ move_uploaded_file( $file['tmp_name'], $tmp_file ) ) 
    329330                return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) ); 
    330331 
     332        // If a resize was requested, perform the resize. 
     333        $do_resize = apply_filters( 'wp_upload_resize', isset( $_REQUEST['image_resize'] ) ); 
     334        if ($do_resize) { 
     335                $old_temp = $tmp_file; 
     336                $tmp_file = image_resize( $tmp_file, (int) get_option('large_size_w'), (int) get_option('large_size_h'), 0, 'resized'); 
     337                if ( ! is_wp_error($tmp_file) ) { 
     338                        unlink($old_temp); 
     339                } else { 
     340                        $tmp_file = $old_temp; 
     341                } 
     342        } 
     343 
     344        // Copy the temporary file into its destination 
     345        $new_file = $uploads['path'] . "/$filename"; 
     346        copy( $tmp_file, $new_file ); 
     347        unlink($tmp_file); 
     348         
    331349        // Set correct file permissions 
    332350        $stat = stat( dirname( $new_file )); 
    333351        $perms = $stat['mode'] & 0000666; 
  • wp-admin/includes/media.php

     
    14371437function media_upload_form( $errors = null ) { 
    14381438        global $type, $tab, $pagenow; 
    14391439 
    1440         $flash_action_url = admin_url('async-upload.php'); 
     1440        $upload_action_url = admin_url('async-upload.php'); 
    14411441 
    1442         // If Mac and mod_security, no Flash. :( 
    1443         $flash = true; 
    1444         if ( false !== stripos($_SERVER['HTTP_USER_AGENT'], 'mac') && apache_mod_loaded('mod_security') ) 
    1445                 $flash = false; 
    1446  
    1447         $flash = apply_filters('flash_uploader', $flash); 
    14481442        $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0; 
    14491443 
    14501444        $upload_size_unit = $max_upload_size =  wp_max_upload_size(); 
     
    14581452                $upload_size_unit = (int) $upload_size_unit; 
    14591453        } 
    14601454?> 
    1461 <script type="text/javascript"> 
    1462 //<![CDATA[ 
    1463 var uploaderMode = 0; 
    1464 jQuery(document).ready(function($){ 
    1465         uploaderMode = getUserSetting('uploader'); 
    1466         $('.upload-html-bypass a').click(function(){deleteUserSetting('uploader');uploaderMode=0;swfuploadPreLoad();return false;}); 
    1467         $('.upload-flash-bypass a').click(function(){setUserSetting('uploader', '1');uploaderMode=1;swfuploadPreLoad();return false;}); 
    1468 }); 
    1469 //]]> 
    14701455</script> 
    14711456<div id="media-upload-notice"> 
    14721457<?php if (isset($errors['upload_notice']) ) { ?> 
     
    14871472 
    14881473do_action('pre-upload-ui'); 
    14891474 
    1490 if ( $flash ) : 
    1491  
    1492 // Set the post params, which SWFUpload will post back with the file, and pass 
     1475// Set the post params, which plupload will post back with the file, and pass 
    14931476// them through a filter. 
    14941477$post_params = array( 
    14951478                "post_id" => $post_id, 
     
    15001483                "tab" => $tab, 
    15011484                "short" => "1", 
    15021485); 
    1503 $post_params = apply_filters( 'swfupload_post_params', $post_params ); 
     1486$post_params = apply_filters( 'upload_post_params', $post_params ); 
    15041487$p = array(); 
    15051488foreach ( $post_params as $param => $val ) 
    15061489        $p[] = "\t\t'$param' : '$val'"; 
    15071490$post_params_str = implode( ", \n", $p ); 
    15081491 
    1509 // #8545. wmode=transparent cannot be used with SWFUpload 
    1510 if ( 'media-new.php' == $pagenow ) { 
    1511         $upload_image_path = get_user_option( 'admin_color' ); 
    1512         if ( 'classic' != $upload_image_path ) 
    1513                 $upload_image_path = 'fresh'; 
    1514         $upload_image_path = admin_url( 'images/upload-' . $upload_image_path . '.png?ver=20101205' ); 
    1515 } else { 
    1516         $upload_image_path = includes_url( 'images/upload.png?ver=20100531' ); 
    1517 } 
    1518  
    15191492?> 
    15201493<script type="text/javascript"> 
    15211494//<![CDATA[ 
    1522 var swfu; 
    1523 SWFUpload.onload = function() { 
    1524         var settings = { 
    1525                         button_text: '<span class="button"><?php _e('Select Files'); ?><\/span>', 
    1526                         button_text_style: '.button { text-align: center; font-weight: bold; font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif; font-size: 11px; text-shadow: 0 1px 0 #FFFFFF; color:#464646; }', 
    1527                         button_height: "23", 
    1528                         button_width: "132", 
    1529                         button_text_top_padding: 3, 
    1530                         button_image_url: '<?php echo $upload_image_path; ?>', 
    1531                         button_placeholder_id: "flash-browse-button", 
    1532                         upload_url : "<?php echo esc_attr( $flash_action_url ); ?>", 
    1533                         flash_url : "<?php echo includes_url('js/swfupload/swfupload.swf'); ?>", 
    1534                         file_post_name: "async-upload", 
    1535                         file_types: "<?php echo apply_filters('upload_file_glob', '*.*'); ?>", 
    1536                         post_params : { 
    1537                                 <?php echo $post_params_str; ?> 
    1538                         }, 
    1539                         file_size_limit : "<?php echo $max_upload_size; ?>b", 
    1540                         file_dialog_start_handler : fileDialogStart, 
    1541                         file_queued_handler : fileQueued, 
    1542                         upload_start_handler : uploadStart, 
    1543                         upload_progress_handler : uploadProgress, 
    1544                         upload_error_handler : uploadError, 
    1545                         upload_success_handler : <?php echo apply_filters( 'swfupload_success_handler', 'uploadSuccess' ); ?>, 
    1546                         upload_complete_handler : uploadComplete, 
    1547                         file_queue_error_handler : fileQueueError, 
    1548                         file_dialog_complete_handler : fileDialogComplete, 
    1549                         swfupload_pre_load_handler: swfuploadPreLoad, 
    1550                         swfupload_load_failed_handler: swfuploadLoadFailed, 
    1551                         custom_settings : { 
    1552                                 degraded_element_id : "html-upload-ui", // id of the element displayed when swfupload is unavailable 
    1553                                 swfupload_element_id : "flash-upload-ui" // id of the element displayed when swfupload is available 
    1554                         }, 
    1555                         debug: false 
    1556                 }; 
    1557                 swfu = new SWFUpload(settings); 
    1558 }; 
     1495var resize_mode = false; 
     1496var resize_height = <?php echo get_option('large_size_h'); ?>,  
     1497        resize_width = <?php echo get_option('large_size_w'); ?>; 
     1498 
     1499jQuery(function($) { 
     1500        window.uploader = new plupload.Uploader({ 
     1501                runtimes: '<?php echo apply_filters('plupload_runtimes', 'html5,silverlight,flash,html4'); ?>', 
     1502                browse_button: 'plupload-browse-button', 
     1503                container: 'plupload-upload-ui', 
     1504                drop_element: 'wpwrap', 
     1505                file_data_name: 'async-upload', 
     1506                max_file_size: '<?php echo $max_upload_size / 1024; ?>kb', 
     1507                url: '<?php echo esc_attr( $upload_action_url ); ?>', 
     1508                plupload_swf_url: '<?php echo includes_url('js/plupload/plupload.plupload.swf'); ?>', 
     1509                silverlight_xap_url: '<?php echo includes_url('js/plupload/plupload.silverlight.xap'); ?>', 
     1510                filters: [ 
     1511                        {title: "Allowed files", extensions: "<?php echo apply_filters('upload_file_glob', '*'); ?>"} 
     1512                ], 
     1513                multipart: true, 
     1514                multipart_params : { 
     1515                        <?php echo $post_params_str; ?> 
     1516                } 
     1517        }); 
     1518         
     1519        resize_mode = getUserSetting('resize_mode') == 'true'; 
     1520        setResize(resize_mode) 
     1521        $('#image_resize').bind('change', function() { 
     1522                setResize($(this).prop('checked')); 
     1523        }); 
     1524 
     1525        uploader.init(); 
     1526 
     1527        uploader.bind('FilesAdded', function(up, files) { 
     1528                $.each(files, function(i, file) { 
     1529                        fileQueued(file); 
     1530                }); 
     1531         
     1532                up.refresh(); 
     1533                up.start(); 
     1534        }); 
     1535 
     1536        uploader.bind('BeforeUpload', function(up, file) { 
     1537                uploadStart(file); 
     1538        }); 
     1539         
     1540        uploader.bind('UploadProgress', function(up, file) { 
     1541                uploadProgress(file, file.loaded, file.size); 
     1542        }); 
     1543         
     1544        uploader.bind('Error', function(up, err) { 
     1545                uploadError(err.file, err.code, err.message); 
     1546         
     1547                up.refresh(); 
     1548        }); 
     1549 
     1550        uploader.bind('FileUploaded', function(up, file, response) { 
     1551                <?php echo apply_filters( 'plupload_success_handler', 'uploadSuccess' ); ?>(file, response.response); 
     1552        }); 
     1553 
     1554}); 
    15591555//]]> 
    15601556</script> 
    15611557 
    1562 <div id="flash-upload-ui" class="hide-if-no-js"> 
    1563 <?php do_action('pre-flash-upload-ui'); ?> 
     1558<div id="plupload-upload-ui" class="hide-if-no-js"> 
     1559<?php do_action('pre-plupload-upload-ui'); ?> 
    15641560 
    15651561        <div> 
    15661562        <?php _e( 'Choose files to upload' ); ?> 
    1567         <div id="flash-browse-button"></div> 
     1563        <span id="plupload-browse-button" class="button"><?php _e('Select Files'); ?></span> 
    15681564        <span><input id="cancel-upload" disabled="disabled" onclick="cancelUpload()" type="button" value="<?php esc_attr_e('Cancel Upload'); ?>" class="button" /></span> 
    15691565        </div> 
    1570         <p class="media-upload-size"><?php printf( __( 'Maximum upload file size: %d%s' ), $upload_size_unit, $sizes[$u] ); ?></p> 
    1571 <?php do_action('post-flash-upload-ui'); ?> 
    1572         <p class="howto"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p> 
     1566<?php do_action('post-plupload-upload-ui'); ?> 
    15731567</div> 
    1574 <?php endif; // $flash ?> 
    15751568 
    1576 <div id="html-upload-ui" <?php if ( $flash ) echo 'class="hide-if-js"'; ?>> 
     1569<div id="html-upload-ui" class="hide-if-js"> 
    15771570<?php do_action('pre-html-upload-ui'); ?> 
    15781571        <p id="async-upload-wrap"> 
    15791572                <label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label> 
    15801573                <input type="file" name="async-upload" id="async-upload" /> 
    15811574                <?php submit_button( __( 'Upload' ), 'button', 'html-upload', false ); ?> 
    1582                 <a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e('Cancel'); ?></a> 
     1575                <a href="<?php echo admin_url('upload.php'); ?>"><?php _e('Cancel'); ?></a> 
    15831576        </p> 
    15841577        <div class="clear"></div> 
    1585         <p class="media-upload-size"><?php printf( __( 'Maximum upload file size: %d%s' ), $upload_size_unit, $sizes[$u] ); ?></p> 
    1586         <?php if ( is_lighttpd_before_150() ): ?> 
    1587         <p><?php _e('If you want to use all capabilities of the uploader, like uploading multiple files at once, please update to lighttpd 1.5.'); ?></p> 
    1588         <?php endif;?> 
    1589 <?php do_action('post-html-upload-ui', $flash); ?> 
     1578<?php do_action('post-html-upload-ui', $plupload); ?> 
    15901579</div> 
     1580 
     1581<p class="media-upload-size"><?php printf( __( 'Maximum upload file size: %d%s' ), $upload_size_unit, $sizes[$u] ); ?></p> 
     1582<p class="howto"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p> 
     1583 
    15911584<?php do_action('post-upload-ui'); ?> 
    15921585<?php 
    15931586} 
     
    22722265/** 
    22732266 * {@internal Missing Short Description}} 
    22742267 * 
    2275  * Support a GET parameter for disabling the flash uploader. 
    2276  * 
    22772268 * @since 2.6.0 
    2278  * 
    2279  * @param unknown_type $flash 
    2280  * @return unknown 
    22812269 */ 
    2282 function media_upload_use_flash($flash) { 
    2283         if ( array_key_exists('flash', $_REQUEST) ) 
    2284                 $flash = !empty($_REQUEST['flash']); 
    2285         return $flash; 
     2270function media_upload_max_image_resize() { 
     2271?> 
     2272<input name="image_resize" type="checkbox" id="image_resize" value="1" /> 
     2273<label for="image_resize"><?php printf( __( 'Scale images to %d x %d'), get_option('large_size_w'), get_option('large_size_h') ); ?></label> 
     2274<?php  
    22862275} 
    22872276 
    2288 add_filter('flash_uploader', 'media_upload_use_flash'); 
     2277add_action('post-upload-ui', 'media_upload_max_image_resize'); 
    22892278 
    2290 /** 
    2291  * {@internal Missing Short Description}} 
    2292  * 
    2293  * @since 2.6.0 
    2294  */ 
    2295 function media_upload_flash_bypass() { 
    2296         echo '<p class="upload-flash-bypass">'; 
    2297         printf( __('You are using the Flash uploader.  Problems?  Try the <a href="%s">Browser uploader</a> instead.'), esc_url(add_query_arg('flash', 0)) ); 
    2298         echo '</p>'; 
    2299 } 
    2300  
    2301 /** 
    2302  * {@internal Missing Short Description}} 
    2303  * 
    2304  * @since 2.6.0 
    2305  */ 
    2306 function media_upload_html_bypass($flash = true) { 
    2307         echo '<p class="upload-html-bypass hide-if-no-js">'; 
    2308         _e('You are using the Browser uploader.'); 
    2309         if ( $flash ) { 
    2310                 // the user manually selected the browser uploader, so let them switch back to Flash 
    2311                 echo ' '; 
    2312                 printf( __('Try the <a href="%s">Flash uploader</a> instead.'), esc_url(add_query_arg('flash', 1)) ); 
    2313         } 
    2314         echo "</p>\n"; 
    2315 } 
    2316  
    2317 add_action('post-flash-upload-ui', 'media_upload_flash_bypass'); 
    2318 add_action('post-html-upload-ui', 'media_upload_html_bypass'); 
    2319  
    2320 /** 
    2321  * {@internal Missing Short Description}} 
    2322  * 
    2323  * Make sure the GET parameter sticks when we submit a form. 
    2324  * 
    2325  * @since 2.6.0 
    2326  * 
    2327  * @param unknown_type $url 
    2328  * @return unknown 
    2329  */ 
    2330 function media_upload_bypass_url($url) { 
    2331         if ( array_key_exists('flash', $_REQUEST) ) 
    2332                 $url = add_query_arg('flash', intval($_REQUEST['flash'])); 
    2333         return $url; 
    2334 } 
    2335  
    2336 add_filter('media_upload_form_url', 'media_upload_bypass_url'); 
    2337  
    23382279add_filter('async_upload_image', 'get_media_item', 10, 2); 
    23392280add_filter('async_upload_audio', 'get_media_item', 10, 2); 
    23402281add_filter('async_upload_video', 'get_media_item', 10, 2); 
  • wp-admin/media-upload.php

     
    1818if (!current_user_can('upload_files')) 
    1919        wp_die(__('You do not have permission to upload files.')); 
    2020 
    21 wp_enqueue_script('swfupload-all'); 
    22 wp_enqueue_script('swfupload-handlers'); 
     21wp_enqueue_script('plupload-full'); 
     22wp_enqueue_script('plupload-handlers'); 
    2323wp_enqueue_script('image-edit'); 
    2424wp_enqueue_script('set-post-thumbnail' ); 
    2525wp_enqueue_style('imgareaselect'); 
  • wp-includes/script-loader.php

     
    198198 
    199199        $scripts->add( 'jcrop', "/wp-includes/js/jcrop/jquery.Jcrop$suffix.js", array('jquery'), '0.9.8-20110113'); 
    200200 
    201         $scripts->add( 'swfobject', "/wp-includes/js/swfobject.js", false, '2.2'); 
    202201 
    203         $scripts->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', false, '2201-20110113'); 
    204         $scripts->add( 'swfupload-swfobject', '/wp-includes/js/swfupload/plugins/swfupload.swfobject.js', array('swfupload', 'swfobject'), '2201a'); 
    205         $scripts->add( 'swfupload-queue', '/wp-includes/js/swfupload/plugins/swfupload.queue.js', array('swfupload'), '2201'); 
    206         $scripts->add( 'swfupload-speed', '/wp-includes/js/swfupload/plugins/swfupload.speed.js', array('swfupload'), '2201'); 
     202        $scripts->add( 'plupload', '/wp-includes/js/plupload/plupload.js', false, '1.4.3.2'); 
     203        $scripts->add( 'plupload-html5', '/wp-includes/js/plupload/plupload.html5.js', array('plupload'), '1.4.3.2'); 
     204        $scripts->add( 'plupload-flash', '/wp-includes/js/plupload/plupload.flash.js', array('plupload'), '1.4.3.2'); 
     205        $scripts->add( 'plupload-silverlight', '/wp-includes/js/plupload/plupload.silverlight.js', array('plupload'), '1.4.3.2'); 
     206        $scripts->add( 'plupload-gears', '/wp-includes/js/plupload/plupload.gears.js', array('plupload'), '1.4.3.2'); 
     207        $scripts->add( 'plupload-html4', '/wp-includes/js/plupload/plupload.html4.js', array('plupload'), '1.4.3.2'); 
    207208 
    208         if ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) { 
     209        // TODO: find out if we can use the plupload.full.js (it does load browserplus) 
     210        $scripts->add( 'plupload-full', false, array('plupload', 'plupload-html5', 'plupload-flash', 'plupload-silverlight', 'plupload-gears', 'plupload-html4'), '1.4.3.2'); 
     211 
     212        $scripts->add( 'plupload-handlers', '/wp-includes/js/plupload/handlers.js', array('plupload-full', 'jquery'), '1.4.3.2'); 
     213         
     214        // TODO: find out if we really need this debug clause with plupload 
     215        /*if ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) { 
    209216                // queue all SWFUpload scripts that are used by default 
    210217                $scripts->add( 'swfupload-all', false, array('swfupload', 'swfupload-swfobject', 'swfupload-queue'), '2201'); 
    211218        } else { 
    212                 $scripts->add( 'swfupload-all', '/wp-includes/js/swfupload/swfupload-all.js', array(), '2201a'); 
    213         } 
     219                $scripts->add( 'swfupload-all', '/wp-includes/js/swfupload/swfupload-all.js', array(), '2201'); 
     220        }*/ 
    214221 
    215         $scripts->add( 'swfupload-handlers', "/wp-includes/js/swfupload/handlers$suffix.js", array('swfupload-all', 'jquery'), '2201-20110524'); 
    216222        $max_upload_size = ( (int) ( $max_up = @ini_get('upload_max_filesize') ) < (int) ( $max_post = @ini_get('post_max_size') ) ) ? $max_up : $max_post; 
    217223        if ( empty($max_upload_size) ) 
    218224                $max_upload_size = __('not configured'); 
    219225        // these error messages came from the sample swfupload js, they might need changing. 
    220         $scripts->add_script_data( 'swfupload-handlers', 'swfuploadL10n', array( 
    221                         'queue_limit_exceeded' => __('You have attempted to queue too many files.'), 
     226        $scripts->localize( 'plupload-handlers', 'pluploadL10n', array( 
    222227                        'file_exceeds_size_limit' => __('This file exceeds the maximum upload size for this site.'), 
    223228                        'zero_byte_file' => __('This file is empty. Please try another.'), 
    224229                        'invalid_filetype' => __('This file type is not allowed. Please try another.'), 
     230                        'not_an_image' => __('This file is not an image. Please try another.'), 
     231                        'image_memory_exceeded' => __('Memery exceeded. Please try another smaller file.'), 
     232                        'image_dimensions_exceeded' => __('This is larger than the maximum size. Please try another.'), 
    225233                        'default_error' => __('An error occurred in the upload. Please try again later.'), 
    226234                        'missing_upload_url' => __('There was a configuration error. Please contact the server administrator.'), 
    227235                        'upload_limit_exceeded' => __('You may only upload 1 file.'), 
     
    234242                        'dismiss' => __('Dismiss'), 
    235243                        'crunching' => __('Crunching&hellip;'), 
    236244                        'deleted' => __('moved to the trash.'), 
    237                         'error_uploading' => __('&#8220;%s&#8221; has failed to upload due to an error') 
     245                        'error_uploading' => __('&#8220;%s&#8221; has failed to upload due to an error'), 
     246                        'l10n_print_after' => 'try{convertEntities(pluploadL10n);}catch(e){};', 
    238247        ) ); 
    239248 
    240249        $scripts->add( 'comment-reply', "/wp-includes/js/comment-reply$suffix.js", false, '20090102');