Follow-up r70037: Move isIniSizeOverflow magic to WebRequestUpload
[lhc/web/wiklou.git] / includes / upload / UploadFromFile.php
1 <?php
2 /**
3 * @file
4 * @ingroup upload
5 *
6 * @author Bryan Tong Minh
7 *
8 * Implements regular file uploads
9 */
10 class UploadFromFile extends UploadBase {
11 protected $mWebUpload = null;
12
13 function initializeFromRequest( &$request ) {
14 $this->mWebUpload = $request->getUpload( 'wpUploadFile' );
15
16 $desiredDestName = $request->getText( 'wpDestFile' );
17 if( !$desiredDestName )
18 $desiredDestName = $this->mWebUpload->getName();
19 return $this->initializePathInfo(
20 $desiredDestName,
21 $this->mWebUpload->getTempName(),
22 $this->mWebUpload->getSize()
23 );
24 }
25 /**
26 * Entry point for upload from file.
27 */
28 function initialize( $name, $tempPath, $fileSize ) {
29 return $this->initializePathInfo( $name, $tempPath, $fileSize );
30 }
31 static function isValidRequest( $request ) {
32 # Allow all requests, even if no file is present, so that an error
33 # because a post_max_size or upload_max_filesize overflow
34 return true;
35 }
36
37 public function verifyUpload() {
38 # Check for a post_max_size or upload_max_size overflow, so that a
39 # proper error can be shown to the user
40 if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
41 if ( $this->mWebUpload->isIniSizeOverflow() ) {
42 global $wgMaxUploadSize;
43 return array(
44 'status' => self::FILE_TOO_LARGE,
45 'max' => min(
46 $wgMaxUploadSize,
47 wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
48 wfShorthandToInteger( ini_get( 'post_max_size' ) )
49 ),
50 );
51 }
52 }
53
54 return parent::verifyUpload();
55 }
56 }