r61779 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61778‎ | r61779 | r61780 >
Date:07:05, 1 February 2010
Author:mah
Status:deferred (Comments)
Tags:
Comment:
follow up r61355, initial, incomplete dealing with TimStarlings CR
Modified paths:
  • /trunk/phase3/includes/api/ApiUpload.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadBase.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadFromChunks.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadBase.php
@@ -1019,4 +1019,10 @@
10201020 return $blacklist;
10211021 }
10221022
 1023+ public function getImageInfo($result) {
 1024+ $file = $this->getLocalFile();
 1025+ $imParam = ApiQueryImageInfo::getPropertyNames();
 1026+ return ApiQueryImageInfo::getInfo( $file, array_flip( $imParam ), $result );
 1027+ }
 1028+
10231029 }
Index: trunk/phase3/includes/upload/UploadFromChunks.php
@@ -88,8 +88,10 @@
8989 * @returns void
9090 */
9191 protected function initFromSessionKey( $sessionKey, $sessionData ) {
92 - if ( !$sessionKey || empty( $sessionKey ) ) {
93 - $this->status = Status::newFromFatal( 'Missing session data.' );
 92+ // testing against null because we don't want to cause obscure
 93+ // bugs when $sessionKey is full of "0"
 94+ if ( !$sessionKey === null ) {
 95+ $this->status = Status::newFromFatal( 'import-token-mismatch' );
9496 return;
9597 }
9698 $this->sessionKey = $sessionKey;
@@ -115,7 +117,7 @@
116118 * @see UploadBase::performUpload
117119 */
118120 public function performUpload( $comment, $pageText, $watch, $user ) {
119 - wfDebug( "\n\n\performUpload(chunked): sum:" . $comment . ' c: ' . $pageText . ' w:' . $watch );
 121+ wfDebug( "\n\n\performUpload(chunked): comment:" . $comment . ' pageText: ' . $pageText . ' watch:' . $watch );
120122 global $wgUser, $wgOut;
121123
122124 if ( $this->chunkMode == self::INIT ) {
@@ -147,13 +149,13 @@
148150 );
149151 $wgOut->disable();
150152 } else if ( $this->chunkMode == self::DONE ) {
151 - if ( $comment == '' )
 153+ if ( !$comment )
152154 $comment = $this->comment;
153155
154 - if ( $pageText == '' )
 156+ if ( !$pageText )
155157 $pageText = $this->pageText;
156158
157 - if ( $watch == '' )
 159+ if ( !$watch )
158160 $watch = $this->watch;
159161
160162 $status = parent::performUpload( $comment, $pageText, $watch, $user );
@@ -203,15 +205,34 @@
204206 $_SESSION['wsUploadData'][$this->sessionKey]['repoPath'] = $this->repoPath;
205207 }
206208 return $status;
 209+ }
 210+ if ( $this->getRealPath( $this->repoPath ) ) {
 211+ $this->status = $this->appendToUploadFile( $this->repoPath, $this->mTempPath );
207212 } else {
208 - if ( $this->getRealPath( $this->repoPath ) ) {
209 - $this->status = $this->appendToUploadFile( $this->repoPath, $this->mTempPath );
210 - } else {
211 - $this->status = Status::newFatal( 'filenotfound', $this->repoPath );
212 - }
 213+ $this->status = Status::newFatal( 'filenotfound', $this->repoPath );
 214+ }
 215+ if ( $this->fileSize > $wgMaxUploadSize )
 216+ $this->status = Status::newFatal( 'largefileserver' );
 217+ }
213218
214 - if ( $this->fileSize > $wgMaxUploadSize )
215 - $this->status = Status::newFatal( 'largefileserver' );
 219+ public function verifyUpload() {
 220+ if ( $this->chunkMode != self::DONE ) {
 221+ return Status::newGood();
216222 }
 223+ return parent::verifyUpload();
217224 }
 225+
 226+ public function checkWarnings() {
 227+ if ( $this->chunkMode != self::DONE ) {
 228+ return null;
 229+ }
 230+ return parent::checkWarnings();
 231+ }
 232+
 233+ public function getImageInfo( $result ) {
 234+ if ( $this->chunkMode != self::DONE ) {
 235+ return null;
 236+ }
 237+ return parent::getImageInfo( $result );
 238+ }
218239 }
Index: trunk/phase3/includes/api/ApiUpload.php
@@ -84,9 +84,9 @@
8585 if ( $this->mParams['enablechunks'] ) {
8686 $this->mUpload = new UploadFromChunks();
8787 $this->mUpload->initialize(
88 - $request->getText( 'done' ),
89 - $request->getText( 'filename' ),
90 - $request->getText( 'chunksessionkey' ),
 88+ $request->getVal( 'done', null ),
 89+ $request->getVal( 'filename', null ),
 90+ $request->getVal( 'chunksessionkey', null ),
9191 $request->getFileTempName( 'chunk' ),
9292 $request->getFileSize( 'chunk' ),
9393 $request->getSessionData( 'wsUploadData' )
@@ -126,13 +126,6 @@
127127 if ( !isset( $this->mUpload ) )
128128 $this->dieUsage( 'No upload module set', 'nomodule' );
129129
130 -
131 - // Finish up the exec command:
132 - $this->doExecUpload();
133 - }
134 -
135 - protected function doExecUpload() {
136 - global $wgUser;
137130 // Check whether the user has the appropriate permissions to upload anyway
138131 $permission = $this->mUpload->isAllowed( $wgUser );
139132
@@ -144,8 +137,8 @@
145138 }
146139 // Perform the upload
147140 $result = $this->performUpload();
 141+
148142 // Cleanup any temporary mess
149 - // FIXME: This should be in a try .. finally block with performUpload
150143 $this->mUpload->cleanupTempFile();
151144 $this->getResult()->addValue( null, $this->getModuleName(), $result );
152145 }
@@ -255,12 +248,8 @@
256249 $file = $this->mUpload->getLocalFile();
257250 $result['result'] = 'Success';
258251 $result['filename'] = $file->getName();
 252+ $result['imageinfo'] = $this->mUpload->getImageInfo( $this->getResult() );
259253
260 - // Append imageinfo to the result
261 - $imParam = ApiQueryImageInfo::getPropertyNames();
262 - $result['imageinfo'] = ApiQueryImageInfo::getInfo( $file,
263 - array_flip( $imParam ), $this->getResult() );
264 -
265254 return $result;
266255 }
267256

Follow-up revisions

RevisionCommit summaryAuthorDate
r61793Whitespace fixes for r61761, r61779catrope15:36, 1 February 2010
r61901follow up r61779 - anyone who writes "!$x == null" is an idiotmah02:19, 3 February 2010
r62806follow up r62231, r61779, r62175...mah02:15, 22 February 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r61355UploadChunks added from js2 branch. Refactored. Still needs to be...mah04:37, 22 January 2010

Comments

#Comment by Platonides (talk | contribs)   20:31, 1 February 2010

if ( !$sessionKey === null ) will always be false.

It is treated as (!$sessionKey) === null not as !($sessionKey === null) which is what you intended.

The right way would be to use if ( $sessionKey !== null ) which doesn't have to be disambiguated by operator priorities.

#Comment by Tim Starling (talk | contribs)   08:24, 15 February 2010
-			if ( $comment == '' )
+			if ( !$comment )

That's not an improvement. Now instead of suppressing empty comments, you're suppressing empty comments and comments that contain a string representation of the number zero. I was thinking more along the lines of $comment === null, assuming that's what was intended.

verifyUpload() and checkWarnings() still look right, they look like they will act on the current chunk instead of the whole uploaded file. Have you tested them?

#Comment by MarkAHershberger (talk | contribs)   03:15, 22 February 2010

fixed in r62806

#Comment by Tim Starling (talk | contribs)   08:25, 15 February 2010

s/still look/still don't look/

#Comment by Bryan (talk | contribs)   19:08, 12 March 2010

UploadBase::getImageInfo returns a result in API format, and thus belongs somewhere in the API code. Please do not mix frontend with backend.

Status & tagging log