r57732 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57731‎ | r57732 | r57733 >
Date:00:14, 15 October 2009
Author:dale
Status:reverted
Tags:
Comment:
* ( bug 21089 ) fixes js2 upload stash support.
* Tested with chunk firefogg uploads, normal js2 uploads and http copy by url uploads
Modified paths:
  • /trunk/phase3/includes/api/ApiUpload.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadFromChunks.php (modified) (history)
  • /trunk/phase3/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js (modified) (history)
  • /trunk/phase3/js2/mwEmbed/mv_embed.js (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadFromChunks.php
@@ -57,13 +57,14 @@
5858 // check for the file:
5959 return (bool)$request->getFileTempName( 'file' );
6060 }
61 -
6261 /* check warnings depending on chunk_mode */
6362 function checkWarnings(){
64 - $warning = array();
65 - return $warning;
 63+ if( $this->chunk_mode == UploadFromChunks::DONE ){
 64+ return parent::checkWarnings();
 65+ }else{
 66+ return array();
 67+ }
6668 }
67 -
6869 function isEmptyFile(){
6970 // does not apply to chunk init
7071 if( $this->chunk_mode == UploadFromChunks::INIT ){
@@ -72,20 +73,17 @@
7374 return parent::isEmptyFile();
7475 }
7576 }
76 -
7777 /**
7878 * Verify whether the upload is sane.
7979 * Returns self::OK or else an array with error information
8080 */
8181 function verifyUpload() {
82 - // no checks on chunk upload mode:
83 - if( $this->chunk_mode == UploadFromChunks::INIT )
84 - return array( 'status' => self::OK );
85 -
86 - // verify on init and last chunk request
87 - if( $this->chunk_mode == UploadFromChunks::CHUNK ||
88 - $this->chunk_mode == UploadFromChunks::DONE )
 82+ // verify once DONE uploading chunks
 83+ if( $this->chunk_mode == UploadFromChunks::DONE ){
8984 return parent::verifyUpload();
 85+ }else{
 86+ return array( 'status' => self::OK );
 87+ }
9088 }
9189
9290 // only run verifyFile on completed uploaded chunks
@@ -185,7 +183,7 @@
186184 return $status;
187185 }
188186 } else if( $this->chunk_mode == UploadFromChunks::DONE ){
189 - // update the values from the local (session init) if not paseed again)
 187+ // update the values from the local (session init) if not passed again)
190188 if( $summary == '' )
191189 $summary = $this->mSummary;
192190
@@ -194,7 +192,9 @@
195193
196194 if( $watch == '' )
197195 $watch = $this->mWatch;
 196+
198197 $status = parent::performUpload( $summary, $comment, $watch, $user );
 198+
199199 if( !$status->isGood() ) {
200200 return $status;
201201 }
@@ -209,7 +209,6 @@
210210 )
211211 );
212212 exit( 0 );
213 -
214213 }
215214 }
216215
Index: trunk/phase3/includes/api/ApiUpload.php
@@ -57,11 +57,11 @@
5858 // Check whether upload is enabled
5959 if ( !UploadBase::isEnabled() )
6060 $this->dieUsageMsg( array( 'uploaddisabled' ) );
61 -
 61+
6262 // One and only one of the following parameters is needed
6363 $this->requireOnlyOneParameter( $this->mParams,
64 - 'sessionkey', 'file', 'url', 'enablechunks' );
65 -
 64+ 'sessionkey', 'file', 'url', 'enablechunks' );
 65+
6666 if ( $this->mParams['enablechunks'] ) {
6767 /**
6868 * Chunked upload mode
@@ -88,11 +88,10 @@
8989 /**
9090 * Return the status of the given background upload session_key:
9191 */
92 -
9392 // Check the session key
9493 if( !isset( $_SESSION['wsDownload'][$this->mParams['sessionkey']] ) )
9594 return $this->dieUsageMsg( array( 'invalid-session-key' ) );
96 -
 95+
9796 $sd =& $_SESSION['wsDownload'][$this->mParams['sessionkey']];
9897 // Keep passing down the upload sessionkey
9998 $statusResult = array(
@@ -100,22 +99,22 @@
101100 );
102101
103102 // put values into the final apiResult if available
104 - if( isset( $sd['apiUploadResult'] ) )
 103+ if( isset( $sd['apiUploadResult'] ) )
105104 $statusResult['apiUploadResult'] = $sd['apiUploadResult'];
106 - if( isset( $sd['loaded'] ) )
 105+ if( isset( $sd['loaded'] ) )
107106 $statusResult['loaded'] = $sd['loaded'];
108 - if( isset( $sd['content_length'] ) )
 107+ if( isset( $sd['content_length'] ) )
109108 $statusResult['content_length'] = $sd['content_length'];
110109
111 - return $this->getResult()->addValue( null,
 110+ return $this->getResult()->addValue( null,
112111 $this->getModuleName(), $statusResult );
113 -
 112+
114113 } elseif( $this->mParams['sessionkey'] ) {
115114 /**
116115 * Upload stashed in a previous request
117116 */
118117 $this->mUpload = new UploadFromStash();
119 - $this->mUpload->initialize( $this->mParams['filename'],
 118+ $this->mUpload->initialize( $this->mParams['filename'],
120119 $_SESSION['wsUploadData'][$this->mParams['sessionkey']] );
121120 } else {
122121 /**
@@ -135,14 +134,14 @@
136135 );
137136 } elseif ( isset( $this->mParams['url'] ) ) {
138137 $this->mUpload = new UploadFromUrl();
139 - $this->mUpload->initialize( $this->mParams['filename'],
 138+ $this->mUpload->initialize( $this->mParams['filename'],
140139 $this->mParams['url'], $this->mParams['asyncdownload'] );
141140
142141 $status = $this->mUpload->fetchFile();
143142 if( !$status->isOK() ) {
144143 return $this->dieUsage( 'fetchfileerror', $status->getWikiText() );
145144 }
146 -
 145+
147146 // check if we doing a async request set session info and return the upload_session_key)
148147 if( $this->mUpload->isAsync() ){
149148 $upload_session_key = $status->value;
@@ -161,11 +160,11 @@
162161 }
163162 }
164163 }
165 -
 164+
166165 if( !isset( $this->mUpload ) )
167166 $this->dieUsage( 'No upload module set', 'nomodule' );
168 -
169 -
 167+
 168+
170169 // Finish up the exec command:
171170 $this->doExecUpload();
172171
@@ -196,7 +195,7 @@
197196 if( $permErrors !== true ) {
198197 $this->dieUsageMsg( array( 'baddaccess-groups' ) );
199198 }
200 -
 199+
201200 // TODO: Move them to ApiBase's message map
202201 $verification = $this->mUpload->verifyUpload();
203202 if( $verification['status'] !== UploadBase::OK ) {
@@ -210,8 +209,8 @@
211210 break;
212211 case UploadBase::FILETYPE_BADTYPE:
213212 global $wgFileExtensions;
214 - $this->dieUsage( 'This type of file is banned', 'filetype-banned',
215 - 0, array(
 213+ $this->dieUsage( 'This type of file is banned', 'filetype-banned',
 214+ 0, array(
216215 'filetype' => $verification['finalExt'],
217216 'allowed' => $wgFileExtensions
218217 ) );
@@ -227,12 +226,12 @@
228227 $this->dieUsage( 'Overwriting an existing file is not allowed', 'overwrite' );
229228 break;
230229 case UploadBase::VERIFICATION_ERROR:
231 - $this->getResult()->setIndexedTagName( $verification['details'], 'detail' );
 230+ $this->getResult()->setIndexedTagName( $verification['details'], 'detail' );
232231 $this->dieUsage( 'This file did not pass file verification', 'verification-error',
233232 0, array( 'details' => $verification['details'] ) );
234233 break;
235234 case UploadBase::UPLOAD_VERIFICATION_ERROR:
236 - $this->dieUsage( "The modification you tried to make was aborted by an extension hook",
 235+ $this->dieUsage( "The modification you tried to make was aborted by an extension hook",
237236 'hookaborted', 0, array( 'error' => $verification['error'] ) );
238237 break;
239238 default:
@@ -242,14 +241,12 @@
243242 }
244243 return $result;
245244 }
246 -
247245 if( !$this->mParams['ignorewarnings'] ) {
248246 $warnings = $this->mUpload->checkWarnings();
249247 if( $warnings ) {
250 -
251248 // Add indices
252249 $this->getResult()->setIndexedTagName( $warnings, 'warning' );
253 -
 250+
254251 if( isset( $warnings['duplicate'] ) ) {
255252 $dupes = array();
256253 foreach( $warnings['duplicate'] as $key => $dupe )
@@ -262,16 +259,18 @@
263260 if( isset( $warnings['exists'] ) ) {
264261 $warning = $warnings['exists'];
265262 unset( $warnings['exists'] );
266 - $warnings[$warning['warning']] = $warning['file']->getName();
 263+ $warnings[$warning['warning']] = $warning['file']->getName();
267264 }
268 -
 265+
269266 $result['result'] = 'Warning';
270267 $result['warnings'] = $warnings;
271268
272269 $sessionKey = $this->mUpload->stashSession();
273 - if ( !$sessionKey )
 270+ if ( !$sessionKey )
274271 $this->dieUsage( 'Stashing temporary file failed', 'stashfailed' );
 272+
275273 $result['sessionkey'] = $sessionKey;
 274+
276275 return $result;
277276 }
278277 }
@@ -283,8 +282,8 @@
284283 if( !$status->isGood() ) {
285284 $error = $status->getErrorsArray();
286285 $this->getResult()->setIndexedTagName( $result['details'], 'error' );
287 -
288 - $this->dieUsage( 'An internal error occurred', 'internal-error', 0, $error );
 286+
 287+ $this->dieUsage( 'An internal error occurred', 'internal-error', 0, $error );
289288 }
290289
291290 $file = $this->mUpload->getLocalFile();
Index: trunk/phase3/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js
@@ -336,26 +336,6 @@
337337 _this.processApiResult( data );
338338 });
339339 },
340 - doAjaxWarningIgnore:function(){
341 - var _this = this;
342 - if( !_this.upload_session_key )
343 - return js_error('missing upload_session_key (can\'t ignore warnigns');
344 - //do the ignore warnings submit to the api:
345 - var req = {
346 - 'ignorewarnings' : 'true',
347 - 'sessionkey' :!_this.upload_session_key
348 - };
349 - //add token if present:
350 - if(this.etoken)
351 - req['token'] = this.etoken;
352 -
353 - do_api_req({
354 - 'data':req,
355 - 'url': _this.api_url
356 - },function(data){
357 - _this.processApiResult(data);
358 - });
359 - },
360340 doAjaxUploadStatus:function() {
361341 var _this = this;
362342
@@ -452,10 +432,10 @@
453433 error_code = apiRes.error.code;
454434 }else if( apiRes.upload.code ){
455435 if(typeof apiRes.upload.code == 'object'){
456 - if(apiRes.upload.code[0]){
 436+ if( apiRes.upload.code[0] ){
457437 error_code = apiRes.upload.code[0];
458438 }
459 - if(apiRes.upload.code['status']){
 439+ if( apiRes.upload.code['status'] ){
460440 error_code = apiRes.upload.code['status'];
461441 if(apiRes.upload.code['filtered'])
462442 errorReplaceArg =apiRes.upload.code['filtered'];
@@ -564,14 +544,36 @@
565545 wmsg+='</li>';
566546 }
567547 wmsg+='</ul>';
568 - if( apiRes.upload.warnings.sessionkey)
569 - _this.warnings_sessionkey = apiRes.upload.warnings.sessionkey;
 548+ if( apiRes.upload.sessionkey)
 549+ _this.warnings_sessionkey = apiRes.upload.sessionkey;
 550+
570551 var bObj = {};
571552 bObj[ gM('mwe-ignorewarning') ] = function() {
572 - js_log('ignorewarning req:')
573 - //re-inciate the upload proccess
574 - $j('#wpIgnoreWarning').attr('checked', true);
575 - $j( _this.editForm ).submit();
 553+ //check if we have a stashed key:
 554+ if( _this.warnings_sessionkey ){
 555+ //set to "loading"
 556+ $j( '#upProgressDialog' ).html( mv_get_loading_img() );
 557+ //setup loading:
 558+ var req = {
 559+ 'action' : 'upload',
 560+ 'sessionkey': _this.warnings_sessionkey,
 561+ 'ignorewarnings':1,
 562+ 'filename': $j('#wpDestFile').val(),
 563+ 'token' : _this.etoken
 564+ };
 565+ //run the upload from stash request
 566+ do_api_req({
 567+ 'data': req,
 568+ 'url' : _this.api_url
 569+ }, function( data ){
 570+ _this.processApiResult( data );
 571+ });
 572+ }else{
 573+ js_log('No session key re-sending upload')
 574+ //do a stashed upload
 575+ $j('#wpIgnoreWarning').attr('checked', true);
 576+ $j( _this.editForm ).submit();
 577+ }
576578 };
577579 bObj[ gM('mwe-return-to-form') ] = function(){
578580 $j(this).dialog('close');
Index: trunk/phase3/js2/mwEmbed/mv_embed.js
@@ -1016,7 +1016,7 @@
10171017 js_log( 'embedVideoCheck:' );
10181018 // Make sure we have jQuery
10191019 _this.jQueryCheck( function() {
1020 - //set class videonojs to hidden
 1020+ //set class videonojs to loading
10211021 $j('.videonojs').html( gM('mwe-loading_txt') );
10221022 //Set up the embed video player class request: (include the skin js as well)
10231023 var depReq = [

Status & tagging log