r74017 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74016‎ | r74017 | r74018 >
Date:11:26, 30 September 2010
Author:neilk
Status:deferred
Tags:
Comment:
Modified paths:
  • /branches/uploadwizard/phase3/includes/specials/SpecialSessionStash.php (modified) (history)
  • /branches/uploadwizard/phase3/includes/upload/SessionStash.php (modified) (history)

Diff [purge]

Index: branches/uploadwizard/phase3/includes/upload/SessionStash.php
@@ -31,7 +31,7 @@
3232 * Designed to be compatible with the session stashing code in UploadBase (should replace eventually)
3333 * @param {FileRepo} optional -- repo in which to store files. Will choose LocalRepo if not supplied.
3434 */
35 - public function __construct( $repo=null ) {
 35+ public function __construct( $repo = null ) {
3636
3737 if ( is_null( $repo ) ) {
3838 $repo = RepoGroup::singleton()->getLocalRepo();
@@ -81,7 +81,7 @@
8282
8383 // guards against PHP class changing while session data doesn't
8484 if ($stashData['version'] !== UploadBase::SESSION_VERSION ) {
85 - return self::$error['outdated session version'];
 85+ throw new MWException( 'outdated session version' );
8686 }
8787
8888 // The path is flattened in with the other random props so we have to dig it out.
@@ -108,7 +108,7 @@
109109 * @param {Array} data - other data you want added to the session. Do not use 'mTempPath', 'mFileProps', 'mFileSize', or version as keys here
110110 * @return {SessionStashFile} file
111111 */
112 - public function stashFile( $key, $path, $data=array() ) {
 112+ public function stashFile( $key, $path, $data = array() ) {
113113 if ( !$key ) {
114114 $key = mt_rand( 0, 0x7fffffff );
115115 }
@@ -196,36 +196,6 @@
197197 }
198198
199199 /**
200 - * Test if a path looks like it's in the right place
201 - *
202 - * @param {String} $path
203 - * @return {Boolean}
204 - */
205 - public function isPathValid( $path ) {
206 -
207 - if ( strval( $filename ) == '' ) {
208 - return false;
209 - }
210 -
211 - /**
212 - * Lifted this bit from extensions/WebStore::validateFilename.
213 - * Use the same traversal protection as Title::secureAndSplit()
214 - */
215 - if ( strpos( $filename, '.' ) !== false &&
216 - ( $filename === '.' || $filename === '..' ||
217 - strpos( $filename, './' ) === 0 ||
218 - strpos( $filename, '../' ) === 0 ||
219 - strpos( $filename, '/./' ) !== false ||
220 - strpos( $filename, '/../' ) !== false ) ) {
221 - return false;
222 - }
223 -
224 -
225 - return true;
226 -
227 - }
228 -
229 - /**
230200 * A method needed by the file transforming and scaling routines in File.php
231201 * We do not necessarily care about doing the description at this point
232202 * @return {String} the empty string
@@ -275,7 +245,7 @@
276246 * @param {String|false} name of thumbnail (e.g. "120px-123456.jpg" ), or false to just get the path
277247 * @return {String} path thumbnail should take on filesystem, or containing directory if thumbname is false
278248 */
279 - public function getThumbPath( $thumbName=false ) {
 249+ public function getThumbPath( $thumbName = false ) {
280250 $path = dirname( $this->path );
281251 if ( $thumbName !== false ) {
282252 $path .= "/$thumbName";
@@ -311,7 +281,7 @@
312282 * @param {String} basename of thumbnail file -- however, we don't want to use the file exactly
313283 * @return {String} URL to access thumbnail, or URL with partial path
314284 */
315 - public function getThumbUrl( $thumbName=false ) {
 285+ public function getThumbUrl( $thumbName = false ) {
316286 $path = $this->sessionStash->getBaseUrl();
317287 $extension = $this->getExtension();
318288 if ( $thumbName !== false ) {
@@ -367,7 +337,7 @@
368338 * @param {Bitmask} flags suitable for File::transform()
369339 * @return {ThumbnailImage} with additional File thumbnailFile property
370340 */
371 - public function transform( $params, $flags=0 ) {
 341+ public function transform( $params, $flags = 0 ) {
372342
373343 // force it to get a thumbnail right away
374344 $flags |= self::RENDER_NOW;
Index: branches/uploadwizard/phase3/includes/specials/SpecialSessionStash.php
@@ -33,13 +33,9 @@
3434
3535 // $request is the request (usually wgRequest)
3636 // $subpage is everything in the URL after Special:SessionStash
37 - public function __construct( $request=null, $subpage=null ) {
38 - global $wgRequest;
39 -
 37+ public function __construct( $request = null, $subpage = null ) {
4038 parent::__construct( 'SessionStash', 'upload' );
41 -
4239 $this->stash = new SessionStash();
43 -
4440 }
4541
4642 /**
@@ -55,7 +51,6 @@
5652 // prevent callers from doing standard HTML output -- we'll take it from here
5753 $wgOut->disable();
5854
59 - // global $wgScriptPath, $wgLang, $wgUser, $wgOut;
6055 wfDebug( __METHOD__ . " in subpage for $subPage \n" );
6156
6257 try {
@@ -67,16 +62,14 @@
6863 return true;
6964
7065 } catch( SessionStashFileNotFoundException $e ) {
71 - wfHttpError( 404, self::$HttpErrors[404], $e->getCode(), $e->getMessage() );
72 -
 66+ $code = 404;
7367 } catch( SessionStashBadPathException $e ) {
74 - wfHttpError( 403, self::$HttpErrors[403], $e->getCode(), $e->getMessage() );
75 -
 68+ $code = 403;
7669 } catch( Exception $e ) {
77 - wfHttpError( $code, self::$HttpErrors[$code], $e->getCode(), $e->getMessage() );
78 -
 70+ $code = 500;
7971 }
8072
 73+ wfHttpError( $code, self::$HttpErrors[$code], $e->getCode(), $e->getMessage() );
8174 return false;
8275 }
8376
@@ -106,11 +99,11 @@
107100 * @param {File} file
108101 */
109102 private function outputFile( $file ) {
110 - header( 'Content-Type: ' . $file->getMimeType() );
111 - header( 'Content-Transfer-Encoding: binary' );
112 - header( 'Expires: Sun, 17-Jan-2038 19:14:07 GMT' );
113 - header( 'Pragma: public' );
114 - header( 'Content-Length: ' . $file->getSize() );
 103+ header( 'Content-Type: ' . $file->getMimeType(), true );
 104+ header( 'Content-Transfer-Encoding: binary', true );
 105+ header( 'Expires: Sun, 17-Jan-2038 19:14:07 GMT', true );
 106+ header( 'Pragma: public', true );
 107+ header( 'Content-Length: ' . $file->getSize(), true );
115108 readfile( $file->getPath() );
116109 }
117110 }

Status & tagging log