r104895 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104894‎ | r104895 | r104896 >
Date:20:47, 1 December 2011
Author:aaron
Status:deferred
Tags:
Comment:
* Updated img_auth.php to handle storage paths
* Made FSFileBackend::getLocalCopy make better use TempFSFile methods
* Broke up long line in File:transform
Modified paths:
  • /branches/FileBackend/phase3/img_auth.php (modified) (history)
  • /branches/FileBackend/phase3/includes/filerepo/backend/FSFileBackend.php (modified) (history)
  • /branches/FileBackend/phase3/includes/filerepo/file/File.php (modified) (history)
  • /branches/FileBackend/phase3/thumb.php (modified) (history)

Diff [purge]

Index: branches/FileBackend/phase3/includes/filerepo/file/File.php
@@ -834,8 +834,10 @@
835835 // Purge. Useful in the event of Core -> Squid connection failure or squid
836836 // purge collisions from elsewhere during failure. Don't keep triggering for
837837 // "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+ }
840842 }
841843 } while (false);
842844
Index: branches/FileBackend/phase3/includes/filerepo/backend/FSFileBackend.php
@@ -6,7 +6,7 @@
77 */
88
99 /**
10 - * Class for a file-system based file backend.
 10+ * Class for a file system based file backend.
1111 * Status messages should avoid mentioning the internal FS paths.
1212 * Likewise, error suppression should be used to path disclosure.
1313 *
@@ -449,17 +449,11 @@
450450 $i = strrpos( $source, '.' );
451451 $ext = strtolower( $i ? substr( $source, $i + 1 ) : '' );
452452 // 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 ) {
457455 return null;
458456 }
459 - // Apply the original extension
460 - $tmpPath = "{$initialTmpPath}.{$ext}";
461 - if ( !rename( $initialTmpPath, $tmpPath ) ) {
462 - return null;
463 - }
 457+ $tmpPath = $tmpFile->getPath();
464458
465459 // Copy the source file over the temp file
466460 wfSuppressWarnings();
Index: branches/FileBackend/phase3/img_auth.php
@@ -72,37 +72,31 @@
7373 return;
7474 }
7575
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?
8480 }
8581
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.
9983 // (e.g. 120px-Foo.png => Foo.png or page2-120px-Foo.png => Foo.png).
10084 // This only applies to thumbnails, and all thumbnails should
10185 // be under a folder that has the source file name.
102 - $name = wfBaseName( $path );
10386 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;
10592 }
10693
 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+
107101 $title = Title::makeTitleSafe( NS_FILE, $name );
108102 if ( !$title instanceof Title ) { // files have valid titles
109103 wfForbidden( 'img-auth-accessdenied', 'img-auth-badtitle', $name );
@@ -124,7 +118,7 @@
125119
126120 // Stream the requested file
127121 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' ) );
129123 }
130124
131125 /**
Index: branches/FileBackend/phase3/thumb.php
@@ -86,6 +86,7 @@
8787 $headers[] = 'Vary: Cookie';
8888 }
8989
 90+ // Check the source file storage path
9091 if ( !$img ) {
9192 wfThumbError( 404, wfMsg( 'badtitletext' ) );
9293 wfProfileOut( __METHOD__ );
@@ -204,4 +205,3 @@
205206
206207 EOT;
207208 }
208 -

Status & tagging log