Index: branches/REL1_5/phase3/thumb.php |
— | — | @@ -44,7 +44,7 @@ |
45 | 45 | } |
46 | 46 | $thumbPath = wfImageThumbDir( $fileName ) . '/' . $thumbName; |
47 | 47 | |
48 | | -if ( file_exists( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) { |
| 48 | +if ( is_file( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) { |
49 | 49 | wfStreamFile( $thumbPath ); |
50 | 50 | exit; |
51 | 51 | } |
Index: branches/REL1_5/phase3/includes/Image.php |
— | — | @@ -960,12 +960,40 @@ |
961 | 961 | $thumbName = $this->thumbName( $width, $this->fromSharedDirectory ); |
962 | 962 | $thumbPath = wfImageThumbDir( $this->name, $this->fromSharedDirectory ).'/'.$thumbName; |
963 | 963 | |
| 964 | + if ( is_dir( $thumbPath ) ) { |
| 965 | + // Directory where file should be |
| 966 | + // This happened occasionally due to broken migration code in 1.5 |
| 967 | + // Rename to broken-* |
| 968 | + global $wgUploadDirectory; |
| 969 | + for ( $i = 0; $i < 100 ; $i++ ) { |
| 970 | + $broken = "$wgUploadDirectory/broken-$i-$thumbName"; |
| 971 | + if ( !file_exists( $broken ) ) { |
| 972 | + rename( $thumbPath, $broken ); |
| 973 | + break; |
| 974 | + } |
| 975 | + } |
| 976 | + // Code below will ask if it exists, and the answer is now no |
| 977 | + clearstatcache(); |
| 978 | + } |
| 979 | + |
964 | 980 | if ( !file_exists( $thumbPath ) ) { |
965 | 981 | $oldThumbPath = wfDeprecatedThumbDir( $thumbName, 'thumb', $this->fromSharedDirectory ). |
966 | 982 | '/'.$thumbName; |
967 | 983 | $done = false; |
968 | | - if ( file_exists( $oldThumbPath ) ) { |
| 984 | + |
| 985 | + // Migration from old directory structure |
| 986 | + if ( is_file( $oldThumbPath ) ) { |
969 | 987 | if ( filemtime($oldThumbPath) >= filemtime($this->imagePath) ) { |
| 988 | + if ( file_exists( $thumbPath ) ) { |
| 989 | + if ( !is_dir( $thumbPath ) ) { |
| 990 | + // Old image in the way of rename |
| 991 | + unlink( $thumbPath ); |
| 992 | + } else { |
| 993 | + // This should have been dealt with already |
| 994 | + wfDebugDieBacktrace( "Directory where image should be: $thumbPath" ); |
| 995 | + } |
| 996 | + } |
| 997 | + // Rename the old image into the new location |
970 | 998 | rename( $oldThumbPath, $thumbPath ); |
971 | 999 | $done = true; |
972 | 1000 | } else { |
— | — | @@ -1542,7 +1570,11 @@ |
1543 | 1571 | umask( $oldumask ); |
1544 | 1572 | } |
1545 | 1573 | |
1546 | | - if ( ! is_dir( $dir ) ) { |
| 1574 | + if ( ! is_dir( $dir ) ) { |
| 1575 | + if ( is_file( $dir ) ) { |
| 1576 | + // Old thumbnail in the way of directory creation, kill it |
| 1577 | + unlink( $dir ); |
| 1578 | + } |
1547 | 1579 | $oldumask = umask(0); |
1548 | 1580 | @mkdir( $dir, 0777 ); |
1549 | 1581 | umask( $oldumask ); |