MediaWiki  REL1_19
UploadFromFile.php
Go to the documentation of this file.
00001 <?php
00008 class UploadFromFile extends UploadBase {
00009 
00013         protected $mUpload = null;
00014 
00018         function initializeFromRequest( &$request ) {
00019                 $upload = $request->getUpload( 'wpUploadFile' );                
00020                 $desiredDestName = $request->getText( 'wpDestFile' );
00021                 if( !$desiredDestName )
00022                         $desiredDestName = $upload->getName();
00023                         
00024                 return $this->initialize( $desiredDestName, $upload );
00025         }
00026 
00032         function initialize( $name, $webRequestUpload ) {
00033                 $this->mUpload = $webRequestUpload;
00034                 return $this->initializePathInfo( $name, 
00035                         $this->mUpload->getTempName(), $this->mUpload->getSize() );
00036         }
00037 
00042         static function isValidRequest( $request ) {
00043                 # Allow all requests, even if no file is present, so that an error
00044                 # because a post_max_size or upload_max_filesize overflow
00045                 return true;
00046         }
00047 
00051         public function getSourceType() {
00052                 return 'file';
00053         }
00054 
00058         public function verifyUpload() {
00059                 # Check for a post_max_size or upload_max_size overflow, so that a 
00060                 # proper error can be shown to the user
00061                 if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
00062                         if ( $this->mUpload->isIniSizeOverflow() ) {
00063                                 return array( 
00064                                         'status' => UploadBase::FILE_TOO_LARGE,
00065                                         'max' => min( 
00066                                                 self::getMaxUploadSize( $this->getSourceType() ), 
00067                                                 wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ), 
00068                                                 wfShorthandToInteger( ini_get( 'post_max_size' ) )
00069                                         ),
00070                                 );
00071                         }
00072                 }
00073                 
00074                 return parent::verifyUpload();
00075         }
00076 }