Instead of creating an OutputPage and then setting a context start initializing Outpu...
[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 */
32 function initialize( $name, $webRequestUpload ) {
33 $this->mUpload = $webRequestUpload;
34 return $this->initializePathInfo( $name,
35 $this->mUpload->getTempName(), $this->mUpload->getSize() );
36 }
37 static function isValidRequest( $request ) {
38 # Allow all requests, even if no file is present, so that an error
39 # because a post_max_size or upload_max_filesize overflow
40 return true;
41 }
42
43 public function getSourceType() { return 'file'; }
44
45 public function verifyUpload() {
46 # Check for a post_max_size or upload_max_size overflow, so that a
47 # proper error can be shown to the user
48 if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
49 if ( $this->mUpload->isIniSizeOverflow() ) {
50 return array(
51 'status' => UploadBase::FILE_TOO_LARGE,
52 'max' => min(
53 self::getMaxUploadSize( $this->getSourceType() ),
54 wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
55 wfShorthandToInteger( ini_get( 'post_max_size' ) )
56 ),
57 );
58 }
59 }
60
61 return parent::verifyUpload();
62 }
63
64 /**
65 * Get the path to the file underlying the upload
66 * @return String path to file
67 */
68 public function getFileTempname() {
69 return $this->mUpload->getTempname();
70 }
71 }