Index: branches/FileBackend/phase3/includes/filerepo/file/File.php |
— | — | @@ -834,8 +834,10 @@ |
835 | 835 | // Purge. Useful in the event of Core -> Squid connection failure or squid |
836 | 836 | // purge collisions from elsewhere during failure. Don't keep triggering for |
837 | 837 | // "thumbs" which have the main image URL though (bug 13776) |
838 | | - if ( $wgUseSquid && ( !$thumb || $thumb->isError() || $thumb->getUrl() != $this->getURL()) ) { |
839 | | - SquidUpdate::purge( array( $thumbUrl ) ); |
| 838 | + if ( $wgUseSquid ) { |
| 839 | + if ( !$thumb || $thumb->isError() || $thumb->getUrl() != $this->getURL() ) { |
| 840 | + SquidUpdate::purge( array( $thumbUrl ) ); |
| 841 | + } |
840 | 842 | } |
841 | 843 | } while (false); |
842 | 844 | |
Index: branches/FileBackend/phase3/includes/filerepo/backend/FSFileBackend.php |
— | — | @@ -6,7 +6,7 @@ |
7 | 7 | */ |
8 | 8 | |
9 | 9 | /** |
10 | | - * Class for a file-system based file backend. |
| 10 | + * Class for a file system based file backend. |
11 | 11 | * Status messages should avoid mentioning the internal FS paths. |
12 | 12 | * Likewise, error suppression should be used to path disclosure. |
13 | 13 | * |
— | — | @@ -449,17 +449,11 @@ |
450 | 450 | $i = strrpos( $source, '.' ); |
451 | 451 | $ext = strtolower( $i ? substr( $source, $i + 1 ) : '' ); |
452 | 452 | // Create a new temporary file... |
453 | | - wfSuppressWarnings(); |
454 | | - $initialTmpPath = tempnam( wfTempDir(), 'localcopy' ); |
455 | | - wfRestoreWarnings(); |
456 | | - if ( $initialTmpPath === false ) { |
| 453 | + $tmpFile = TempFSFile::factory( 'localcopy', $ext ); |
| 454 | + if ( !$tmpFile ) { |
457 | 455 | return null; |
458 | 456 | } |
459 | | - // Apply the original extension |
460 | | - $tmpPath = "{$initialTmpPath}.{$ext}"; |
461 | | - if ( !rename( $initialTmpPath, $tmpPath ) ) { |
462 | | - return null; |
463 | | - } |
| 457 | + $tmpPath = $tmpFile->getPath(); |
464 | 458 | |
465 | 459 | // Copy the source file over the temp file |
466 | 460 | wfSuppressWarnings(); |
Index: branches/FileBackend/phase3/img_auth.php |
— | — | @@ -72,37 +72,31 @@ |
73 | 73 | return; |
74 | 74 | } |
75 | 75 | |
76 | | - // Get the full file path |
77 | | - $filename = realpath( $wgUploadDirectory . $path ); |
78 | | - $realUpload = realpath( $wgUploadDirectory ); |
79 | | - |
80 | | - // Basic directory traversal check |
81 | | - if ( substr( $filename, 0, strlen( $realUpload ) ) != $realUpload ) { |
82 | | - wfForbidden( 'img-auth-accessdenied', 'img-auth-notindir' ); |
83 | | - return; |
| 76 | + // Get the local file repository |
| 77 | + $repo = RepoGroup::singleton()->getRepo( 'local' ); |
| 78 | + if ( !$repo ) { |
| 79 | + return; // wtf? |
84 | 80 | } |
85 | 81 | |
86 | | - // Check to see if the file exists |
87 | | - if ( !file_exists( $filename ) ) { |
88 | | - wfForbidden( 'img-auth-accessdenied','img-auth-nofile', $filename ); |
89 | | - return; |
90 | | - } |
91 | | - |
92 | | - // Check to see if tried to access a directory |
93 | | - if ( is_dir( $filename ) ) { |
94 | | - wfForbidden( 'img-auth-accessdenied','img-auth-isdir', $filename ); |
95 | | - return; |
96 | | - } |
97 | | - |
98 | | - // Extract the file name and chop off the size specifier. |
| 82 | + // Get the full file storage path and extract the source file name. |
99 | 83 | // (e.g. 120px-Foo.png => Foo.png or page2-120px-Foo.png => Foo.png). |
100 | 84 | // This only applies to thumbnails, and all thumbnails should |
101 | 85 | // be under a folder that has the source file name. |
102 | | - $name = wfBaseName( $path ); |
103 | 86 | if ( strpos( $path, '/thumb/' ) === 0 ) { |
104 | | - $name = wfBaseName( dirname( $path ) ); // this file is a thumbnail |
| 87 | + $name = wfBaseName( dirname( $path ) ); // file is a thumbnail |
| 88 | + $filename = $repo->getZonePath( 'thumb' ) . substr( $path, 6 ); // strip "/thumb" |
| 89 | + } else { |
| 90 | + $name = wfBaseName( $path ); // file is a source file |
| 91 | + $filename = $repo->getZonePath( 'public' ) . $path; |
105 | 92 | } |
106 | 93 | |
| 94 | + // Check to see if the file exists |
| 95 | + var_dump($filename); |
| 96 | + if ( !$repo->fileExists( $filename, FileRepo::FILES_ONLY ) ) { |
| 97 | + wfForbidden( 'img-auth-accessdenied','img-auth-nofile', $filename ); |
| 98 | + return; |
| 99 | + } |
| 100 | + |
107 | 101 | $title = Title::makeTitleSafe( NS_FILE, $name ); |
108 | 102 | if ( !$title instanceof Title ) { // files have valid titles |
109 | 103 | wfForbidden( 'img-auth-accessdenied', 'img-auth-badtitle', $name ); |
— | — | @@ -124,7 +118,7 @@ |
125 | 119 | |
126 | 120 | // Stream the requested file |
127 | 121 | wfDebugLog( 'img_auth', "Streaming `".$filename."`." ); |
128 | | - StreamFile::stream( $filename, array( 'Cache-Control: private', 'Vary: Cookie' ) ); |
| 122 | + $repo->streamFile( $filename, array( 'Cache-Control: private', 'Vary: Cookie' ) ); |
129 | 123 | } |
130 | 124 | |
131 | 125 | /** |
Index: branches/FileBackend/phase3/thumb.php |
— | — | @@ -86,6 +86,7 @@ |
87 | 87 | $headers[] = 'Vary: Cookie'; |
88 | 88 | } |
89 | 89 | |
| 90 | + // Check the source file storage path |
90 | 91 | if ( !$img ) { |
91 | 92 | wfThumbError( 404, wfMsg( 'badtitletext' ) ); |
92 | 93 | wfProfileOut( __METHOD__ ); |
— | — | @@ -204,4 +205,3 @@ |
205 | 206 | |
206 | 207 | EOT; |
207 | 208 | } |
208 | | - |