Changeset 52352 for trunk/src/wp-includes/functions.php
- Timestamp:
- 12/10/2021 08:28:27 PM (4 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/functions.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.php
r52215 r52352 2539 2539 } 2540 2540 2541 // Get the mime type. Uploaded files were already checked with wp_check_filetype_and_ext() 2542 // in _wp_handle_upload(). Using wp_check_filetype() would be sufficient here. 2541 /* 2542 * Get the mime type. Uploaded files were already checked with wp_check_filetype_and_ext() 2543 * in _wp_handle_upload(). Using wp_check_filetype() would be sufficient here. 2544 */ 2543 2545 $file_type = wp_check_filetype( $filename ); 2544 2546 $mime_type = $file_type['type']; … … 2551 2553 $_dir = trailingslashit( $dir ); 2552 2554 2553 // If the extension is uppercase add an alternate file name with lowercase extension. Both need to be tested 2554 // for uniqueness as the extension will be changed to lowercase for better compatibility with different filesystems. 2555 // Fixes an inconsistency in WP < 2.9 where uppercase extensions were allowed but image sub-sizes were created with 2556 // lowercase extensions. 2555 /* 2556 * If the extension is uppercase add an alternate file name with lowercase extension. 2557 * Both need to be tested for uniqueness as the extension will be changed to lowercase 2558 * for better compatibility with different filesystems. Fixes an inconsistency in WP < 2.9 2559 * where uppercase extensions were allowed but image sub-sizes were created with 2560 * lowercase extensions. 2561 */ 2557 2562 if ( $ext && $lc_ext !== $ext ) { 2558 2563 $lc_filename = preg_replace( '|' . preg_quote( $ext ) . '$|', $lc_ext, $filename ); 2559 2564 } 2560 2565 2561 // Increment the number added to the file name if there are any files in $dir whose names match one of the 2562 // possible name variations. 2566 /* 2567 * Increment the number added to the file name if there are any files in $dir 2568 * whose names match one of the possible name variations. 2569 */ 2563 2570 while ( file_exists( $_dir . $filename ) || ( $lc_filename && file_exists( $_dir . $lc_filename ) ) ) { 2564 2571 $new_number = (int) $number + 1; 2565 2572 2566 2573 if ( $lc_filename ) { 2567 $lc_filename = str_replace( array( "-{$number}{$lc_ext}", "{$number}{$lc_ext}" ), "-{$new_number}{$lc_ext}", $lc_filename ); 2574 $lc_filename = str_replace( 2575 array( "-{$number}{$lc_ext}", "{$number}{$lc_ext}" ), 2576 "-{$new_number}{$lc_ext}", 2577 $lc_filename 2578 ); 2568 2579 } 2569 2580 … … 2571 2582 $filename = "{$filename}-{$new_number}"; 2572 2583 } else { 2573 $filename = str_replace( array( "-{$number}{$ext}", "{$number}{$ext}" ), "-{$new_number}{$ext}", $filename ); 2584 $filename = str_replace( 2585 array( "-{$number}{$ext}", "{$number}{$ext}" ), 2586 "-{$new_number}{$ext}", 2587 $filename 2588 ); 2574 2589 } 2575 2590 … … 2582 2597 } 2583 2598 2584 // Prevent collisions with existing file names that contain dimension-like strings 2585 // (whether they are subsizes or originals uploaded prior to #42437). 2599 /* 2600 * Prevent collisions with existing file names that contain dimension-like strings 2601 * (whether they are subsizes or originals uploaded prior to #42437). 2602 */ 2586 2603 2587 2604 $files = array(); … … 2618 2635 $count = count( $files ); 2619 2636 2620 // Ensure this never goes into infinite loop 2621 // as it uses pathinfo() and regex in the check, but string replacement for the changes. 2637 /* 2638 * Ensure this never goes into infinite loop as it uses pathinfo() and regex in the check, 2639 * but string replacement for the changes. 2640 */ 2622 2641 $i = 0; 2623 2642 … … 2626 2645 2627 2646 // If $ext is uppercase it was replaced with the lowercase version after the previous loop. 2628 $filename = str_replace( array( "-{$number}{$lc_ext}", "{$number}{$lc_ext}" ), "-{$new_number}{$lc_ext}", $filename ); 2647 $filename = str_replace( 2648 array( "-{$number}{$lc_ext}", "{$number}{$lc_ext}" ), 2649 "-{$new_number}{$lc_ext}", 2650 $filename 2651 ); 2629 2652 2630 2653 $number = $new_number; … … 2634 2657 } 2635 2658 2636 // Check if an image will be converted after uploading or some existing images sub-sizes file names may conflict 2637 // when regenerated. If yes, ensure the new file name will be unique and will produce unique sub-sizes. 2659 /* 2660 * Check if an image will be converted after uploading or some existing image sub-size file names may conflict 2661 * when regenerated. If yes, ensure the new file name will be unique and will produce unique sub-sizes. 2662 */ 2638 2663 if ( $is_image ) { 2639 2664 /** This filter is documented in wp-includes/class-wp-image-editor.php */ … … 2669 2694 2670 2695 if ( ! empty( $alt_filenames ) ) { 2671 // Add the original filename. It needs to be checked again together with the alternate filenames 2672 // when $number is incremented. 2696 /* 2697 * Add the original filename. It needs to be checked again 2698 * together with the alternate filenames when $number is incremented. 2699 */ 2673 2700 $alt_filenames[ $lc_ext ] = $filename; 2674 2701 … … 2680 2707 2681 2708 foreach ( $alt_filenames as $alt_ext => $alt_filename ) { 2682 $alt_filenames[ $alt_ext ] = str_replace( array( "-{$number}{$alt_ext}", "{$number}{$alt_ext}" ), "-{$new_number}{$alt_ext}", $alt_filename ); 2709 $alt_filenames[ $alt_ext ] = str_replace( 2710 array( "-{$number}{$alt_ext}", "{$number}{$alt_ext}" ), 2711 "-{$new_number}{$alt_ext}", 2712 $alt_filename 2713 ); 2683 2714 } 2684 2715 2685 // Also update the $number in (the output) $filename. 2686 // If the extension was uppercase it was already replaced with the lowercase version. 2687 $filename = str_replace( array( "-{$number}{$lc_ext}", "{$number}{$lc_ext}" ), "-{$new_number}{$lc_ext}", $filename ); 2716 /* 2717 * Also update the $number in (the output) $filename. 2718 * If the extension was uppercase it was already replaced with the lowercase version. 2719 */ 2720 $filename = str_replace( 2721 array( "-{$number}{$lc_ext}", "{$number}{$lc_ext}" ), 2722 "-{$new_number}{$lc_ext}", 2723 $filename 2724 ); 2688 2725 2689 2726 $number = $new_number;
Note: See TracChangeset
for help on using the changeset viewer.