Docs: Correct the format of some comments per the documentation standards.

Follow-up to [10357], [10939], [43309], [51003], [51266], [51653], [51738], [52110].

See #53399.
Built from https://develop.svn.wordpress.org/trunk@52352


git-svn-id: http://core.svn.wordpress.org/trunk@51944 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov
2021-12-10 20:30:05 +00:00
parent 88b1019dc3
commit 3beb1d25ab
11 changed files with 79 additions and 43 deletions

View File

@@ -2538,8 +2538,10 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null )
$filename = str_replace( "{$fname}{$ext}", "{$fname}-{$number}{$ext}", $filename );
}
// Get the mime type. Uploaded files were already checked with wp_check_filetype_and_ext()
// in _wp_handle_upload(). Using wp_check_filetype() would be sufficient here.
/*
* Get the mime type. Uploaded files were already checked with wp_check_filetype_and_ext()
* in _wp_handle_upload(). Using wp_check_filetype() would be sufficient here.
*/
$file_type = wp_check_filetype( $filename );
$mime_type = $file_type['type'];
@@ -2550,27 +2552,40 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null )
$lc_ext = strtolower( $ext );
$_dir = trailingslashit( $dir );
// If the extension is uppercase add an alternate file name with lowercase extension. Both need to be tested
// for uniqueness as the extension will be changed to lowercase for better compatibility with different filesystems.
// Fixes an inconsistency in WP < 2.9 where uppercase extensions were allowed but image sub-sizes were created with
// lowercase extensions.
/*
* If the extension is uppercase add an alternate file name with lowercase extension.
* Both need to be tested for uniqueness as the extension will be changed to lowercase
* for better compatibility with different filesystems. Fixes an inconsistency in WP < 2.9
* where uppercase extensions were allowed but image sub-sizes were created with
* lowercase extensions.
*/
if ( $ext && $lc_ext !== $ext ) {
$lc_filename = preg_replace( '|' . preg_quote( $ext ) . '$|', $lc_ext, $filename );
}
// Increment the number added to the file name if there are any files in $dir whose names match one of the
// possible name variations.
/*
* Increment the number added to the file name if there are any files in $dir
* whose names match one of the possible name variations.
*/
while ( file_exists( $_dir . $filename ) || ( $lc_filename && file_exists( $_dir . $lc_filename ) ) ) {
$new_number = (int) $number + 1;
if ( $lc_filename ) {
$lc_filename = str_replace( array( "-{$number}{$lc_ext}", "{$number}{$lc_ext}" ), "-{$new_number}{$lc_ext}", $lc_filename );
$lc_filename = str_replace(
array( "-{$number}{$lc_ext}", "{$number}{$lc_ext}" ),
"-{$new_number}{$lc_ext}",
$lc_filename
);
}
if ( '' === "{$number}{$ext}" ) {
$filename = "{$filename}-{$new_number}";
} else {
$filename = str_replace( array( "-{$number}{$ext}", "{$number}{$ext}" ), "-{$new_number}{$ext}", $filename );
$filename = str_replace(
array( "-{$number}{$ext}", "{$number}{$ext}" ),
"-{$new_number}{$ext}",
$filename
);
}
$number = $new_number;
@@ -2581,8 +2596,10 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null )
$filename = $lc_filename;
}
// Prevent collisions with existing file names that contain dimension-like strings
// (whether they are subsizes or originals uploaded prior to #42437).
/*
* Prevent collisions with existing file names that contain dimension-like strings
* (whether they are subsizes or originals uploaded prior to #42437).
*/
$files = array();
$count = 10000;
@@ -2617,15 +2634,21 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null )
if ( ! empty( $files ) ) {
$count = count( $files );
// Ensure this never goes into infinite loop
// as it uses pathinfo() and regex in the check, but string replacement for the changes.
/*
* Ensure this never goes into infinite loop as it uses pathinfo() and regex in the check,
* but string replacement for the changes.
*/
$i = 0;
while ( $i <= $count && _wp_check_existing_file_names( $filename, $files ) ) {
$new_number = (int) $number + 1;
// If $ext is uppercase it was replaced with the lowercase version after the previous loop.
$filename = str_replace( array( "-{$number}{$lc_ext}", "{$number}{$lc_ext}" ), "-{$new_number}{$lc_ext}", $filename );
$filename = str_replace(
array( "-{$number}{$lc_ext}", "{$number}{$lc_ext}" ),
"-{$new_number}{$lc_ext}",
$filename
);
$number = $new_number;
$i++;
@@ -2633,8 +2656,10 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null )
}
}
// Check if an image will be converted after uploading or some existing images sub-sizes file names may conflict
// when regenerated. If yes, ensure the new file name will be unique and will produce unique sub-sizes.
/*
* Check if an image will be converted after uploading or some existing image sub-size file names may conflict
* when regenerated. If yes, ensure the new file name will be unique and will produce unique sub-sizes.
*/
if ( $is_image ) {
/** This filter is documented in wp-includes/class-wp-image-editor.php */
$output_formats = apply_filters( 'image_editor_output_format', array(), $_dir . $filename, $mime_type );
@@ -2668,8 +2693,10 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null )
}
if ( ! empty( $alt_filenames ) ) {
// Add the original filename. It needs to be checked again together with the alternate filenames
// when $number is incremented.
/*
* Add the original filename. It needs to be checked again
* together with the alternate filenames when $number is incremented.
*/
$alt_filenames[ $lc_ext ] = $filename;
// Ensure no infinite loop.
@@ -2679,12 +2706,22 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null )
$new_number = (int) $number + 1;
foreach ( $alt_filenames as $alt_ext => $alt_filename ) {
$alt_filenames[ $alt_ext ] = str_replace( array( "-{$number}{$alt_ext}", "{$number}{$alt_ext}" ), "-{$new_number}{$alt_ext}", $alt_filename );
$alt_filenames[ $alt_ext ] = str_replace(
array( "-{$number}{$alt_ext}", "{$number}{$alt_ext}" ),
"-{$new_number}{$alt_ext}",
$alt_filename
);
}
// Also update the $number in (the output) $filename.
// If the extension was uppercase it was already replaced with the lowercase version.
$filename = str_replace( array( "-{$number}{$lc_ext}", "{$number}{$lc_ext}" ), "-{$new_number}{$lc_ext}", $filename );
/*
* Also update the $number in (the output) $filename.
* If the extension was uppercase it was already replaced with the lowercase version.
*/
$filename = str_replace(
array( "-{$number}{$lc_ext}", "{$number}{$lc_ext}" ),
"-{$new_number}{$lc_ext}",
$filename
);
$number = $new_number;
$i++;