Add support for Number grouping(commafy) based on CLDR number grouping patterns like...
[lhc/web/wiklou.git] / includes / upload / UploadFromFile.php
1 <?php
2 /**
3 * Implements regular file uploads
4 *
5 * @file
6 * @ingroup upload
7 * @author Bryan Tong Minh
8 */
9
10 class UploadFromFile extends UploadBase {
11
12 /**
13 * @var WebRequestUpload
14 */
15 protected $mUpload = null;
16
17 /**
18 * @param $request WebRequest
19 */
20 function initializeFromRequest( &$request ) {
21 $upload = $request->getUpload( 'wpUploadFile' );
22 $desiredDestName = $request->getText( 'wpDestFile' );
23 if( !$desiredDestName )
24 $desiredDestName = $upload->getName();
25
26 return $this->initialize( $desiredDestName, $upload );
27 }
28
29 /**
30 * Initialize from a filename and a WebRequestUpload
31 * @param $name
32 * @param $webRequestUpload
33 */
34 function initialize( $name, $webRequestUpload ) {
35 $this->mUpload = $webRequestUpload;
36 return $this->initializePathInfo( $name,
37 $this->mUpload->getTempName(), $this->mUpload->getSize() );
38 }
39
40 /**
41 * @param $request
42 * @return bool
43 */
44 static function isValidRequest( $request ) {
45 # Allow all requests, even if no file is present, so that an error
46 # because a post_max_size or upload_max_filesize overflow
47 return true;
48 }
49
50 /**
51 * @return string
52 */
53 public function getSourceType() {
54 return 'file';
55 }
56
57 /**
58 * @return array
59 */
60 public function verifyUpload() {
61 # Check for a post_max_size or upload_max_size overflow, so that a
62 # proper error can be shown to the user
63 if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
64 if ( $this->mUpload->isIniSizeOverflow() ) {
65 return array(
66 'status' => UploadBase::FILE_TOO_LARGE,
67 'max' => min(
68 self::getMaxUploadSize( $this->getSourceType() ),
69 wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
70 wfShorthandToInteger( ini_get( 'post_max_size' ) )
71 ),
72 );
73 }
74 }
75
76 return parent::verifyUpload();
77 }
78
79 /**
80 * Get the path to the file underlying the upload
81 * @return String path to file
82 */
83 public function getFileTempname() {
84 return $this->mUpload->getTempname();
85 }
86 }