r65043 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65042‎ | r65043 | r65044 >
Date:08:44, 15 April 2010
Author:btongminh
Status:ok (Comments)
Tags:
Comment:
Refactored UploadFromUrl to use HttpFunctions.
Errors while fetching the file are now properly handled and also displayed in a reasonable way to the user (bug 22015).
Modified paths:
  • /trunk/phase3/includes/specials/SpecialUpload.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadFromUrl.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadFromUrl.php
@@ -78,44 +78,25 @@
7979 if( !self::isValidUrl( $this->mUrl ) ) {
8080 return Status::newFatal( 'upload-proto-error' );
8181 }
82 - $res = $this->curlCopy();
83 - if( $res !== true ) {
84 - return Status::newFatal( $res );
85 - }
86 - return Status::newGood();
87 - }
8882
89 - /**
90 - * Safe copy from URL
91 - * Returns true if there was an error, false otherwise
92 - */
93 - private function curlCopy() {
94 - global $wgOut;
95 -
9683 # Open temporary file
9784 $this->mCurlDestHandle = @fopen( $this->mTempPath, "wb" );
9885 if( $this->mCurlDestHandle === false ) {
9986 # Could not open temporary file to write in
100 - return 'upload-file-error';
 87+ return Status::newFatal( 'upload-file-error' );
10188 }
102 -
103 - $ch = curl_init();
104 - curl_setopt( $ch, CURLOPT_HTTP_VERSION, 1.0); # Probably not needed, but apparently can work around some bug
105 - curl_setopt( $ch, CURLOPT_TIMEOUT, 10); # 10 seconds timeout
106 - curl_setopt( $ch, CURLOPT_LOW_SPEED_LIMIT, 512); # 0.5KB per second minimum transfer speed
107 - curl_setopt( $ch, CURLOPT_URL, $this->mUrl);
108 - curl_setopt( $ch, CURLOPT_WRITEFUNCTION, array( $this, 'uploadCurlCallback' ) );
109 - curl_exec( $ch );
110 - $error = curl_errno( $ch );
111 - curl_close( $ch );
112 -
 89+
 90+ $options = array(
 91+ 'method' => 'GET',
 92+ 'timeout' => 10,
 93+ );
 94+ $req = HttpRequest::factory( $this->mUrl, $options );
 95+ $req->setCallback( array( $this, 'uploadCurlCallback' ) );
 96+ $status = $req->execute();
11397 fclose( $this->mCurlDestHandle );
11498 unset( $this->mCurlDestHandle );
11599
116 - if( $error )
117 - return "upload-curl-error$errornum";
118 -
119 - return true;
 100+ return $status;
120101 }
121102
122103 /**
Index: trunk/phase3/includes/specials/SpecialUpload.php
@@ -390,7 +390,7 @@
391391 // Fetch the file if required
392392 $status = $this->mUpload->fetchFile();
393393 if( !$status->isOK() ) {
394 - $this->showUploadForm( $this->getUploadForm( $wgOut->parse( $status->getWikiText() ) ) );
 394+ $this->showUploadError( $wgOut->parse( $status->getWikiText() ) );
395395 return;
396396 }
397397

Follow-up revisions

RevisionCommit summaryAuthorDate
r65044RELEASE-NOTES for r65043.btongminh08:46, 15 April 2010

Comments

#Comment by Nikerabbit (talk | contribs)   09:02, 15 April 2010
$this->showUploadError( $wgOut->parse( $status->getWikiText() ) );

Can we pass messages (with args) around instead of the text of the messages? It is the easiest way to ensure that magic words etc work correctly.

#Comment by Bryan (talk | contribs)   09:36, 15 April 2010

We could. The Status object stores the message key and args, so we could just pass the Status object to showUploadError

Status & tagging log