r50836 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50835‎ | r50836 | r50837 >
Date:21:34, 20 May 2009
Author:dale
Status:deferred
Tags:
Comment:
fixed missing session on upload issue
Modified paths:
  • /branches/new-upload/phase3/includes/HttpFunctions.php (modified) (history)
  • /branches/new-upload/phase3/includes/OutputPage.php (modified) (history)
  • /branches/new-upload/phase3/includes/UploadBase.php (modified) (history)
  • /branches/new-upload/phase3/includes/UploadFromStash.php (modified) (history)
  • /branches/new-upload/phase3/includes/UploadFromUrl.php (modified) (history)
  • /branches/new-upload/phase3/includes/specials/SpecialUpload.php (modified) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvFirefogg.js (modified) (history)

Diff [purge]

Index: branches/new-upload/phase3/includes/UploadFromUrl.php
@@ -15,18 +15,21 @@
1616 return $wgAllowCopyUploads && parent::isEnabled();
1717 }
1818 /*entry point for Api upload:: ASYNC_DOWNLOAD (if possible) */
19 - function initialize( $name, $url, $asyncdownload = Http::SYNC_DOWNLOAD ) {
 19+ function initialize( $name, $url, $asyncdownload = false) {
2020 global $wgTmpDirectory, $wgPhpCliPath;
21 -
22 - if($asyncdownload && $wgPhpCliPath && wfShellExecEnabled() ){
23 - $this->dl_mode = Http::ASYNC_DOWNLOAD;
24 - }else{
25 - $this->dl_mode = Http::SYNC_DOWNLOAD;
 21+
 22+ //check for $asyncdownload request:
 23+ if($asyncdownload !== false){
 24+ if($wgPhpCliPath && wfShellExecEnabled() ){
 25+ $this->dl_mode = Http::ASYNC_DOWNLOAD;
 26+ }else{
 27+ $this->dl_mode = Http::SYNC_DOWNLOAD;
 28+ }
2629 }
2730
2831 $local_file = tempnam( $wgTmpDirectory, 'WEBUPLOAD' );
2932 parent::initialize( $name, $local_file, 0, true );
30 -
 33+
3134 $this->mUrl = trim( $url );
3235 }
3336 public function isAsync(){
@@ -34,6 +37,7 @@
3538 }
3639 /*entry point for SpecialUpload no ASYNC_DOWNLOAD possible: */
3740 function initializeFromRequest( &$request ) {
 41+
3842 //set dl mode if not set:
3943 if(!$this->dl_mode)
4044 $this->dl_mode = Http::SYNC_DOWNLOAD;
@@ -49,18 +53,16 @@
5054 /**
5155 * Do the real fetching stuff
5256 */
53 - function fetchFile( ) {
 57+ function fetchFile( ) {
5458 //entry point for SpecialUplaod
5559 if( self::isValidURI($this->mUrl) === false) {
5660 return Status::newFatal('upload-proto-error');
57 - }
58 - //print "fetchFile:: $this->dl_mode";
 61+ }
 62+ //now do the actual download to the target file:
 63+ $status = Http::doDownload ( $this->mUrl, $this->mTempPath, $this->dl_mode );
5964
60 - //now do the actual download to the target file:
61 - $status = Http::doDownload ( $this->mUrl, $this->mTempPath, $this->dl_mode );
62 -
6365 //update the local filesize var:
64 - $this->mFileSize = filesize( $this->mTempPath );
 66+ $this->mFileSize = filesize( $this->mTempPath );
6567
6668 return $status;
6769 }
Index: branches/new-upload/phase3/includes/OutputPage.php
@@ -1020,9 +1020,7 @@
10211021 if( $this->mDoNothing ){
10221022 return;
10231023 }
1024 -
1025 - wfProfileIn( __METHOD__ );
1026 -
 1024+ wfProfileIn( __METHOD__ );
10271025 if ( '' != $this->mRedirect ) {
10281026 # Standards require redirect URLs to be absolute
10291027 $this->mRedirect = wfExpandUrl( $this->mRedirect );
@@ -1031,8 +1029,7 @@
10321030 $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
10331031 }
10341032 $this->mLastModified = wfTimestamp( TS_RFC2822 );
1035 - }
1036 -
 1033+ }
10371034 $this->sendCacheControl();
10381035
10391036 $wgRequest->response()->header("Content-Type: text/html; charset=utf-8");
Index: branches/new-upload/phase3/includes/UploadFromStash.php
@@ -1,6 +1,6 @@
22 <?php
33 class UploadFromStash extends UploadBase {
4 - static function isValidSessionKey( $key, $sessionData ) {
 4+ static function isValidSessionKey( $key, $sessionData ) {
55 return !empty( $key ) &&
66 is_array( $sessionData ) &&
77 isset( $sessionData[$key] ) &&
@@ -9,7 +9,7 @@
1010 ;
1111 }
1212 static function isValidRequest(& $request ) {
13 - $sessionData = $request->getSessionData('wsUploadData');
 13+ $sessionData = $request->getSessionData('wsUploadData');
1414 return self::isValidSessionKey(
1515 $request->getInt( 'wpSessionKey' ),
1616 $sessionData
@@ -30,14 +30,13 @@
3131
3232 $this->mFileProps = $sessionData['mFileProps'];
3333 }
34 - function initializeFromRequest( &$request ) {
 34+ function initializeFromRequest( &$request ) {
3535 $sessionKey = $request->getInt( 'wpSessionKey' );
3636 $sessionData = $request->getSessionData('wsUploadData');
3737
3838 $desiredDestName = $request->getText( 'wpDestFile' );
3939 if( !$desiredDestName )
40 - $desiredDestName = $request->getText( 'wpUploadFile' );
41 -
 40+ $desiredDestName = $request->getText( 'wpUploadFile' );
4241 return $this->initialize( $desiredDestName, $sessionData[$sessionKey] );
4342 }
4443
Index: branches/new-upload/phase3/includes/HttpFunctions.php
@@ -31,12 +31,8 @@
3232 public static function doDownload( $url, $target_file_path , $dl_mode = self::SYNC_DOWNLOAD , $redirectCount=0){
3333 global $wgPhpCliPath, $wgMaxUploadSize, $wgMaxRedirects;
3434 //do a quick check to HEAD to insure the file size is not > $wgMaxUploadSize
35 - $head = get_headers($url, 1);
 35+ $head = get_headers($url, 1);
3636
37 - //check for non-valid result:
38 -
39 - wfDebug("\n head: " . print_r($head, true). "\n");
40 -
4137 //check for redirects:
4238 if( isset( $head['Location'] ) && strrpos($head[0], '302')!==false ){
4339 if($redirectCount < $wgMaxRedirects){
Index: branches/new-upload/phase3/includes/specials/SpecialUpload.php
@@ -41,7 +41,7 @@
4242 * Get data POSTed through the form and assign them to the object
4343 * @param $request Data posted.
4444 */
45 - function __construct( &$request ) {
 45+ function __construct( &$request ) {
4646 // Guess the desired name from the filename if not provided
4747 $this->mDesiredDestName = $request->getText( 'wpDestFile' );
4848 if( !$this->mDesiredDestName )
@@ -82,8 +82,8 @@
8383 * @access public
8484 */
8585 function execute() {
86 - global $wgUser, $wgOut;
87 -
 86+ global $wgUser, $wgOut;
 87+
8888 # Check uploading enabled
8989 if( !UploadBase::isEnabled() ) {
9090 $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext' );
@@ -258,10 +258,10 @@
259259 $status = $this->mUpload->fetchFile();
260260 if( !$status->isOK() ){
261261 return array( 'status' =>UploadBase::BEFORE_PROCESSING, 'error'=>$status->getWikiText() );
262 - }
 262+ }
263263
264264 // Check whether this is a sane upload
265 - $result = $this->mUpload->verifyUpload();
 265+ $result = $this->mUpload->verifyUpload();
266266 if( $result != UploadBase::OK )
267267 return $result;
268268
Index: branches/new-upload/phase3/includes/UploadBase.php
@@ -57,12 +57,12 @@
5858 * Create a form of UploadBase depending on wpSourceType and initializes it
5959 */
6060 static function createFromRequest( &$request, $type = null ) {
61 - $type = $type ? $type : $request->getVal( 'wpSourceType' );
62 -
 61+ $type = $type ? $type : $request->getVal( 'wpSourceType' );
 62+
6363 if( !$type )
64 - return null;
65 -
66 - $type = ucfirst($type);
 64+ return null;
 65+
 66+ $type = ucfirst($type);
6767 $className = 'UploadFrom'.$type;
6868 if( !in_array( $type, self::$uploadHandlers ) )
6969 return null;
@@ -70,8 +70,9 @@
7171 if( !call_user_func( array( $className, 'isEnabled' ) ) )
7272 return null;
7373
 74+
7475 if( !call_user_func( array( $className, 'isValidRequest' ), $request ) )
75 - return null;
 76+ return null;
7677
7778 $handler = new $className;
7879
@@ -279,7 +280,7 @@
280281
281282 $exists = self::getExistsWarning( $this->mLocalFile );
282283 if( $exists !== false )
283 - $warning['exists'] = $exists;
 284+ $warning['exists'] = $exists;
284285
285286 // Check whether this may be a thumbnail
286287 if( $exists !== false && $exists[0] != 'thumb'
@@ -455,16 +456,17 @@
456457 # Couldn't save the file.
457458 return false;
458459 }
459 - $mTempPath = $status->value;
460 -
461 - $key = $this->getSessionKey ();
 460+ $mTempPath = $status->value;
 461+ session_start();//start up the session (might have been previously closed to prevent php session locking)
 462+ $key = $this->getSessionKey ();
462463 $_SESSION['wsUploadData'][$key] = array(
463464 'mTempPath' => $mTempPath,
464465 'mFileSize' => $this->mFileSize,
465466 'mSrcName' => $this->mSrcName,
466467 'mFileProps' => $this->mFileProps,
467468 'version' => self::SESSION_VERSION,
468 - );
 469+ );
 470+ session_write_close();
469471 return $key;
470472 }
471473 //pull session Key gen from stash in cases where we want to start an upload without much information
Index: branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvFirefogg.js
@@ -8,10 +8,9 @@
99 'fogg-save_local_file' : 'Save Ogg',
1010 'fogg-check_for_fogg' : 'Checking for Firefogg <blink>...</blink>',
1111 'fogg-installed' : 'Firefogg is Installed',
12 - 'fogg-please_install' : 'You don\'t have firefogg, please <a href="$1">install firefogg</a>',
 12+ 'fogg-please_install' : 'You don\'t have firefogg installed, please <a href="$1">install firefogg</a>',
1313 'fogg-use_latest_fox' : 'You need a <a href="http://www.mozilla.com/en-US/firefox/all-beta.html">Firefox 3.5</a> to use Firefogg',
14 - 'passthrough_mode' : 'Your selected file is already ogg or not a video file',
15 -
 14+ 'passthrough_mode' : 'Your selected file is already ogg or not a video file',
1615 });
1716
1817 var firefogg_install_links = {
@@ -132,11 +131,11 @@
133132 },
134133 getTargetHtml:function(target){
135134 if( target.substr(7,3)=='btn'){
136 - return '<input class="' + target + '" type="button" value="' + gM( 'fogg-' + target.substring(11)) + '"/> ';
 135+ return '<input style="" class="' + target + '" type="button" value="' + gM( 'fogg-' + target.substring(11)) + '"/> ';
137136 }else if(target.substr(7,5)=='input'){
138 - return '<input class="' + target + '" type="text" value="' + gM( 'fogg-' + target.substring(11)) + '"/> ';
 137+ return '<input style="" class="' + target + '" type="text" value="' + gM( 'fogg-' + target.substring(11)) + '"/> ';
139138 }else{
140 - return '<div class="' + target + '">'+ gM('fogg-'+ target.substring(7)) + '</div> ';
 139+ return '<div style="" class="' + target + '" >'+ gM('fogg-'+ target.substring(7)) + '</div> ';
141140 }
142141 },
143142 doControlBindings: function(){
@@ -145,21 +144,28 @@
146145 //hide all targets:
147146 var hide_target_list='';
148147 var coma='';
149 - $j.each(default_firefogg_options, function(target, na){
 148+ $j.each(default_firefogg_options, function(target, na){
150149 if(target.substring(0, 6)=='target'){
151150 hide_target_list+=coma + _this[target];
152151 coma=',';
153152 }
154 - });
155 - $j( hide_target_list ).hide();
 153+ });
 154+ $j( hide_target_list ).hide();
 155+ //if rewriting the form lets keep the text input around:
 156+ if(_this.form_rewrite)
 157+ $j('#target_input_file_name').show();
156158
157159 //hide all but check-for-fogg
158160 //check for firefogg
159161 if( _this.firefoggCheck() ){
160162 //show select file:
161 - $j(this.target_btn_select_file).click(function(){
162 - _this.select_fogg();
163 - }).show().attr('disabled', false);
 163+ $j(this.target_btn_select_file).unbind(
 164+ ).attr('disabled', false
 165+ ).css({'display':'inline'}
 166+ ).click(function(){
 167+ _this.select_fogg();
 168+ });
 169+
164170 }else{
165171 var os_link = false;
166172 if(navigator.oscpu){
@@ -169,11 +175,11 @@
170176 os_link = firefogg_install_links['macosx'];
171177 else if(navigator.oscpu.search('Win') >= 0)
172178 os_link = firefogg_install_links['win32'];
173 - }
174 - $j(_this.target_please_install).html( gM('fogg-please_install',os_link )).show();
 179+ }
 180+ $j(_this.target_please_install).html( gM('fogg-please_install',os_link )).css('padding', '10px').show();
175181 }
176182 //setup the target save local file bindins:
177 - $j( _this.target_btn_save_local_file ).click(function(){
 183+ $j( _this.target_btn_save_local_file ).unbind().click(function(){
178184 //update the output target
179185 if(_this.fogg){
180186 //if(_this.fogg.saveVideoAs()){
@@ -194,26 +200,42 @@
195201 //assume input target
196202 setupForm: function(){
197203 js_log('firefogg::setupForm::');
198 -
199 - //call the parent form setup
200 - this.pe_setupForm();
201 - <input type="file" size="60" id="wpUploadFile" name="wpUploadFile" tabindex="1"/>
202 - //change the file browser to type text:
203 - $j(this.selector).replaceWith('<input type="text" ' +
204 - 'size="' + $j(this.selector).attr('size') + '" ' +
205 - 'id="' + $j(this.selector).attr('id') + '" ' +
206 - 'name="' + $j(this.selector).attr("name") + '" ' +
207 - 'tabindex="' + $j(this.selector).attr('tabindex') + '" '+
208 - 'class="' + $j(this.selector).attr('class') + '" ' +
209 - '>');
210204
 205+ //check if we have firefogg (if not just add a link and stop proccessing)
 206+ if( !this.firefoggCheck() ){
 207+ //add some status indicators if not provided:
 208+ if(!this.target_please_install){
 209+ $j(this.selector).after ( this.getTargetHtml('target_please_install') );
 210+ //match the first sibling of our input type selector:
 211+ this.target_please_install = this.selector + ' ~ .target_please_install';
 212+ }
 213+ //update download link:
 214+ this.doControlBindings();
 215+ return false;
 216+ }
 217+ //else do form setup:
 218+ this.pe_setupForm();
 219+ //change the file browser to type text: (can't directly change input from "file" to "text" so longer way:
 220+ var inTag = '<input ';
 221+ $j.each($j(this.selector).get(0).attributes, function(i, attr){
 222+ var val = attr.value;
 223+ if( attr.name == 'type')
 224+ val = 'text';
 225+ inTag += attr.name + '="' + val + '" ';
 226+ });
 227+ if(!$j(this.selector).attr('style'))
 228+ inTag += 'style="display:inline" ';
 229+ inTag+= '>';
 230+
 231+ js_log('set input: ' + inTag);
 232+ $j(this.selector).replaceWith(inTag);
 233+
211234 this.target_input_file_name = this.selector;
212235
213236 $j(this.selector).after(
214237 this.getTargetHtml('target_btn_select_file')
215238 );
216 - //check for the other inline status indicator targets:
217 -
 239+ //check for the other inline status indicator targets:
218240 //update the bindings:
219241 this.doControlBindings();
220242 },
@@ -228,7 +250,7 @@
229251 js_log('videoSelectReady');
230252 //if not already hidden hide select file and show "select new":
231253 $j(_this.target_btn_select_file).hide();
232 - //show and setup binding for new file:
 254+ //show and setup binding for select new file:
233255 $j(_this.target_btn_select_new_file).show().click(function(){
234256 _this.select_fogg();
235257 });
@@ -255,12 +277,12 @@
256278 $j(_this.target_input_file_name).val(_this.fogg.sourceFilename).show();
257279
258280 if(_this.new_source_cb){
259 - new_source_cb( _this.fogg.sourceFilename );
 281+ _this.new_source_cb( _this.fogg.sourceFilename );
260282 }
261283 }
262284 }
263285 //wait 100ms to get video info:
264 - setTimeout(videoSelectReady, 200);
 286+ setTimeout(videoSelectReady, 100);
265287 }
266288 },
267289 //simple auto encoder settings just enable passthough if file is not video or > 480 pixles tall

Status & tagging log