r50468 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50467‎ | r50468 | r50469 >
Date:05:47, 11 May 2009
Author:dale
Status:deferred
Tags:
Comment:
debug cleanup
removed extension check on urls
Modified paths:
  • /branches/new-upload/phase3/includes/HttpFunctions.php (modified) (history)
  • /branches/new-upload/phase3/skins/common/upload.js (modified) (history)

Diff [purge]

Index: branches/new-upload/phase3/skins/common/upload.js
@@ -87,8 +87,7 @@
8888 var obj = this;
8989 var fileName = this.nameToCheck;
9090 sajax_do_call( 'UploadForm::ajaxGetExistsWarning', [this.nameToCheck],
91 - function (result) {
92 -
 91+ function (result) {
9392 obj.processResult(result, fileName)
9493 }
9594 );
@@ -148,7 +147,9 @@
149148 fname = path.substring(backslash+1, 10000);
150149 }
151150 //check for the wgFileExtensions and clear if not a valid fname extension
152 - if( wgFileExtensions ){
 151+
 152+ //urls are less likely to have a usefull extension don't include them in the extention check
 153+ if( wgFileExtensions && id != 'wpUploadFileURL' ){
153154 var found = false;
154155 if( fname.lastIndexOf('.')!=-1 ){
155156 var ext = fname.substr( fname.lastIndexOf('.')+1 );
Index: branches/new-upload/phase3/includes/HttpFunctions.php
@@ -31,10 +31,16 @@
3232 global $wgPhpCliPath, $wgMaxUploadSize;
3333 //do a quick check to HEAD to insure the file size is not > $wgMaxUploadSize to large no need to download it
3434 $head = get_headers($url, 1);
35 - if($head['Content-Length'] > $wgMaxUploadSize){
36 - return Status::newFatal('requested file length ' . $head['Content-Length'] . ' is greater than $wgMaxUploadSize: ' . $wgMaxUploadSize);
37 - }
 35+
 36+ //check for redirects:
 37+
3838 $content_length = (isset($head['Content-Length']))?$head['Content-Length']:null;
 39+ if($content_length){
 40+ if($content_length > $wgMaxUploadSize){
 41+ return Status::newFatal('requested file length ' . $content_length . ' is greater than $wgMaxUploadSize: ' . $wgMaxUploadSize);
 42+ }
 43+ }
 44+
3945 //check if we can find phpCliPath (for doing a background shell request to php to do the download:
4046 if( $wgPhpCliPath && wfShellExecEnabled() && $dl_mode == self::ASYNC_DOWNLOAD){
4147 wfDebug("\ASYNC_DOWNLOAD\n");
@@ -100,6 +106,7 @@
101107 */
102108 public static function doSessionIdDownload( $session_id, $upload_session_key ){
103109 global $wgUser, $wgEnableWriteAPI;
 110+ wfDebug("\n\ndoSessionIdDownload\n\n");
104111 //set session to the provided key:
105112 session_id($session_id);
106113 //start the session
@@ -124,23 +131,26 @@
125132 'upload_session_key' => $upload_session_key
126133 ) );
127134 //run the actual request .. (this can take some time)
128 - wfDebug("doRequest: " . $sd['url'] . ' tf: ' . $sd['target_file_path'] );
129 - $status = $req->doRequest();
 135+ wfDebug("do Request: " . $sd['url'] . ' tf: ' . $sd['target_file_path'] );
 136+ $status = $req->doRequest();
 137+ wfDebug("done with req status is: ". $status->isOK(). ' '.$status->value. "\n");
130138
131 -
132 - //start up the session again:
133 - if( session_start() === false){
134 - wfDebug( __METHOD__ . ' ERROR:: Could not start session');
135 - }
136 - //re-grab the updated session data:
137 - $sd =& $_SESSION[ 'wsDownload' ][$upload_session_key];
138 - if( $status->isOK() ){
 139+ if( $status->isOK() ){
 140+
 141+ //start up the session again:
 142+ if( session_start() === false){
 143+ wfDebug( __METHOD__ . ' ERROR:: Could not start session');
 144+ }
 145+ //re-grab the updated session data:
 146+ $sd =& $_SESSION[ 'wsDownload' ][$upload_session_key];
 147+
139148 //setup the faxRequest
140149 $fauxReqData = $sd['mParams'];
141150 $fauxReqData['action'] = 'upload';
142151 $fauxReqData['format'] = 'json';
143152 $fauxReqData['internalhttpsession'] = $upload_session_key;
144 -
 153+ //evil but no other clean way about it:
 154+
145155 $faxReq = new FauxRequest($fauxReqData, true);
146156 $processor = new ApiMain($faxReq, $wgEnableWriteAPI);
147157
@@ -151,15 +161,15 @@
152162 $printer->initPrinter(false);
153163 ob_start();
154164 $printer->execute();
155 - $apiUploadResult = ob_get_clean();
156 -
 165+ $apiUploadResult = ob_get_clean();
 166+
 167+ wfDebug("\n\n got:" . $apiUploadResult." \n");
 168+
 169+ wfDebug("\n\n got api result:: $apiUploadResult \n" );
157170 //the status updates runner will grab the result form the session:
158 - $sd['apiUploadResult'] = $apiUploadResult;
159 - }else{
160 - //status != OK
161 - $sd['apiUploadResult'] = ApiFormatJson::getJsonEncode( array( 'error' => $status->getWikiText() ) );
 171+ $sd['apiUploadResult'] = $apiUploadResult;
 172+ session_write_close();
162173 }
163 - session_write_close();
164174 }
165175
166176 /**
@@ -230,7 +240,7 @@
231241 }
232242 }
233243 private function doCurlReq(){
234 - global $wgHTTPFileTimeout, $wgHTTPTimeout, $wgHTTPProxy, $wgTitle;
 244+ global $wgHTTPFileTimeout, $wgHTTPProxy, $wgTitle;
235245
236246 $status = Status::newGood();
237247 $c = curl_init( $this->url );
@@ -240,8 +250,11 @@
241251 curl_setopt( $c, CURLOPT_PROXY, 'localhost:80' );
242252 } else if ($wgHTTPProxy) {
243253 curl_setopt($c, CURLOPT_PROXY, $wgHTTPProxy);
244 - }
 254+ }
245255
 256+ curl_setopt( $c, CURLOPT_TIMEOUT, $wgHTTPFileTimeout );
 257+
 258+
246259 curl_setopt( $c, CURLOPT_USERAGENT, Http::userAgent() );
247260
248261 if ( $this->method == 'POST' ) {
@@ -268,11 +281,6 @@
269282 $status = $cwrite->status;
270283 }
271284 curl_setopt( $c, CURLOPT_WRITEFUNCTION, array($cwrite, 'callbackWriteBody') );
272 - //set to the file time out:
273 - curl_setopt( $c, CURLOPT_TIMEOUT, $wgHTTPFileTimeout );
274 - }else{
275 - //set to script time timeout
276 - curl_setopt( $c, CURLOPT_TIMEOUT, $wgHTTPTimeout );
277285 }
278286
279287 //start output grabber:
@@ -307,7 +315,6 @@
308316 if ( $retcode != 200 ) {
309317 wfDebug( __METHOD__ . ": HTTP return code $retcode\n" );
310318 $status = Status::newFatal( "HTTP return code $retcode\n" );
311 -
312319 }
313320 # Don't return truncated output
314321 $errno = curl_errno( $c );

Status & tagging log