Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -1705,7 +1705,48 @@ |
1706 | 1706 | return true; |
1707 | 1707 | if( file_exists( $fullDir ) ) |
1708 | 1708 | return true; |
1709 | | - return mkdir( str_replace( '/', DIRECTORY_SEPARATOR, $fullDir ), $mode, true ); |
| 1709 | + |
| 1710 | + # Go back through the paths to find the first directory that exists |
| 1711 | + $currentDir = $fullDir; |
| 1712 | + $createList = array(); |
| 1713 | + while ( strval( $currentDir ) !== '' && !file_exists( $currentDir ) ) { |
| 1714 | + # Strip trailing slashes |
| 1715 | + $currentDir = rtrim( $currentDir, '/\\' ); |
| 1716 | + |
| 1717 | + # Add to create list |
| 1718 | + $createList[] = $currentDir; |
| 1719 | + |
| 1720 | + # Find next delimiter searching from the end |
| 1721 | + $p = max( strrpos( $currentDir, '/' ), strrpos( $currentDir, '\\' ) ); |
| 1722 | + if ( $p === false ) { |
| 1723 | + $currentDir = false; |
| 1724 | + } else { |
| 1725 | + $currentDir = substr( $currentDir, 0, $p ); |
| 1726 | + } |
| 1727 | + } |
| 1728 | + |
| 1729 | + if ( count( $createList ) == 0 ) { |
| 1730 | + # Directory specified already exists |
| 1731 | + return true; |
| 1732 | + } elseif ( $currentDir === false ) { |
| 1733 | + # Went all the way back to root and it apparently doesn't exist |
| 1734 | + return false; |
| 1735 | + } |
| 1736 | + |
| 1737 | + # Now go forward creating directories |
| 1738 | + $createList = array_reverse( $createList ); |
| 1739 | + foreach ( $createList as $dir ) { |
| 1740 | + # Check first to avoid spamming with warnings |
| 1741 | + if ( !is_writable( $dir ) ) { |
| 1742 | + return false; |
| 1743 | + } |
| 1744 | + # use chmod to override the umask, as suggested by the PHP manual |
| 1745 | + if ( !mkdir( $dir, $mode ) || !chmod( $dir, $mode ) ) { |
| 1746 | + wfDebugLog( 'mkdir', "Unable to create directory $dir\n" ); |
| 1747 | + return false; |
| 1748 | + } |
| 1749 | + } |
| 1750 | + return true; |
1710 | 1751 | } |
1711 | 1752 | |
1712 | 1753 | /** |