Follow-up r78452: missed a couple of hidden fields in SpecialUpload
[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 protected $mUpload = null;
12
13 function initializeFromRequest( &$request ) {
14 $upload = $request->getUpload( 'wpUploadFile' );
15 $desiredDestName = $request->getText( 'wpDestFile' );
16 if( !$desiredDestName )
17 $desiredDestName = $upload->getName();
18
19 return $this->initialize( $desiredDestName, $upload );
20 }
21
22 /**
23 * Initialize from a filename and a WebRequestUpload
24 */
25 function initialize( $name, $webRequestUpload ) {
26 $this->mUpload = $webRequestUpload;
27 return $this->initializePathInfo( $name,
28 $this->mUpload->getTempName(), $this->mUpload->getSize() );
29 }
30 static function isValidRequest( $request ) {
31 # Allow all requests, even if no file is present, so that an error
32 # because a post_max_size or upload_max_filesize overflow
33 return true;
34 }
35
36 public function getSourceType() { return 'file'; }
37
38 public function verifyUpload() {
39 # Check for a post_max_size or upload_max_size overflow, so that a
40 # proper error can be shown to the user
41 if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
42 if ( $this->mUpload->isIniSizeOverflow() ) {
43 return array(
44 'status' => UploadBase::FILE_TOO_LARGE,
45 'max' => min(
46 self::getMaxUploadSize( $this->getSourceType() ),
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
57 /**
58 * Get the path to the file underlying the upload
59 * @return String path to file
60 */
61 public function getFileTempname() {
62 return $this->mUpload->getTempname();
63 }
64
65
66 }