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