r70049 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70048‎ | r70049 | r70050 >
Date:21:53, 27 July 2010
Author:btongminh
Status:ok (Comments)
Tags:
Comment:
Follow-up r70037: Fix ApiUpload by passing a WebRequestUpload to the the initializer
Follow-up r64403 and r69911: Fix broken upload from stash in Api.

Please tests your commits, even if the change seems totally harmless. You can use <http://mwclient.svn.sourceforge.net/viewvc/mwclient/tests/upload_api_test.py?revision=HEAD&amp;view=markup&gt; to automatically test uploading via the Api.
Modified paths:
  • /trunk/phase3/includes/api/ApiUpload.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadFromFile.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadFromFile.php
@@ -8,25 +8,24 @@
99 * Implements regular file uploads
1010 */
1111 class UploadFromFile extends UploadBase {
12 - protected $mWebUpload = null;
 12+ protected $mUpload = null;
1313
1414 function initializeFromRequest( &$request ) {
15 - $this->mWebUpload = $request->getUpload( 'wpUploadFile' );
16 -
 15+ $upload = $request->getUpload( 'wpUploadFile' );
1716 $desiredDestName = $request->getText( 'wpDestFile' );
1817 if( !$desiredDestName )
19 - $desiredDestName = $this->mWebUpload->getName();
20 - return $this->initializePathInfo(
21 - $desiredDestName,
22 - $this->mWebUpload->getTempName(),
23 - $this->mWebUpload->getSize()
24 - );
 18+ $desiredDestName = $upload->getName();
 19+
 20+ return $this->initialize( $desiredDestName, $upload );
2521 }
 22+
2623 /**
27 - * Entry point for upload from file.
 24+ * Initialize from a filename and a WebRequestUpload
2825 */
29 - function initialize( $name, $tempPath, $fileSize ) {
30 - return $this->initializePathInfo( $name, $tempPath, $fileSize );
 26+ function initialize( $name, $webRequestUpload ) {
 27+ $this->mUpload = $webRequestUpload;
 28+ return $this->initializePathInfo( $name,
 29+ $this->mUpload->getTempName(), $this->mUpload->getSize() );
3130 }
3231 static function isValidRequest( $request ) {
3332 # Allow all requests, even if no file is present, so that an error
@@ -38,7 +37,7 @@
3938 # Check for a post_max_size or upload_max_size overflow, so that a
4039 # proper error can be shown to the user
4140 if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
42 - if ( $this->mWebUpload->isIniSizeOverflow() ) {
 41+ if ( $this->mUpload->isIniSizeOverflow() ) {
4342 global $wgMaxUploadSize;
4443 return array(
4544 'status' => self::FILE_TOO_LARGE,
Index: trunk/phase3/includes/api/ApiUpload.php
@@ -54,72 +54,65 @@
5555 // One and only one of the following parameters is needed
5656 $this->requireOnlyOneParameter( $this->mParams,
5757 'sessionkey', 'file', 'url' );
 58+ // And this one is needed
 59+ if ( !isset( $this->mParams['filename'] ) ) {
 60+ $this->dieUsageMsg( array( 'missingparam', 'filename' ) );
 61+ }
5862
 63+
5964 if ( $this->mParams['sessionkey'] ) {
60 - /**
61 - * Upload stashed in a previous request
62 - */
63 - // Check the session key
64 - if ( !isset( $_SESSION[$this->mUpload->getSessionKey()][$this->mParams['sessionkey']] ) ) {
 65+ // Upload stashed in a previous request
 66+ $sessionData = $request->getSessionData( UploadBase::SESSION_KEYNAME );
 67+ if ( !UploadFromStash::isValidSessionKey( $this->mParams['sessionkey'], $sessionData ) ) {
6568 $this->dieUsageMsg( array( 'invalid-session-key' ) );
6669 }
6770
6871 $this->mUpload = new UploadFromStash();
6972 $this->mUpload->initialize( $this->mParams['filename'],
7073 $this->mParams['sessionkey'],
71 - $_SESSION[$this->mUpload->getSessionKey()][$this->mParams['sessionkey']] );
72 - } elseif ( isset( $this->mParams['filename'] ) ) {
73 - /**
74 - * Upload from URL, etc.
75 - * Parameter filename is required
76 - */
77 - if ( isset( $this->mParams['file'] ) ) {
78 - $this->mUpload = new UploadFromFile();
79 - $this->mUpload->initialize(
80 - $this->mParams['filename'],
81 - $request->getFileTempName( 'file' ),
82 - $request->getFileSize( 'file' )
83 - );
84 - } elseif ( isset( $this->mParams['url'] ) ) {
85 - // make sure upload by URL is enabled:
86 - if ( !$wgAllowCopyUploads ) {
87 - $this->dieUsageMsg( array( 'copyuploaddisabled' ) );
88 - }
 74+ $sessionData[$this->mParams['sessionkey']] );
 75+
 76+
 77+ } elseif ( isset( $this->mParams['file'] ) ) {
 78+ $this->mUpload = new UploadFromFile();
 79+ $this->mUpload->initialize(
 80+ $this->mParams['filename'],
 81+ $request->getUpload( 'file' )
 82+ );
 83+ } elseif ( isset( $this->mParams['url'] ) ) {
 84+ // Make sure upload by URL is enabled:
 85+ if ( !$wgAllowCopyUploads ) {
 86+ $this->dieUsageMsg( array( 'copyuploaddisabled' ) );
 87+ }
8988
90 - // make sure the current user can upload
91 - if ( !$wgUser->isAllowed( 'upload_by_url' ) ) {
92 - $this->dieUsageMsg( array( 'badaccess-groups' ) );
93 - }
 89+ $this->mUpload = new UploadFromUrl;
 90+ $async = $this->mParams['asyncdownload'] ? 'async' : null;
 91+ $this->checkPermissions( $wgUser );
9492
95 - $this->mUpload = new UploadFromUrl;
96 - $async = $this->mParams['asyncdownload'] ? 'async' : null;
 93+ $result = $this->mUpload->initialize(
 94+ $this->mParams['filename'],
 95+ $this->mParams['url'],
 96+ $this->mParams['comment'],
 97+ $this->mParams['watchlist'],
 98+ $this->mParams['ignorewarnings'],
 99+ $async );
 100+
 101+ if ( $async ) {
 102+ $this->getResult()->addValue( null,
 103+ $this->getModuleName(),
 104+ array( 'queued' => $result ) );
 105+ return;
 106+ }
97107
98 - $result = $this->mUpload->initialize( $this->mParams['filename'],
99 - $this->mParams['url'],
100 - $this->mParams['comment'],
101 - $this->mParams['watchlist'],
102 - $this->mParams['ignorewarnings'],
103 - $async );
104 -
105 - $this->checkPermissions( $wgUser );
106 - if ( $async ) {
107 - $this->getResult()->addValue( null,
108 - $this->getModuleName(),
109 - array( 'queued' => $result ) );
110 - return;
111 - }
112 -
113 - $status = $this->mUpload->retrieveFileFromUrl();
114 - if ( !$status->isGood() ) {
115 - $this->getResult()->addValue( null,
116 - $this->getModuleName(),
117 - array( 'error' => $status ) );
118 - return;
119 - }
 108+ $status = $this->mUpload->retrieveFileFromUrl();
 109+ if ( !$status->isGood() ) {
 110+ $this->getResult()->addValue( null,
 111+ $this->getModuleName(),
 112+ array( 'error' => $status ) );
 113+ return;
120114 }
121 - } else {
122 - $this->dieUsageMsg( array( 'missingparam', 'filename' ) );
123115 }
 116+
124117
125118 $this->checkPermissions( $wgUser );
126119

Follow-up revisions

RevisionCommit summaryAuthorDate
r76096Merge UploadFromFile.php changes in r70037 and r70049, but without the max fi...catrope14:42, 5 November 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r64403* Set $titleObj to null by default on getWatchlistValue since it often isn't ...mah19:10, 30 March 2010
r69911Fixup some more wrong static usagesreedy21:08, 25 July 2010
r70037(bug 23380) Uploaded files that are larger than allowed by PHP now show a use...btongminh20:38, 27 July 2010

Comments

#Comment by Bryan (talk | contribs)   21:56, 27 July 2010

Apologies for the dedentation mess. See r1=70048&r2=70049 ViewVC for a readable diff.

Status & tagging log