r49850 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49849‎ | r49850 | r49851 >
Date:00:58, 25 April 2009
Author:dale
Status:deferred
Tags:
Comment:
another (debug) commit of the upload branch
integrated fixes to the http class
Modified paths:
  • /branches/new-upload/phase3/includes/GlobalFunctions.php (modified) (history)
  • /branches/new-upload/phase3/includes/HttpFunctions.php (modified) (history)
  • /branches/new-upload/phase3/includes/Import.php (modified) (history)
  • /branches/new-upload/phase3/includes/PEAR/HTTP/Request2/Adapter/Curl.php (modified) (history)
  • /branches/new-upload/phase3/includes/UploadFromUrl.php (modified) (history)
  • /branches/new-upload/phase3/includes/api/ApiUpload.php (modified) (history)
  • /branches/new-upload/phase3/includes/filerepo/File.php (modified) (history)
  • /branches/new-upload/phase3/includes/filerepo/ForeignAPIRepo.php (modified) (history)
  • /branches/new-upload/phase3/includes/parser/Parser.php (modified) (history)
  • /branches/new-upload/phase3/includes/specials/SpecialUpload.php (modified) (history)
  • /branches/new-upload/phase3/maintenance/findhooks.php (modified) (history)

Diff [purge]

Index: branches/new-upload/phase3/maintenance/findhooks.php
@@ -49,8 +49,9 @@
5050 global $doc, $options;
5151 $m = array();
5252 if( isset( $options['online'] ) ){
53 - $content = Http::get( 'http://www.mediawiki.org/w/index.php?title=Manual:Hooks&action=raw' );
54 - preg_match_all( '/\[\[\/([a-zA-Z0-9-_:]+)\|/', $content, $m );
 53+ $status = Http::get( 'http://www.mediawiki.org/w/index.php?title=Manual:Hooks&action=raw' );
 54+ if( $status->isOK() )
 55+ preg_match_all( '/\[\[\/([a-zA-Z0-9-_:]+)\|/', $status->value, $m );
5556 } else {
5657 $content = file_get_contents( $doc );
5758 preg_match_all( "/\n'(.*?)'/", $content, $m );
Index: branches/new-upload/phase3/includes/GlobalFunctions.php
@@ -2147,23 +2147,8 @@
21482148 */
21492149 function wfShellExec( $cmd, &$retval=null ) {
21502150 global $IP, $wgMaxShellMemory, $wgMaxShellFileSize, $wgMaxShellTime;
2151 -
2152 - static $disabled;
2153 - if ( is_null( $disabled ) ) {
2154 - $disabled = false;
2155 - if( wfIniGetBool( 'safe_mode' ) ) {
2156 - wfDebug( "wfShellExec can't run in safe_mode, PHP's exec functions are too broken.\n" );
2157 - $disabled = true;
2158 - }
2159 - $functions = explode( ',', ini_get( 'disable_functions' ) );
2160 - $functions = array_map( 'trim', $functions );
2161 - $functions = array_map( 'strtolower', $functions );
2162 - if ( in_array( 'passthru', $functions ) ) {
2163 - wfDebug( "passthru is in disabled_functions\n" );
2164 - $disabled = true;
2165 - }
2166 - }
2167 - if ( $disabled ) {
 2151+
 2152+ if ( ! wfShellExecEnabled() ) {
21682153 $retval = 1;
21692154 return "Unable to run external programs in safe mode.";
21702155 }
@@ -2199,8 +2184,25 @@
22002185 }
22012186 return $output;
22022187 }
2203 -
22042188 /**
 2189+ * Checks if the current instance can execute a shell command
 2190+ *
 2191+ */
 2192+function wfShellExecEnabled(){
 2193+ if( wfIniGetBool( 'safe_mode' ) ) {
 2194+ wfDebug( "wfShellExec can't run in safe_mode, PHP's exec functions are too broken.\n" );
 2195+ return false;
 2196+ }
 2197+ $functions = explode( ',', ini_get( 'disable_functions' ) );
 2198+ $functions = array_map( 'trim', $functions );
 2199+ $functions = array_map( 'strtolower', $functions );
 2200+ if ( in_array( 'passthru', $functions ) ) {
 2201+ wfDebug( "passthru is in disabled_functions\n" );
 2202+ return false;
 2203+ }
 2204+ return true;
 2205+}
 2206+/**
22052207 * Workaround for http://bugs.php.net/bug.php?id=45132
22062208 * escapeshellarg() destroys non-ASCII characters if LANG is not a UTF-8 locale
22072209 */
@@ -2597,9 +2599,12 @@
25982600 * Alias for modularized function
25992601 * @deprecated Use Http::get() instead
26002602 */
2601 -function wfGetHTTP( $url, $timeout = 'default' ) {
 2603+function wfGetHTTP( $url ) {
26022604 wfDeprecated(__FUNCTION__);
2603 - return Http::get( $url, $timeout );
 2605+ $status = Http::get( $url );
 2606+ if( $status->isOK() )
 2607+ return $status->value;
 2608+ return null;
26042609 }
26052610
26062611 /**
Index: branches/new-upload/phase3/includes/parser/Parser.php
@@ -3117,16 +3117,16 @@
31183118 }
31193119 }
31203120
3121 - $text = Http::get($url);
3122 - if (!$text)
 3121+ $status = Http::get($url);
 3122+ if ( !$status->isOK() )
31233123 return wfMsg('scarytranscludefailed', $url);
3124 -
 3124+
31253125 $dbw = wfGetDB(DB_MASTER);
31263126 $dbw->replace('transcache', array('tc_url'), array(
31273127 'tc_url' => $url,
31283128 'tc_time' => time(),
3129 - 'tc_contents' => $text));
3130 - return $text;
 3129+ 'tc_contents' => $status->value));
 3130+ return $status->value;
31313131 }
31323132
31333133
Index: branches/new-upload/phase3/includes/filerepo/ForeignAPIRepo.php
@@ -89,11 +89,13 @@
9090 $key = wfMemcKey( 'ForeignAPIRepo', 'Metadata', md5( $url ) );
9191 $data = $wgMemc->get( $key );
9292 if( !$data ) {
93 - $data = Http::get( $url );
94 - if ( !$data ) {
 93+ $status = Http::get( $url );
 94+ if ( $status->isOK() ) {
 95+ $wgMemc->set( $key, $data, 3600 );
 96+ }else{
 97+ //FIXME maybe return status?
9598 return null;
96 - }
97 - $wgMemc->set( $key, $data, 3600 );
 99+ }
98100 }
99101
100102 if( count( $this->mQueryCache ) > 100 ) {
@@ -167,9 +169,12 @@
168170 return $foreignUrl;
169171 }
170172 $localUrl = $wgServer . $wgUploadPath . '/' . $path . $fileName;
171 - $thumb = Http::get( $foreignUrl );
172 - # FIXME: Delete old thumbs that aren't being used. Maintenance script?
173 - file_put_contents($wgUploadDirectory . '/' . $path . $fileName, $thumb );
 173+ //FIXME could use the download to file::
 174+ $status = Http::doDownload( $foreignUrl,
 175+ $wgUploadDirectory . '/' . $path . $fileName,
 176+ Http::SYNC_DOWNLOAD //need to download right away
 177+ );
 178+ # FIXME: Delete old thumbs that aren't being used. Maintenance script?
174179 $wgMemc->set( $key, $localUrl, $this->apiThumbCacheExpiry );
175180 wfDebug( __METHOD__ . " got local thumb $localUrl, saving to cache \n" );
176181 return $localUrl;
Index: branches/new-upload/phase3/includes/filerepo/File.php
@@ -1087,11 +1087,15 @@
10881088 wfDebug("miss\n");
10891089 }
10901090 wfDebug( "Fetching shared description from $renderUrl\n" );
1091 - $res = Http::get( $renderUrl );
1092 - if ( $res && $this->repo->descriptionCacheExpiry > 0 ) {
1093 - $wgMemc->set( $key, $res, $this->repo->descriptionCacheExpiry );
 1091+ $status = Http::get( $renderUrl );
 1092+ if( $status->isOK() ){
 1093+ if ( $status->value && $this->repo->descriptionCacheExpiry > 0 ) {
 1094+ $wgMemc->set( $key, $status->value, $this->repo->descriptionCacheExpiry );
 1095+ }
 1096+ return $res;
 1097+ }else{
 1098+ //http get error
10941099 }
1095 - return $res;
10961100 } else {
10971101 return false;
10981102 }
Index: branches/new-upload/phase3/includes/UploadFromUrl.php
@@ -2,6 +2,9 @@
33 class UploadFromUrl extends UploadBase {
44 protected $mTempDownloadPath;
55
 6+ //by default do a SYNC_DOWNLOAD
 7+ protected $dl_mode = null;
 8+
69 static function isAllowed( $user ) {
710 if( !$user->isAllowed( 'upload_by_url' ) )
811 return 'upload_by_url';
@@ -11,16 +14,24 @@
1215 global $wgAllowCopyUploads;
1316 return $wgAllowCopyUploads && parent::isEnabled();
1417 }
15 -
16 - function initialize( $name, $url ) {
 18+ /*entry point for Api upload:: ASYNC_DOWNLOAD (if possible) */
 19+ function initialize( $name, $url ) {
1720 global $wgTmpDirectory;
 21+
 22+ if(!$this->dl_mode)
 23+ $this->dl_mode = Http::ASYNC_DOWNLOAD;
 24+
1825 $local_file = tempnam( $wgTmpDirectory, 'WEBUPLOAD' );
1926 parent::initialize( $name, $local_file, 0, true );
2027
2128 $this->mUrl = trim( $url );
2229 }
23 -
24 - function initializeFromRequest( &$request ) {
 30+ /*entry point for SpecialUpload no ASYNC_DOWNLOAD possible: */
 31+ function initializeFromRequest( &$request ) {
 32+ //set dl mode if not set:
 33+ if(!$this->dl_mode)
 34+ $this->dl_mode = Http::SYNC_DOWNLOAD;
 35+
2536 $desiredDestName = $request->getText( 'wpDestFile' );
2637 if( !$desiredDestName )
2738 $desiredDestName = $request->getText( 'wpUploadFile' );
@@ -29,30 +40,17 @@
3041 $request->getVal('wpUploadFileURL')
3142 );
3243 }
33 -
3444 /**
3545 * Do the real fetching stuff
3646 */
37 - function fetchFile() {
 47+ function fetchFile( ) {
 48+ //entry point for SpecialUplaod
3849 if( stripos($this->mUrl, 'http://') !== 0 && stripos($this->mUrl, 'ftp://') !== 0 ) {
39 - return array(
40 - 'status' => self::BEFORE_PROCESSING,
41 - 'error' => 'upload-proto-error',
42 - );
 50+ return Status::newFatal('upload-proto-error');
4351 }
44 - //touch the temporary file:
45 - file_put_contents( $this->mTempPath, '' );
46 -
47 - //move the empty target to the shared repo:
48 - $status = $this->saveTempUploadedFile( $this->mDestName, $this->mTempPath );
49 - if( $status->isOK() ) {
50 - $this->mTempDownloadPath = $status->value;
51 - }else{
52 - return $status;
53 - }
54 - //now do the actual download to the shared target:
55 - $status = Http::doDownload ( $this->mUrl, $this->mTempDownloadPath);
56 -
 52+ //print "fetchFile:: $this->dl_mode";
 53+ //now do the actual download to the shared target:
 54+ $status = Http::doDownload ( $this->mUrl, $this->mTempPath, $this->dl_mode);
5755 return $status;
5856
5957 /*
@@ -116,6 +114,7 @@
117115 return $length;
118116 }
119117 */
 118+ //this can be deprecated in favor of http_request2 functions
120119 static function isValidRequest( $request ){
121120 if( !$request->getVal('wpUploadFileURL') )
122121 return false;
Index: branches/new-upload/phase3/includes/api/ApiUpload.php
@@ -39,7 +39,6 @@
4040
4141 public function execute() {
4242 global $wgUser;
43 -
4443
4544 $this->getMain()->requestWriteMode();
4645 $this->mParams = $this->extractRequestParams();
@@ -84,7 +83,7 @@
8584 );
8685 } elseif( isset( $this->mParams['url'] ) ) {
8786 $this->mUpload = new UploadFromUrl();
88 - $this->mUpload->initialize( $this->mParams['filename'], $this->mParams['url'] );
 87+ $this->mUpload->initialize( $this->mParams['filename'], $this->mParams['url']);
8988 }
9089 }
9190
@@ -233,6 +232,7 @@
234233 return array (
235234 'filename' => 'Target filename',
236235 'file' => 'File contents',
 236+ 'chunk'=> 'Chunk File Contents',
237237 'url' => 'Url to upload from',
238238 'comment' => 'Upload comment or initial page text',
239239 'watch' => 'Watch the page',
Index: branches/new-upload/phase3/includes/PEAR/HTTP/Request2/Adapter/Curl.php
@@ -44,7 +44,8 @@
4545 /**
4646 * Base class for HTTP_Request2 adapters
4747 */
48 -require_once 'HTTP/Request2/Adapter.php';
 48+require_once 'HTTP/Request2/Adapter.php';
 49+require_once 'HTTP/Request2/Response.php';
4950
5051 /**
5152 * Adapter for HTTP_Request2 wrapping around cURL extension
@@ -167,14 +168,16 @@
168169 * @return resource a cURL handle, as created by curl_init()
169170 * @throws HTTP_Request2_Exception
170171 */
171 - protected function createCurlHandle()
 172+ public function createCurlHandle()
172173 {
173174 $ch = curl_init();
174175
175176 curl_setopt_array($ch, array(
176177 // setup callbacks
177178 CURLOPT_READFUNCTION => array($this, 'callbackReadBody'),
178 - // CURLOPT_HEADERFUNCTION => array($this, 'callbackWriteHeader'),
 179+
 180+ CURLOPT_HEADERFUNCTION => array($this, 'callbackWriteHeader'),
 181+
179182 CURLOPT_WRITEFUNCTION => array($this, 'callbackWriteBody'),
180183 // disallow redirects
181184 CURLOPT_FOLLOWLOCATION => false,
@@ -325,7 +328,8 @@
326329 * @see HTTP_Request2_Response::parseHeaderLine()
327330 */
328331 protected function callbackWriteHeader($ch, $string)
329 - {
 332+ {
 333+ print "called callbackWriteHeader";
330334 // we may receive a second set of headers if doing e.g. digest auth
331335 if ($this->eventReceivedHeaders || !$this->eventSentHeaders) {
332336 // don't bother with 100-Continue responses (bug #15785)
@@ -342,9 +346,12 @@
343347 $this->eventReceivedHeaders = false;
344348 $this->response = null;
345349 }
346 - }
347 - if (empty($this->response)) {
348 - $this->response = new HTTP_Request2_Response($string, false, $this->request->getConfig('target-file-path'));
 350+ }
 351+
 352+ if (empty($this->response)) {
 353+ print "going to try to get response:";
 354+ $this->response = new HTTP_Request2_Response($string, false, $this->request->getConfig('target-file-path'));
 355+ print "ok";
349356 } else {
350357 $this->response->parseHeaderLine($string);
351358 if ('' == trim($string)) {
@@ -354,8 +361,9 @@
355362 }
356363 $this->eventReceivedHeaders = true;
357364 }
358 - }
359 - return strlen($string);
 365+ }
 366+
 367+ return strlen($string);
360368 }
361369
362370 /**
@@ -370,12 +378,15 @@
371379 {
372380 // cURL calls WRITEFUNCTION callback without calling HEADERFUNCTION if
373381 // response doesn't start with proper HTTP status line (see bug #15716)
374 - if (empty($this->response)) {
375 - throw new HTTP_Request2_Exception("Malformed response: {$string}");
376 - }
 382+ //if (empty($this->response)) {
 383+ // throw new HTTP_Request2_Exception("Malformed response: {$string}");
 384+ //}
377385 $this->response->appendBody($string);
378386 $this->request->setLastEvent('receivedBodyPart', $string);
379387 return strlen($string);
380388 }
 389+}
 390+function callbackWriteBody($ch, $string){
 391+ print 'test write test';
381392 }
382393 ?>
Index: branches/new-upload/phase3/includes/HttpFunctions.php
@@ -1,56 +1,42 @@
22 <?php
3 -
43 /**
5 -* simple wrapper / helper PEAR HTTP_Request2
6 -* http://pear.php.net/package/HTTP_Request2/
 4+ * HTTP handling class
 5+ *
76 */
8 -//get our Request2 class:
9 -require_once 'HTTP/Request2.php';
107
 8+
119 class Http {
 10+ const SYNC_DOWNLOAD = 1; //syncronys upload (in a single request)
 11+ const ASYNC_DOWNLOAD = 2; //asynchronous upload we should spawn out another process and monitor progress if possible)
1212 /**
1313 * Simple wrapper for Http::request( 'GET' )
1414 */
1515 public static function get( $url, $opts = array() ) {
1616 return self::request($url, 'GET', $opts );
1717 }
18 - public static function request( $url, $method = 'GET' , $opts = array()){
19 - //FIXME do something with the $opts ;
20 - $req = new HTTP_Request2( $url, $method, array(
21 - 'adapter' => self::getAdapter(),
22 - 'user-agent' => self::userAgent()
23 - ));
24 - return self::doRequest( $req );
25 - }
26 - /**
27 - * does the actual request
28 - * returns false on errors
29 - */
30 - public static function doRequest( &$req ){
31 - try{
32 - return $req->send();
33 - } catch ( HTTP_Request2_Exception $e ) {
34 - //http error:
35 - wfDebug( __METHOD__ . $e->getMessage() . "\ncode:" . $e->getCode() );
36 - return false;
37 - }
38 - }
39 -
40 - public static function doDownload( $url, $target_path ){
 18+
 19+ public static function doDownload( $url, $target_path , $dl_mode = self::SYNC_DOWNLOAD ){
4120 global $wgPhpCliPath, $wgMaxUploadSize;
4221
43 - //do a quick check to HEAD to insure the file size is not > $wgMaxUploadSize if it is no need to try and download it
 22+ //do a quick check to HEAD to insure the file size is not > $wgMaxUploadSize to large no need to download it
4423 $head = get_headers($url, 1);
4524 if(isset($head['Content-Length']) && $head['Content-Length'] > $wgMaxUploadSize){
4625 return Status::newFatal('requested file length ' .$head['Content-Length'] . ' is greater than $wgMaxUploadSize: ' . $wgMaxUploadSize);
4726 }
4827
4928 //check if we can find phpCliPath (for doing a background shell request to php to do the download:
50 - if( $wgPhpCliPath ){
 29+ if( $wgPhpCliPath && wfShellExecEnabled() && $dl_mode == self::ASYNC_DOWNLOAD){
 30+ //setup session
 31+ die('do shell exec');
 32+ //do shell exec req
5133
52 - }else{
 34+ //return success status and download_session_key
 35+
 36+ //(seperate ajax request can now check on the status of the shell exec)... and even kill or cancel it)
 37+
 38+ }else if( $dl_mode== self::SYNC_DOWNLOAD ){
5339 //else just download as much as we can in the time we have left:
54 - self::doDownloadtoFile();
 40+ return self::doDownloadtoFile($url, $target_path);
5541 }
5642
5743 }
@@ -62,9 +48,11 @@
6349 public static function initBackgroundDownload( $url ){
6450 global $wgMaxUploadSize;
6551 $status = Status::newGood();
66 - //generate a session id with all the details for the download
 52+ //generate a session id with all the details for the download (pid, target_file )
 53+
 54+ //later add in (destName & description)
6755 $session_id = session_id();
68 - print "should spin out a proccess with id: $session_id\n";
 56+ print "should spin out a process with id: $session_id\n";
6957 //maintenance/http_download.php passing it a upload session_id
7058
7159 //return status
@@ -81,23 +69,18 @@
8270 public static function doDownloadtoFile($url, $target_file_path){
8371 global $wgCopyUploadTimeout;
8472
85 - if(is_file($target_file_path)){
86 - $req = new HTTP_Request2( $url, 'GET', array(
87 - 'adapter' => self::getAdapter(),
88 - 'user-agent' => self::userAgent(),
89 - 'connect_timeout' => $wgCopyUploadTimeout,
90 - 'target_file_path' => $target_file_path
91 - ));
92 - }
93 - self::doRequest( $req );
94 - print "GOT FILE of size: " . filesize( $target_file_path ) . "\n";
95 - return true;
 73+ $status = self::request( $url, array(
 74+ 'target_file'=> $target_file_path
 75+ ) );
 76+ //print "downloading to FILE target: $target_file_path " . filesize( $target_file_path ) . "\n";
 77+ return Status::newGood('upload-ok');
9678 }
9779 /**
9880 * Simple wrapper for Http::request( 'POST' )
9981 */
100 - public static function post( $url, $timeout = 'default', $opts = array() ) {
101 - return Http::request( "POST", $url, $timeout, $opts );
 82+ public static function post( $url, $opts = array() ) {
 83+ $opts['method']='POST';
 84+ return Http::request( $url, $opts );
10285 }
10386 /*
10487 * sets the remote adapter (we prefer curl) could add a config var if we want.
@@ -111,38 +94,41 @@
11295 }
11396 /**
11497 * Get the contents of a file by HTTP
115 - * @param $method string HTTP method. Usually GET/POST
116 - * @param $url string Full URL to act on
117 - * @param $timeout int Seconds to timeout. 'default' falls to $wgHTTPTimeout
118 - * @param $curlOptions array Optional array of extra params to pass
119 - * to curl_setopt()
 98+ * @param $url string Full URL to act on
 99+ * @param $Opt associative array Optional array of options:
 100+ * 'method' => 'GET', 'POST' etc.
 101+ * 'target_file' => if curl should output to a target file
 102+ * 'adapter' => 'curl', 'soket'
120103 */
121 - /*public static function request( $method, $url, $timeout = 'default', $curlOptions = array() ) {
 104+ public static function request( $url, $opt = array() ) {
122105 global $wgHTTPTimeout, $wgHTTPProxy, $wgTitle;
 106+ //set defaults:
 107+ $method = (isset($opt['method']))?$opt['method']:'GET';
 108+ $target_file = (isset($opt['target_file']))?$opt['target_file']:false;
 109+
 110+ $status = Status::newGood();
123111
124 - // Go ahead and set the timeout if not otherwise specified
125 - if ( $timeout == 'default' ) {
126 - $timeout = $wgHTTPTimeout;
127 - }
128 -
129112 wfDebug( __METHOD__ . ": $method $url\n" );
130113 # Use curl if available
131114 if ( function_exists( 'curl_init' ) ) {
132115 $c = curl_init( $url );
 116+
 117+ //proxy setup:
133118 if ( self::isLocalURL( $url ) ) {
134119 curl_setopt( $c, CURLOPT_PROXY, 'localhost:80' );
135120 } else if ($wgHTTPProxy) {
136121 curl_setopt($c, CURLOPT_PROXY, $wgHTTPProxy);
137122 }
138123
139 - curl_setopt( $c, CURLOPT_TIMEOUT, $timeout );
 124+ curl_setopt( $c, CURLOPT_TIMEOUT, $wgHTTPTimeout );
140125 curl_setopt( $c, CURLOPT_USERAGENT, self :: userAgent() );
 126+
141127 if ( $method == 'POST' ) {
142128 curl_setopt( $c, CURLOPT_POST, true );
143129 curl_setopt( $c, CURLOPT_POSTFIELDS, '' );
144 - }
145 - else
 130+ }else{
146131 curl_setopt( $c, CURLOPT_CUSTOMREQUEST, $method );
 132+ }
147133
148134 # Set the referer to $wgTitle, even in command-line mode
149135 # This is useful for interwiki transclusion, where the foreign
@@ -152,12 +138,7 @@
153139 if ( is_object( $wgTitle ) ) {
154140 curl_setopt( $c, CURLOPT_REFERER, $wgTitle->getFullURL() );
155141 }
156 -
157 - if ( is_array( $curlOptions ) ) {
158 - foreach( $curlOptions as $option => $value ) {
159 - curl_setopt( $c, $option, $value );
160 - }
161 - }
 142+
162143
163144 ob_start();
164145 curl_exec( $c );
@@ -179,7 +160,7 @@
180161 }
181162 curl_close( $c );
182163 } else {
183 - # Otherwise use file_get_contents...
 164+ # Otherwise use file_get_contents...
184165 # This doesn't have local fetch capabilities...
185166
186167 $headers = array( "User-Agent: " . self :: userAgent() );
@@ -194,10 +175,17 @@
195176 'timeout' => $timeout ) );
196177 $ctx = stream_context_create($opts);
197178
198 - $text = file_get_contents( $url, false, $ctx );
 179+ $status->value = file_get_contents( $url, false, $ctx );
 180+ if(!$status->value){
 181+ $status->error('file_get_contents-failed');
 182+ }
199183 }
200 - return $text;
201 - }*/
 184+ if(!$target_file){
 185+ return $status;
 186+ }else{
 187+ return true;
 188+ }
 189+ }
202190
203191 /**
204192 * Check if the URL can be served by localhost
Index: branches/new-upload/phase3/includes/specials/SpecialUpload.php
@@ -140,6 +140,8 @@
141141 * Do the upload
142142 * Checks are made in SpecialUpload::execute()
143143 *
 144+ * FIXME this should really use the standard Status class (instead of associative array)
 145+ *
144146 * @access private
145147 */
146148 function processUpload(){
@@ -152,10 +154,8 @@
153155 break;
154156
155157 case UploadBase::BEFORE_PROCESSING:
156 - // Do... nothing? Why?
157 - // In fact we should do something because this is where curl errors and similar live
 158+ $this->uploadError( $details['error'] );
158159 break;
159 -
160160 case UploadBase::LARGE_FILE_SERVER:
161161 $this->mainUploadForm( wfMsgHtml( 'largefileserver' ) );
162162 break;
@@ -252,12 +252,13 @@
253253 if( $permErrors !== true ) {
254254 return array( 'status' => UploadBase::PROTECTED_PAGE, 'permissionserrors' => $permErrors );
255255 }
256 -
 256+
257257 // Fetch the file if required
258 - $result = $this->mUpload->fetchFile();
259 - if( $result != UploadBase::OK )
260 - return $result;
261 -
 258+ $status = $this->mUpload->fetchFile();
 259+ if( !$status->isOK() ){
 260+ return array( 'status' =>UploadBase::BEFORE_PROCESSING, 'error'=>$status->getWikiText() );
 261+ }
 262+
262263 // Check whether this is a sane upload
263264 $result = $this->mUpload->verifyUpload();
264265 if( $result != UploadBase::OK )
Index: branches/new-upload/phase3/includes/Import.php
@@ -354,15 +354,16 @@
355355
356356 // @fixme!
357357 $src = $this->getSrc();
358 - $data = Http::get( $src );
359 - if( !$data ) {
360 - wfDebug( "IMPORT: couldn't fetch source $src\n" );
361 - fclose( $f );
362 - unlink( $tempo );
363 - return false;
 358+ $status = Http::get( $src );
 359+ if( !$status->isOK() ){
 360+ if( !$data ) {
 361+ wfDebug( "IMPORT: couldn't fetch source $src\n" );
 362+ fclose( $f );
 363+ unlink( $tempo );
 364+ return false;
 365+ }
364366 }
365 -
366 - fwrite( $f, $data );
 367+ fwrite( $f, $status->value );
367368 fclose( $f );
368369
369370 return $tempo;

Status & tagging log