Index: trunk/phase3/thumb.php |
— | — | @@ -49,7 +49,7 @@ |
50 | 50 | } |
51 | 51 | $thumbPath = wfImageThumbDir( $fileName ) . '/' . $thumbName; |
52 | 52 | |
53 | | -if ( file_exists( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) { |
| 53 | +if ( is_file( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) { |
54 | 54 | wfStreamFile( $thumbPath ); |
55 | 55 | exit; |
56 | 56 | } |
Index: trunk/phase3/includes/Image.php |
— | — | @@ -967,13 +967,41 @@ |
968 | 968 | $thumbName = $this->thumbName( $width, $this->fromSharedDirectory ); |
969 | 969 | $thumbPath = wfImageThumbDir( $this->name, $this->fromSharedDirectory ).'/'.$thumbName; |
970 | 970 | |
| 971 | + if ( is_dir( $thumbPath ) ) { |
| 972 | + // Directory where file should be |
| 973 | + // This happened occasionally due to broken migration code in 1.5 |
| 974 | + // Rename to broken-* |
| 975 | + global $wgUploadDirectory; |
| 976 | + for ( $i = 0; $i < 100 ; $i++ ) { |
| 977 | + $broken = "$wgUploadDirectory/broken-$i-$thumbName"; |
| 978 | + if ( !file_exists( $broken ) ) { |
| 979 | + rename( $thumbPath, $broken ); |
| 980 | + break; |
| 981 | + } |
| 982 | + } |
| 983 | + // Code below will ask if it exists, and the answer is now no |
| 984 | + clearstatcache(); |
| 985 | + } |
| 986 | + |
971 | 987 | if ( !file_exists( $thumbPath ) || |
972 | 988 | filemtime( $thumbPath ) < wfTimestamp( TS_UNIX, $wgThumbnailEpoch ) ) { |
973 | 989 | $oldThumbPath = wfDeprecatedThumbDir( $thumbName, 'thumb', $this->fromSharedDirectory ). |
974 | 990 | '/'.$thumbName; |
975 | 991 | $done = false; |
976 | | - if ( file_exists( $oldThumbPath ) ) { |
| 992 | + |
| 993 | + // Migration from old directory structure |
| 994 | + if ( is_file( $oldThumbPath ) ) { |
977 | 995 | if ( filemtime($oldThumbPath) >= filemtime($this->imagePath) ) { |
| 996 | + if ( file_exists( $thumbPath ) ) { |
| 997 | + if ( !is_dir( $thumbPath ) ) { |
| 998 | + // Old image in the way of rename |
| 999 | + unlink( $thumbPath ); |
| 1000 | + } else { |
| 1001 | + // This should have been dealt with already |
| 1002 | + wfDebugDieBacktrace( "Directory where image should be: $thumbPath" ); |
| 1003 | + } |
| 1004 | + } |
| 1005 | + // Rename the old image into the new location |
978 | 1006 | rename( $oldThumbPath, $thumbPath ); |
979 | 1007 | $done = true; |
980 | 1008 | } else { |
— | — | @@ -1608,6 +1636,10 @@ |
1609 | 1637 | } |
1610 | 1638 | |
1611 | 1639 | if ( ! is_dir( $dir ) ) { |
| 1640 | + if ( is_file( $dir ) ) { |
| 1641 | + // Old thumbnail in the way of directory creation, kill it |
| 1642 | + unlink( $dir ); |
| 1643 | + } |
1612 | 1644 | $oldumask = umask(0); |
1613 | 1645 | @mkdir( $dir, 0777 ); |
1614 | 1646 | umask( $oldumask ); |