]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/upload/UploadFromFile.php
MediaWiki 1.17.0
[autoinstalls/mediawiki.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 verifyUpload() {
37                 # Check for a post_max_size or upload_max_size overflow, so that a 
38                 # proper error can be shown to the user
39                 if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
40                         if ( $this->mUpload->isIniSizeOverflow() ) {
41                                 global $wgMaxUploadSize;
42                                 return array( 
43                                         'status' => UploadBase::FILE_TOO_LARGE,
44                                         'max' => min( 
45                                                 $wgMaxUploadSize, 
46                                                 wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ), 
47                                                 wfShorthandToInteger( ini_get( 'post_max_size' ) )
48                                         ),
49                                 );
50                         }
51                 }
52                 
53                 return parent::verifyUpload();
54         }
55
56         /** 
57          * Get the path to the file underlying the upload
58          * @return String path to file
59          */
60         public function getFileTempname() {
61                 return $this->mUpload->getTempname();
62         }
63
64         
65 }