Index: trunk/phase3/skins/common/wikibits.js |
— | — | @@ -34,10 +34,10 @@ |
35 | 35 | |
36 | 36 | if (!window.onloadFuncts) { |
37 | 37 | var onloadFuncts = []; |
38 | | -} |
39 | | - |
40 | | -//code that is dependent on js2 functions should use js2AddOnloadHook |
41 | | -function addOnloadHook(hookFunct) { |
| 38 | +} |
| 39 | + |
| 40 | +// code that is dependent on js2 functions should use js2AddOnloadHook |
| 41 | +function addOnloadHook(hookFunct) { |
42 | 42 | // Allows add-on scripts to add onload functions |
43 | 43 | if(!doneOnloadHook) { |
44 | 44 | onloadFuncts[onloadFuncts.length] = hookFunct; |
Index: trunk/phase3/includes/upload/UploadFromChunks.php |
— | — | @@ -10,7 +10,7 @@ |
11 | 11 | */ |
12 | 12 | class UploadFromChunks extends UploadBase { |
13 | 13 | |
14 | | - var $chunk_mode; //init, chunk, done |
| 14 | + var $chunk_mode; // init, chunk, done |
15 | 15 | var $mSessionKey = false; |
16 | 16 | var $status = array(); |
17 | 17 | |
— | — | @@ -112,7 +112,7 @@ |
113 | 113 | $this->mSessionKey = $this->getSessionKey(); |
114 | 114 | $_SESSION['wsUploadData'][$this->mSessionKey] = array( |
115 | 115 | 'mComment' => $comment, |
116 | | - 'mSummary' => $summary, |
| 116 | + 'mSummary' => $summary, |
117 | 117 | 'mWatch' => $watch, |
118 | 118 | 'mIgnorewarnings' => true, //ignore warning on chunk uploads (for now) |
119 | 119 | 'mFilteredName' => $this->mFilteredName, |
— | — | @@ -164,7 +164,7 @@ |
165 | 165 | echo ApiFormatJson::getJsonEncode( array( |
166 | 166 | 'uploadUrl' => "{$wgServer}{$wgScriptPath}/api.php?action=upload&". |
167 | 167 | "token={$token}&format=json&enablechunks=true&chunksessionkey=". |
168 | | - $this->setupChunkSession($summary, $comment, $watch ) ) ); |
| 168 | + $this->setupChunkSession( $summary, $comment, $watch ) ) ); |
169 | 169 | exit( 0 ); |
170 | 170 | } else if( $this->chunk_mode == UploadFromChunks::CHUNK ){ |
171 | 171 | $status = $this->doChunkAppend(); |
Index: trunk/phase3/includes/HttpFunctions.php |
— | — | @@ -11,7 +11,8 @@ |
12 | 12 | const ASYNC_DOWNLOAD = 2; // asynchronous upload we should spawn out another process and monitor progress if possible) |
13 | 13 | |
14 | 14 | var $body = ''; |
15 | | - public static function request($method, $url, $opts = Array() ){ |
| 15 | + |
| 16 | + public static function request( $method, $url, $opts = array() ){ |
16 | 17 | $opts['method'] = ( strtoupper( $method ) == 'GET' || strtoupper( $method ) == 'POST' ) ? strtoupper( $method ) : null; |
17 | 18 | $req = new HttpRequest( $url, $opts ); |
18 | 19 | $status = $req->doRequest(); |
— | — | @@ -22,11 +23,12 @@ |
23 | 24 | return false; |
24 | 25 | } |
25 | 26 | } |
| 27 | + |
26 | 28 | /** |
27 | 29 | * Simple wrapper for Http::request( 'GET' ) |
28 | 30 | */ |
29 | 31 | public static function get( $url, $timeout = false ) { |
30 | | - $opts = Array(); |
| 32 | + $opts = array(); |
31 | 33 | if( $timeout ) |
32 | 34 | $opts['timeout'] = $timeout; |
33 | 35 | return Http::request( 'GET', $url, $opts ); |
— | — | @@ -39,7 +41,7 @@ |
40 | 42 | return Http::request( 'POST', $url, $opts ); |
41 | 43 | } |
42 | 44 | |
43 | | - public static function doDownload( $url, $target_file_path , $dl_mode = self::SYNC_DOWNLOAD , $redirectCount = 0 ){ |
| 45 | + public static function doDownload( $url, $target_file_path, $dl_mode = self::SYNC_DOWNLOAD, $redirectCount = 0 ){ |
44 | 46 | global $wgPhpCli, $wgMaxUploadSize, $wgMaxRedirects; |
45 | 47 | // do a quick check to HEAD to insure the file size is not > $wgMaxUploadSize |
46 | 48 | $headRequest = new HttpRequest( $url, array( 'headers_only' => true ) ); |
— | — | @@ -53,7 +55,7 @@ |
54 | 56 | if( isset( $head['Location'] ) && strrpos( $head[0], '302' ) !== false ){ |
55 | 57 | if( $redirectCount < $wgMaxRedirects ){ |
56 | 58 | if( UploadFromUrl::isValidURI( $head['Location'] ) ){ |
57 | | - return self::doDownload( $head['Location'], $target_file_path , $dl_mode, $redirectCount++ ); |
| 59 | + return self::doDownload( $head['Location'], $target_file_path, $dl_mode, $redirectCount++ ); |
58 | 60 | } else { |
59 | 61 | return Status::newFatal( 'upload-proto-error' ); |
60 | 62 | } |
— | — | @@ -104,7 +106,7 @@ |
105 | 107 | // store the url and target path: |
106 | 108 | $_SESSION['wsDownload'][$upload_session_key]['url'] = $url; |
107 | 109 | $_SESSION['wsDownload'][$upload_session_key]['target_file_path'] = $target_file_path; |
108 | | - //since we request from the cmd line we lose the original host name pass in the session: |
| 110 | + // since we request from the cmd line we lose the original host name pass in the session: |
109 | 111 | $_SESSION['wsDownload'][$upload_session_key]['orgServer'] = $wgServer; |
110 | 112 | |
111 | 113 | if( $content_length ) |
— | — | @@ -136,32 +138,33 @@ |
137 | 139 | /** |
138 | 140 | * used to run a session based download. Is initiated via the shell. |
139 | 141 | * |
140 | | - * @param $session_id String: the session id to grab download details from |
| 142 | + * @param $session_id String: the session id to grab download details from |
141 | 143 | * @param $upload_session_key String: the key of the given upload session |
142 | 144 | * (a given client could have started a few http uploads at once) |
143 | 145 | */ |
144 | 146 | public static function doSessionIdDownload( $session_id, $upload_session_key ){ |
145 | 147 | global $wgUser, $wgEnableWriteAPI, $wgAsyncHTTPTimeout, $wgServer; |
146 | 148 | wfDebug( __METHOD__ . "\n\ndoSessionIdDownload:\n\n" ); |
| 149 | + |
147 | 150 | // set session to the provided key: |
148 | 151 | session_id( $session_id ); |
149 | 152 | // start the session |
150 | 153 | if( session_start() === false ){ |
151 | 154 | wfDebug( __METHOD__ . ' could not start session' ); |
152 | 155 | } |
153 | | - //get all the vars we need from session_id |
154 | | - if(!isset($_SESSION[ 'wsDownload' ][$upload_session_key])){ |
155 | | - wfDebug( __METHOD__ .' Error:could not find upload session'); |
| 156 | + // get all the vars we need from session_id |
| 157 | + if( !isset( $_SESSION[ 'wsDownload' ][$upload_session_key] ) ){ |
| 158 | + wfDebug( __METHOD__ . ' Error:could not find upload session'); |
156 | 159 | exit(); |
157 | 160 | } |
158 | 161 | // setup the global user from the session key we just inherited |
159 | 162 | $wgUser = User::newFromSession(); |
160 | 163 | |
161 | 164 | // grab the session data to setup the request: |
162 | | - $sd =& $_SESSION['wsDownload'][$upload_session_key]; |
163 | | - |
164 | | - //update the wgServer var ( since cmd line thinks we are localhost when we are really orgServer) |
165 | | - if(isset($sd['orgServer']) && $sd['orgServer']){ |
| 165 | + $sd =& $_SESSION['wsDownload'][$upload_session_key]; |
| 166 | + |
| 167 | + // update the wgServer var ( since cmd line thinks we are localhost when we are really orgServer) |
| 168 | + if( isset( $sd['orgServer'] ) && $sd['orgServer'] ){ |
166 | 169 | $wgServer = $sd['orgServer']; |
167 | 170 | } |
168 | 171 | // close down the session so we can other http queries can get session updates: |
— | — | @@ -173,7 +176,7 @@ |
174 | 177 | 'timeout' => $wgAsyncHTTPTimeout |
175 | 178 | ) ); |
176 | 179 | // run the actual request .. (this can take some time) |
177 | | - wfDebug( __METHOD__ . "do Request: " . $sd['url'] . ' tf: ' . $sd['target_file_path'] ); |
| 180 | + wfDebug( __METHOD__ . 'do Request: ' . $sd['url'] . ' tf: ' . $sd['target_file_path'] ); |
178 | 181 | $status = $req->doRequest(); |
179 | 182 | //wfDebug("done with req status is: ". $status->isOK(). ' '.$status->getWikiText(). "\n"); |
180 | 183 | |
— | — | @@ -260,13 +263,14 @@ |
261 | 264 | return "MediaWiki/$wgVersion"; |
262 | 265 | } |
263 | 266 | } |
| 267 | + |
264 | 268 | class HttpRequest { |
265 | 269 | var $target_file_path; |
266 | 270 | var $upload_session_key; |
267 | 271 | |
268 | 272 | function __construct( $url, $opt ){ |
269 | 273 | global $wgSyncHTTPTimeout; |
270 | | - //double check its a valid url: |
| 274 | + // double check that it's a valid url: |
271 | 275 | $this->url = $url; |
272 | 276 | |
273 | 277 | // set the timeout to default sync timeout (unless the timeout option is provided) |
— | — | @@ -286,8 +290,7 @@ |
287 | 291 | * 'adapter' => 'curl', 'soket' |
288 | 292 | */ |
289 | 293 | public function doRequest() { |
290 | | - |
291 | | - #make sure we have a valid url |
| 294 | + # Make sure we have a valid url |
292 | 295 | if( !UploadFromUrl::isValidURI( $this->url ) ) |
293 | 296 | return Status::newFatal('bad-url'); |
294 | 297 | |
— | — | @@ -412,12 +415,12 @@ |
413 | 416 | public function doPhpReq(){ |
414 | 417 | global $wgTitle, $wgHTTPProxy; |
415 | 418 | |
416 | | - #check for php.ini allow_url_fopen |
| 419 | + # Check for php.ini allow_url_fopen |
417 | 420 | if( !ini_get( 'allow_url_fopen' ) ){ |
418 | 421 | return Status::newFatal( 'allow_url_fopen needs to be enabled for http copy to work' ); |
419 | 422 | } |
420 | 423 | |
421 | | - //start with good status: |
| 424 | + // start with good status: |
422 | 425 | $status = Status::newGood(); |
423 | 426 | |
424 | 427 | if ( $this->headers_only ) { |
— | — | @@ -425,8 +428,8 @@ |
426 | 429 | return $status; |
427 | 430 | } |
428 | 431 | |
429 | | - //setup the headers |
430 | | - $headers = array( "User-Agent: " . Http :: userAgent() ); |
| 432 | + // setup the headers |
| 433 | + $headers = array( "User-Agent: " . Http::userAgent() ); |
431 | 434 | if ( is_object( $wgTitle ) ) { |
432 | 435 | $headers[] = "Referer: ". $wgTitle->getFullURL(); |
433 | 436 | } |
— | — | @@ -453,25 +456,26 @@ |
454 | 457 | $status = $cwrite->status; |
455 | 458 | return $status; |
456 | 459 | } |
457 | | - //read $fh into the simpleFileWriter (grab in 64K chunks since its likely a media file) |
458 | | - while ( !feof( $fh )) { |
459 | | - $contents = fread($fh, 65536); |
460 | | - $cwrite->callbackWriteBody($fh, $contents ); |
| 460 | + |
| 461 | + // read $fh into the simpleFileWriter (grab in 64K chunks since its likely a media file) |
| 462 | + while ( !feof( $fh ) ) { |
| 463 | + $contents = fread( $fh, 65536 ); |
| 464 | + $cwrite->callbackWriteBody( $fh, $contents ); |
461 | 465 | } |
462 | 466 | |
463 | 467 | $cwrite->close(); |
464 | | - //check for simpleFileWriter error: |
| 468 | + // check for simpleFileWriter error: |
465 | 469 | if( !$cwrite->status->isOK() ){ |
466 | 470 | return $cwrite->status; |
467 | 471 | } |
468 | 472 | } else { |
469 | | - //read $fh into status->value |
| 473 | + // read $fh into status->value |
470 | 474 | $status->value = @stream_get_contents( $fh ); |
471 | 475 | } |
472 | 476 | //close the url file wrapper |
473 | 477 | fclose( $fh ); |
474 | 478 | |
475 | | - //check for "false" |
| 479 | + // check for "false" |
476 | 480 | if( $status->value === false ){ |
477 | 481 | $status->error( 'file_get_contents-failed' ); |
478 | 482 | } |
— | — | @@ -502,7 +506,7 @@ |
503 | 507 | $this->prevTime = time(); |
504 | 508 | } |
505 | 509 | |
506 | | - public function callbackWriteBody($ch, $data_packet){ |
| 510 | + public function callbackWriteBody( $ch, $data_packet ){ |
507 | 511 | global $wgMaxUploadSize; |
508 | 512 | |
509 | 513 | // write out the content |