Make WordPress Core

Ticket #16191: 16191.2.diff

File 16191.2.diff, 2.9 KB (added by mdawaffe, 13 years ago)

Cleanup, Docs

  • wp-includes/default-filters.php

     
    186186add_filter( 'pings_open',           '_close_comments_for_old_post', 10, 2 );
    187187add_filter( 'editable_slug',        'urldecode'                           );
    188188add_filter( 'nav_menu_meta_box_object', '_wp_nav_menu_meta_box_object'    );
     189add_filter( 'wp_handle_upload_prefilter', 'wp_fix_original_filename'      );
    189190
    190191// Atom SSL support
    191192add_filter( 'atom_service_url','atom_service_url_filter' );
  • wp-admin/includes/file.php

     
    10791079        return false;
    10801080}
    10811081
    1082 ?>
     1082/**
     1083 * Replaces $_FILES['blah']['name'] values sent by WebKit with munged double quotes with the value we stored in $_POST['original_file_name']
     1084 * Only works if $_FILES has only one entry, but the bug only exists when using the browser plugin.
     1085 *
     1086 * Attached to wp_handle_upload_prefilter
     1087 *
     1088 * http://core.trac.wordpress.org/ticket/16191
     1089 *
     1090 * @see media_upload_form()
     1091 */
     1092function wp_fix_original_filename( $file ) {
     1093        if ( empty( $_POST['original_file_name'] ) )
     1094                return $file;
     1095
     1096        $original_file_name = stripslashes( $_POST['original_file_name'] );
     1097        $original_file_name = str_replace( '\\', '/', $original_file_name ); // Windows path sanitiation
     1098        $original_file_name = wp_basename( $original_file_name );
     1099
     1100        if ( str_replace( '"', '%22', $original_file_name ) == $file['name'] )
     1101                $file['name'] = $original_file_name;
     1102
     1103        return $file;
     1104}
  • wp-admin/includes/media.php

     
    14061406 *
    14071407 * @since 2.5.0
    14081408 *
     1409 * @see wp_fix_original_filename()
     1410 *
    14091411 * @param unknown_type $errors
    14101412 */
    14111413function media_upload_form( $errors = null ) {
     
    15301532                };
    15311533                swfu = new SWFUpload(settings);
    15321534};
     1535<?php
     1536// Store the original file name in $_POST['original_file_name'] since WebKit munges double quotes
     1537// http://core.trac.wordpress.org/ticket/16191
     1538?>
     1539jQuery( function($) {
     1540        $( '#file-form' ).submit( function() {
     1541                $( '#original-file-name' ).val( $( '#async-upload' ).val() );
     1542        } );
     1543} );
    15331544//]]>
    15341545</script>
    15351546
     
    15521563        <p id="async-upload-wrap">
    15531564                <label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label>
    15541565                <input type="file" name="async-upload" id="async-upload" />
     1566                <input type="hidden" name="original_file_name" id="original-file-name" />
    15551567                <?php submit_button( __( 'Upload' ), 'button', 'html-upload', false ); ?>
    15561568                <a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e('Cancel'); ?></a>
    15571569        </p>