MediaWiki  REL1_24
UploadFromFile.php
Go to the documentation of this file.
00001 <?php
00030 class UploadFromFile extends UploadBase {
00034     protected $mUpload = null;
00035 
00039     function initializeFromRequest( &$request ) {
00040         $upload = $request->getUpload( 'wpUploadFile' );
00041         $desiredDestName = $request->getText( 'wpDestFile' );
00042         if ( !$desiredDestName ) {
00043             $desiredDestName = $upload->getName();
00044         }
00045 
00046         $this->initialize( $desiredDestName, $upload );
00047     }
00048 
00054     function initialize( $name, $webRequestUpload ) {
00055         $this->mUpload = $webRequestUpload;
00056         $this->initializePathInfo( $name,
00057             $this->mUpload->getTempName(), $this->mUpload->getSize() );
00058     }
00059 
00064     static function isValidRequest( $request ) {
00065         # Allow all requests, even if no file is present, so that an error
00066         # because a post_max_size or upload_max_filesize overflow
00067         return true;
00068     }
00069 
00073     public function getSourceType() {
00074         return 'file';
00075     }
00076 
00080     public function verifyUpload() {
00081         # Check for a post_max_size or upload_max_size overflow, so that a
00082         # proper error can be shown to the user
00083         if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
00084             if ( $this->mUpload->isIniSizeOverflow() ) {
00085                 return array(
00086                     'status' => UploadBase::FILE_TOO_LARGE,
00087                     'max' => min(
00088                         self::getMaxUploadSize( $this->getSourceType() ),
00089                         wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
00090                         wfShorthandToInteger( ini_get( 'post_max_size' ) )
00091                     ),
00092                 );
00093             }
00094         }
00095 
00096         return parent::verifyUpload();
00097     }
00098 }