Ticket #19879: 19879.final.patch
| File 19879.final.patch, 7.6 KB (added by , 5 years ago) |
|---|
-
src/wp-includes/post.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
5866 5866 $file = get_attached_file( $post_id ); 5867 5867 5868 5868 if ( is_multisite() ) { 5869 delete_transient( 'dirsize_cache');5869 invalidate_dirsize_cache( $file ); 5870 5870 } 5871 5871 5872 5872 /** -
src/wp-admin/includes/file.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
928 928 $url = $uploads['url'] . "/$filename"; 929 929 930 930 if ( is_multisite() ) { 931 delete_transient( 'dirsize_cache');931 invalidate_dirsize_cache( $new_file ); 932 932 } 933 933 934 934 /** -
src/wp-includes/functions.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
2740 2740 // Compute the URL. 2741 2741 $url = $upload['url'] . "/$filename"; 2742 2742 2743 if ( is_multisite() ) { 2744 invalidate_dirsize_cache( $new_file ); 2745 } 2746 2743 2747 /** This filter is documented in wp-admin/includes/file.php */ 2744 2748 return apply_filters( 2745 2749 'wp_handle_upload', … … 7526 7530 * @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout. 7527 7531 */ 7528 7532 function get_dirsize( $directory, $max_execution_time = null ) { 7529 $dirsize = get_transient( 'dirsize_cache' );7530 7531 if ( is_array( $dirsize ) && isset( $dirsize[ $directory ]['size'] ) ) {7532 return $dirsize[ $directory ]['size'];7533 }7534 7535 if ( ! is_array( $dirsize ) ) {7536 $dirsize = array();7537 }7538 7533 7539 7534 // Exclude individual site directories from the total when checking the main site of a network, 7540 7535 // as they are subdirectories and should not be counted. 7541 7536 if ( is_multisite() && is_main_site() ) { 7542 $ dirsize[ $directory ]['size']= recurse_dirsize( $directory, $directory . '/sites', $max_execution_time );7537 $size = recurse_dirsize( $directory, $directory . '/sites', $max_execution_time ); 7543 7538 } else { 7544 $ dirsize[ $directory ]['size']= recurse_dirsize( $directory, null, $max_execution_time );7539 $size = recurse_dirsize( $directory, null, $max_execution_time ); 7545 7540 } 7546 7541 7547 set_transient( 'dirsize_cache', $dirsize, HOUR_IN_SECONDS ); 7548 return $dirsize[ $directory ]['size']; 7542 return $size; 7549 7543 } 7550 7544 7551 7545 /** … … 7557 7551 * @since MU (3.0.0) 7558 7552 * @since 4.3.0 $exclude parameter added. 7559 7553 * @since 5.2.0 $max_execution_time parameter added. 7554 * @since 5.6.0 $directory_cache parameter added. 7560 7555 * 7561 7556 * @param string $directory Full path of a directory. 7562 7557 * @param string|array $exclude Optional. Full path of a subdirectory to exclude from the total, 7563 7558 * or array of paths. Expected without trailing slash(es). 7564 7559 * @param int $max_execution_time Maximum time to run before giving up. In seconds. The timeout is global 7565 7560 * and is measured from the moment WordPress started to load. 7561 * @param array $directory_cache Optional. Array of cached directory paths. 7562 * 7566 7563 * @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout. 7567 7564 */ 7568 function recurse_dirsize( $directory, $exclude = null, $max_execution_time = null ) {7565 function recurse_dirsize( $directory, $exclude = null, $max_execution_time = null, &$directory_cache = null ) { 7569 7566 $size = 0; 7570 7567 7571 7568 $directory = untrailingslashit( $directory ); 7569 $cache_path = normalize_dirsize_cache_path( $directory ); 7570 $save_cache = false; 7571 7572 if ( ! isset( $directory_cache ) ) { 7573 $directory_cache = get_transient( 'dirsize_cache' ); 7574 $save_cache = true; 7575 } 7576 7577 if ( isset( $directory_cache[ $cache_path ] ) ) { 7578 return $directory_cache[ $cache_path ]; 7579 } 7572 7580 7573 7581 if ( ! file_exists( $directory ) || ! is_dir( $directory ) || ! is_readable( $directory ) ) { 7574 7582 return false; … … 7596 7604 } 7597 7605 } 7598 7606 7599 $handle = opendir( $directory ); 7600 if ( $handle ) { 7601 while ( ( $file = readdir( $handle ) ) !== false ) { 7602 $path = $directory . '/' . $file; 7603 if ( '.' !== $file && '..' !== $file ) { 7604 if ( is_file( $path ) ) { 7605 $size += filesize( $path ); 7606 } elseif ( is_dir( $path ) ) { 7607 $handlesize = recurse_dirsize( $path, $exclude, $max_execution_time ); 7608 if ( $handlesize > 0 ) { 7609 $size += $handlesize; 7610 } 7611 } 7607 /** 7608 * Filters the amount of storage space used by one directory and all it's children, in megabytes. 7609 * Return the actual used space to shortcircuit the recursive PHP file size calculation and use something else 7610 * like a CDN API or native operating system tools for better performance 7611 * 7612 * @since 5.6.0 7613 * 7614 * @param int|false $space_used The amount of used space, in bytes. Default 0. 7615 */ 7616 $size = apply_filters( 'calculate_current_dirsize', $size, $directory, $exclude, $max_execution_time, $directory_cache ); 7617 7618 if ( 0 === $size ) { 7619 $handle = opendir( $directory ); 7620 if ( $handle ) { 7621 while ( ( $file = readdir( $handle ) ) !== false ) { 7622 $path = $directory . '/' . $file; 7623 if ( '.' !== $file && '..' !== $file ) { 7624 if ( is_file( $path ) ) { 7625 $size += filesize( $path ); 7626 } elseif ( is_dir( $path ) ) { 7627 $handlesize = recurse_dirsize( $path, $exclude, $max_execution_time, $directory_cache ); 7628 if ( $handlesize > 0 ) { 7629 $size += $handlesize; 7630 } 7631 } 7612 7632 7613 if ( $max_execution_time > 0 && microtime( true ) - WP_START_TIMESTAMP > $max_execution_time ) { 7614 // Time exceeded. Give up instead of risking a fatal timeout. 7615 $size = null; 7616 break; 7617 } 7618 } 7619 } 7620 closedir( $handle ); 7633 if ( $max_execution_time > 0 && microtime( true ) - WP_START_TIMESTAMP > $max_execution_time ) { 7634 // Time exceeded. Give up instead of risking a fatal timeout. 7635 $size = null; 7636 break; 7637 } 7638 } 7639 } 7640 closedir( $handle ); 7641 } 7621 7642 } 7643 $directory_cache[ $cache_path ] = $size; 7644 7645 // Only write the transient on the top level call and not on recursive calls 7646 if ( $save_cache ) { 7647 set_transient( 'dirsize_cache', $directory_cache ); 7648 } 7649 7622 7650 return $size; 7623 7651 } 7624 7652 7653 /** 7654 * Invalidates entries within the dirsize_cache 7655 * 7656 * Remove the current directory and all parent directories 7657 * from the dirsize_cache transient. 7658 * 7659 * @since 5.6.0 7660 * 7661 * @param string $path Full path of a directory or file. 7662 */ 7663 function invalidate_dirsize_cache( $path ) { 7664 $directory_cache = get_transient( 'dirsize_cache' ); 7665 7666 if ( empty( $directory_cache ) ) { 7667 return; 7668 } 7669 7670 $cache_path = normalize_dirsize_cache_path( $path ); 7671 unset( $directory_cache[ $cache_path ] ); 7672 7673 while ( DIRECTORY_SEPARATOR !== $cache_path && '.' !== $cache_path && '..' !== $cache_path ) { 7674 $cache_path = dirname( $cache_path ); 7675 unset( $directory_cache[ $cache_path ] ); 7676 } 7677 7678 set_transient( 'dirsize_cache', $directory_cache ); 7679 } 7680 7681 /** 7682 * Normalize dirsize cache path. 7683 * 7684 * Ensures array keys within the dirsize_cache transient follow the same format. 7685 * 7686 * @since 5.6.0 7687 * 7688 * @param string $path 7689 * @return string 7690 */ 7691 function normalize_dirsize_cache_path( $path ) { 7692 $path = str_replace( ABSPATH, '', $path ); 7693 7694 return untrailingslashit( $path ); 7695 } 7696 7625 7697 /** 7626 7698 * Checks compatibility with the current WordPress version. 7627 7699 *